Self hosted FLOSS fitness/workout, nutrition and weight tracker
Some test refactoring and table pdf tests added
alelevinas56c628cbd34f
diff --git a/wger/manager/tests/test_schedule.py b/wger/manager/tests/test_schedule.pyindex 43f27ee8b..e2cfe311b 100644--- a/wger/manager/tests/test_schedule.py+++ b/wger/manager/tests/test_schedule.py@@ -476,26 +476,26 @@ class ScheduleModelTestCase(WorkoutManagerTestCase):self.assertTrue(schedule.get_current_scheduled_workout().workout, workout)-class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):+class SchedulePdfExportTestCase(WorkoutManagerTestCase):'''Test exporting a schedule as a pdf'''- def export_pdf_token(self):+ def export_pdf_token(self, pdf_type="log"):'''Helper function to test exporting a workout as a pdf using tokens'''user = User.objects.get(username='test')uid, token = make_token(user)- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 1,+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 1,'uidb64': uid,'token': token}))self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')self.assertEqual(response['Content-Disposition'],- 'attachment; filename=Schedule-1-log.pdf')+ 'attachment; filename=Schedule-1-{0}.pdf'.format(pdf_type))# Approximate size onlyself.assertGreater(int(response['Content-Length']), 29000)@@ -504,17 +504,17 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):# Wrong or expired tokenuid = 'MQ'token = '3xv-57ef74923091fe7f186e'- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 1,+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 1,'uidb64': uid,'token': token}))self.assertEqual(response.status_code, 403)- def export_pdf(self, fail=False):+ def export_pdf(self, fail=False, pdf_type="log"):'''Helper function to test exporting a workout as a pdf'''- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 1}))+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 1}))if fail:self.assertIn(response.status_code, (403, 404, 302))@@ -522,20 +522,20 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')self.assertEqual(response['Content-Disposition'],- 'attachment; filename=Schedule-1-log.pdf')+ 'attachment; filename=Schedule-1-{0}.pdf'.format(pdf_type))# Approximate size onlyself.assertGreater(int(response['Content-Length']), 29000)self.assertLess(int(response['Content-Length']), 35000)- def export_pdf_with_comments(self, fail=False):+ def export_pdf_with_comments(self, fail=False, pdf_type="log"):'''Helper function to test exporting a workout as a pdf, with exercise coments'''user = User.objects.get(username='test')uid, token = make_token(user)- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 3,+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 3,'images': 0,'comments': 1,'uidb64': uid,@@ -547,19 +547,19 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')self.assertEqual(response['Content-Disposition'],- 'attachment; filename=Schedule-3-log.pdf')+ 'attachment; filename=Schedule-3-{0}.pdf'.format(pdf_type))# Approximate size onlyself.assertGreater(int(response['Content-Length']), 29000)self.assertLess(int(response['Content-Length']), 35000)- def export_pdf_with_images(self, fail=False):+ def export_pdf_with_images(self, fail=False, pdf_type="log"):'''Helper function to test exporting a workout as a pdf, with exercise images'''user = User.objects.get(username='test')uid, token = make_token(user)- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 3,+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 3,'images': 1,'comments': 0,'uidb64': uid,@@ -571,20 +571,20 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')self.assertEqual(response['Content-Disposition'],- 'attachment; filename=Schedule-3-log.pdf')+ 'attachment; filename=Schedule-3-{0}.pdf'.format(pdf_type))# Approximate size onlyself.assertGreater(int(response['Content-Length']), 29000)self.assertLess(int(response['Content-Length']), 35000)- def export_pdf_with_images_and_comments(self, fail=False):+ def export_pdf_with_images_and_comments(self, fail=False, pdf_type="log"):'''Helper function to test exporting a workout as a pdf, with images and comments'''user = User.objects.get(username='test')uid, token = make_token(user)- response = self.client.get(reverse('manager:schedule:pdf-log', kwargs={'pk': 3,+ response = self.client.get(reverse('manager:schedule:pdf-{0}'.format(pdf_type), kwargs={'pk': 3,'images': 1,'comments': 1,'uidb64': uid,@@ -596,13 +596,13 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.assertEqual(response.status_code, 200)self.assertEqual(response['Content-Type'], 'application/pdf')self.assertEqual(response['Content-Disposition'],- 'attachment; filename=Schedule-3-log.pdf')+ 'attachment; filename=Schedule-3-{0}.pdf'.format(pdf_type))# Approximate size onlyself.assertGreater(int(response['Content-Length']), 29000)self.assertLess(int(response['Content-Length']), 35000)- def test_export_pdf_anonymous(self):+ def test_export_pdf_log_anonymous(self):'''Tests exporting a workout as a pdf as an anonymous user'''@@ -610,7 +610,7 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf(fail=True)self.export_pdf_token()- def test_export_pdf_owner(self):+ def test_export_pdf_log_owner(self):'''Tests exporting a workout as a pdf as the owner user'''@@ -619,7 +619,7 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf(fail=False)self.export_pdf_token()- def test_export_pdf_other(self):+ def test_export_pdf_log_other(self):'''Tests exporting a workout as a pdf as a logged user not owning the data'''@@ -628,7 +628,7 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf(fail=True)self.export_pdf_token()- def test_export_pdf_with_comments(self, fail=False):+ def test_export_pdf_log_with_comments(self, fail=False):'''Tests exporting a workout as a pdf as the owner user with comments'''@@ -636,7 +636,7 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf_with_comments(fail=False)self.export_pdf_token()- def test_export_pdf_with_images(self, fail=False):+ def test_export_pdf_log_with_images(self, fail=False):'''Tests exporting a workout as a pdf as the owner user with images'''@@ -644,7 +644,7 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf_with_images(fail=False)self.export_pdf_token()- def test_export_pdf_with_images_and_comments(self, fail=False):+ def test_export_pdf_log_with_images_and_comments(self, fail=False):'''Tests exporting a workout as a pdf as the owner user with images andcomments'''@@ -652,6 +652,59 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):self.export_pdf_with_images_and_comments(fail=False)self.export_pdf_token()++ #####TABLE#####++ def test_export_pdf_table_anonymous(self):+ '''+ Tests exporting a workout as a pdf as an anonymous user+ '''++ self.export_pdf(fail=True, pdf_type="table")+ self.export_pdf_token(pdf_type="table")++ def test_export_pdf_table_owner(self):+ '''+ Tests exporting a workout as a pdf as the owner user+ '''++ self.user_login('test')+ self.export_pdf(fail=False, pdf_type="table")+ self.export_pdf_token(pdf_type="table")++ def test_export_pdf_table_other(self):+ '''+ Tests exporting a workout as a pdf as a logged user not owning the data+ '''++ self.user_login('admin')+ self.export_pdf(fail=True, pdf_type="table")+ self.export_pdf_token(pdf_type="table")++ def test_export_pdf_table_with_comments(self, fail=False):+ '''+ Tests exporting a workout as a pdf as the owner user with comments+ '''+ self.user_login('test')+ self.export_pdf_with_comments(fail=False, pdf_type="table")+ self.export_pdf_token(pdf_type="table")++ def test_export_pdf_table_with_images(self, fail=False):+ '''+ Tests exporting a workout as a pdf as the owner user with images+ '''+ self.user_login('test')+ self.export_pdf_with_images(fail=False, pdf_type="table")+ self.export_pdf_token(pdf_type="table")++ def test_export_pdf_table_with_images_and_comments(self, fail=False):+ '''+ Tests exporting a workout as a pdf as the owner user with images andcomments+ '''+ self.user_login('test')+ self.export_pdf_with_images_and_comments(fail=False, pdf_type="table")+ self.export_pdf_token(pdf_type="table")+class ScheduleApiTestCase(api_base_test.ApiBaseResourceTestCase):'''Tests the schedule overview resource