From 31c04a1aabdbffe08304af728f89031742b51d46 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 16 Dec 2018 10:17:56 +0100 Subject: [PATCH 1/4] coach view requires login --- rowers/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/rowers/views.py b/rowers/views.py index 9cbe9de5..c7b4d897 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -15167,6 +15167,7 @@ def plannedsession_teamedit_view(request, #@user_passes_test(iscoachmember,login_url="/rowers/promembership/", # redirect_field_name=None) +@login_required() def plannedsessions_coach_view(request, teamid=0,userid=0): From 8e14eb0e803279d9d268ad2fcf8abcbf38051bed Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 16 Dec 2018 11:04:14 +0100 Subject: [PATCH 2/4] testing email workout type --- rowers/c2stuff.py | 2 ++ rowers/tests.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- rowers/uploads.py | 12 ++++++------ 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 9641a41a..e99a8c00 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -422,6 +422,8 @@ def createc2workoutdata(w): workouttype = w.workouttype if workouttype in otwtypes: workouttype = 'water' + elif workouttype not in rowtypes: + workouttype = 'other' try: startdatetime = w.startdatetime.isoformat() diff --git a/rowers/tests.py b/rowers/tests.py index 97358244..4a94b60b 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -1037,6 +1037,49 @@ boattype: 2x out = StringIO() call_command('processemail', stdout=out, testing=True) self.assertIn('Successfully processed email attachments',out.getvalue()) + +class UploadTests(TestCase): + def setUp(self): + redis_connection.publish('tasks','KILL') + u = User.objects.create_user('john', + 'sander@ds.ds', + 'koeinsloot') + r = Rower.objects.create(user=u,gdproptin=True, + gdproptindate=timezone.now() + ) + + nu = datetime.datetime.now() + workoutsbox = Mailbox.objects.create(name='workouts') + workoutsbox.save() + failbox = Mailbox.objects.create(name='Failed') + failbox.save() + m = Message(mailbox=workoutsbox, + from_header = u.email, + subject = "3x(5min/2min)/r2 \r2", + body = """ +workout run + """) + m.save() + a2 = 'media/mailbox_attachments/colin2.csv' + copyfile('rowers/testdata/emails/colin.csv',a2) + a = MessageAttachment(message=m,document=a2[6:]) + a.save() + + def tearDown(self): + for filename in os.listdir('media/mailbox_attachments'): + path = os.path.join('media/mailbox_attachments/',filename) + if not os.path.isdir(path): + try: + os.remove(path) + except IOError: + pass + + @patch('requests.get', side_effect=mocked_requests) + def test_email_workouttype(self, mock_get): + out = StringIO() + call_command('processemail', stdout=out, testing=True) + w = Workout.objects.get(id=1) + self.assertEqual(w.workouttype,'Run') class EmailTests(TestCase): def setUp(self): @@ -1060,7 +1103,6 @@ class EmailTests(TestCase): subject = filename, body=""" --- -chart: time workouttype: water boattype: 4x ... @@ -1075,7 +1117,6 @@ boattype: 4x from_header = u.email, subject = "3x(5min/2min)/r2 \r2", body = """ -chart time workout water """) m.save() diff --git a/rowers/uploads.py b/rowers/uploads.py index ac60340c..b040c56a 100644 --- a/rowers/uploads.py +++ b/rowers/uploads.py @@ -127,7 +127,7 @@ def gettypeoptions_body2(uploadoptions,body): if tester.match(line.lower()): for typ,verb in workouttypes: str1 = '^(workout)(.*)({a})'.format( - a = typ + a = typ.lower() ) testert = re.compile(str1) if testert.match(line.lower()): @@ -239,11 +239,11 @@ def getplotoptions(uploadoptions,value): def gettype(uploadoptions,value,key): workouttype = 'rower' - for type,verb in workouttypes: - if value == type: - workouttype = type + for typ,verb in workouttypes: + if value == typ: + workouttype = typ if value == verb: - workouttype = type + workouttype = typ uploadoptions[key] = workouttype @@ -314,7 +314,7 @@ def upload_options(body): uploadoptions = getplotoptions_body2(uploadoptions,body) uploadoptions = getsyncoptions_body2(uploadoptions,body) uploadoptions = getprivateoptions_body2(uploadoptions,body) - typeoptions = gettypeoptions_body2(uploadoptions,body) + uploadoptions = gettypeoptions_body2(uploadoptions,body) uploadoptions = getstravaid(uploadoptions,body) uploadoptions = getworkoutsources(uploadoptions,body) except IOError: From dbb988458d03996a47c0e842f5002f955a15c66f Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 16 Dec 2018 11:36:46 +0100 Subject: [PATCH 3/4] removing unnecessary code --- rowers/c2stuff.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index e99a8c00..9641a41a 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -422,8 +422,6 @@ def createc2workoutdata(w): workouttype = w.workouttype if workouttype in otwtypes: workouttype = 'water' - elif workouttype not in rowtypes: - workouttype = 'other' try: startdatetime = w.startdatetime.isoformat() From ae1a8a89939975baad2f5b5d8c92e980cee2f35f Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Sun, 16 Dec 2018 12:13:02 +0100 Subject: [PATCH 4/4] fixed C2 test (mocked get) --- rowers/tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rowers/tests.py b/rowers/tests.py index 4a94b60b..9aff5550 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -459,7 +459,8 @@ class C2Objects(DjangoTestCase): self.assertEqual(response.status_code, 302) @patch('rowers.c2stuff.requests.post', side_effect=mocked_requests) - def test_c2_list(self, mock_get): + @patch('rowers.c2stuff.requests.get', side_effect=mocked_requests) + def test_c2_list(self, mock_get, mock_post): response = self.c.get('/rowers/workout/c2list',follow=True) self.assertEqual(response.status_code,200)