diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index ceed4054..e52fae9b 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -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) diff --git a/rowers/tests/test_emails.py b/rowers/tests/test_emails.py index b2d6bb87..6370879c 100644 --- a/rowers/tests/test_emails.py +++ b/rowers/tests/test_emails.py @@ -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") diff --git a/rowers/tests/testdata/testdata.csv.gz b/rowers/tests/testdata/testdata.csv.gz index c271349e..e7b60c9a 100644 Binary files a/rowers/tests/testdata/testdata.csv.gz and b/rowers/tests/testdata/testdata.csv.gz differ