now passing all tests
This commit is contained in:
@@ -34,8 +34,6 @@ from rowers.models import User,VirtualRace,Workout
|
||||
from rowers.plannedsessions import email_submit_race
|
||||
|
||||
|
||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
||||
|
||||
# If you find a solution that does not need the two paths, please comment!
|
||||
sys.path.append('$path_to_root_of_project$')
|
||||
@@ -189,9 +187,31 @@ class Command(BaseCommand):
|
||||
default=False,
|
||||
help="Run in testing mode, don't send emails",
|
||||
)
|
||||
parser.add_argument(
|
||||
'--mailbox',
|
||||
action='store_true',
|
||||
dest='mailbox',
|
||||
default='workouts',
|
||||
help="Changing mailbox name",
|
||||
)
|
||||
|
||||
"""Run the Email processing command """
|
||||
def handle(self, *args, **options):
|
||||
if 'testing' in options:
|
||||
testing = options['testing']
|
||||
else:
|
||||
testing = False
|
||||
|
||||
if 'mailbox' in options:
|
||||
workoutmailbox = Mailbox.objects.get(name=options['mailbox'])
|
||||
else:
|
||||
workoutmailbox = Mailbox.objects.get(name='workouts')
|
||||
|
||||
if 'failedmailbox' in options:
|
||||
failedmailbox = Mailbox.objects.get(name=options['failedmailbox'])
|
||||
else:
|
||||
failedmailbox = Mailbox.objects.get(name='Failed')
|
||||
|
||||
# Polar
|
||||
polar_available = polarstuff.get_polar_notifications()
|
||||
res = polarstuff.get_all_new_workouts(polar_available)
|
||||
@@ -207,10 +227,6 @@ class Command(BaseCommand):
|
||||
attachments = MessageAttachment.objects.filter(
|
||||
message_id__in=message_ids
|
||||
)
|
||||
if 'testing' in options:
|
||||
testing = options['testing']
|
||||
else:
|
||||
testing = False
|
||||
cntr = 0
|
||||
for attachment in attachments:
|
||||
filename, extension = os.path.splitext(attachment.document.name)
|
||||
|
||||
@@ -24,7 +24,7 @@ class EmailUpload(TestCase):
|
||||
rowerplan='coach')
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox = Mailbox.objects.create(name='workouts1')
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
@@ -57,7 +57,7 @@ workout run
|
||||
def test_emailupload(
|
||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts1')
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
ws = Workout.objects.filter(name="run")
|
||||
@@ -86,7 +86,7 @@ class EmailBikeErgUpload(TestCase):
|
||||
rowerplan='coach')
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox = Mailbox.objects.create(name='workouts2')
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
@@ -119,7 +119,7 @@ workout bikeerg
|
||||
def test_emailupload(
|
||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts2')
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
ws = Workout.objects.filter(name="bikeerg")
|
||||
@@ -147,7 +147,7 @@ class EmailBikeUpload(TestCase):
|
||||
rowerplan='coach')
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox = Mailbox.objects.create(name='workouts3')
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
@@ -180,14 +180,14 @@ workout bike
|
||||
def test_emailupload(
|
||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts3')
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
ws = Workout.objects.filter(name="bikeerg")
|
||||
ws = Workout.objects.filter(name="bike")
|
||||
|
||||
self.assertEqual(len(ws),1)
|
||||
w = ws[0]
|
||||
self.assertEqual(w.workouttype,'bike')
|
||||
self.assertEqual(w.workouttype,'Bike')
|
||||
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ class EmailTests(TestCase):
|
||||
rowerplan='coach')
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox = Mailbox.objects.create(name='workouts4')
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
@@ -270,7 +270,7 @@ race 1
|
||||
def test_emailprocessing(
|
||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts4')
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ class EmailAdminUpload(TestCase):
|
||||
self.race = RaceFactory(manager = self.theadmin)
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
workoutsbox = Mailbox.objects.create(name='workouts')
|
||||
workoutsbox = Mailbox.objects.create(name='workouts5')
|
||||
workoutsbox.save()
|
||||
failbox = Mailbox.objects.create(name='Failed')
|
||||
failbox.save()
|
||||
@@ -331,7 +331,7 @@ race 1
|
||||
def test_email_admin_upload(
|
||||
self, mocked_sqlalchemy,mocked_polar_notifications, mock_get, mock_post):
|
||||
out = StringIO()
|
||||
call_command('processemail', stdout=out,testing=True)
|
||||
call_command('processemail', stdout=out,testing=True,mailbox='workouts5')
|
||||
self.assertIn('Successfully processed email attachments',out.getvalue())
|
||||
|
||||
ws = Workout.objects.filter(name="johnsworkout")
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
Reference in New Issue
Block a user