Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Added tests for comments and images

alelevinasa11b6c3ca88f
diff --git a/wger/manager/tests/test_schedule.py b/wger/manager/tests/test_schedule.py
index 229c4ff5b..43f27ee8b 100644
--- a/wger/manager/tests/test_schedule.py
+++ b/wger/manager/tests/test_schedule.py
@@ -528,6 +528,80 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):
self.assertGreater(int(response['Content-Length']), 29000)
self.assertLess(int(response['Content-Length']), 35000)
+ def export_pdf_with_comments(self, fail=False):
+ '''
+ 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,
+ 'images': 0,
+ 'comments': 1,
+ 'uidb64': uid,
+ 'token': token}))
+
+ if fail:
+ self.assertIn(response.status_code, (403, 404, 302))
+ else:
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response['Content-Type'], 'application/pdf')
+ self.assertEqual(response['Content-Disposition'],
+ 'attachment; filename=Schedule-3-log.pdf')
+
+ # Approximate size only
+ self.assertGreater(int(response['Content-Length']), 29000)
+ self.assertLess(int(response['Content-Length']), 35000)
+
+ def export_pdf_with_images(self, fail=False):
+ '''
+ 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,
+ 'images': 1,
+ 'comments': 0,
+ 'uidb64': uid,
+ 'token': token}))
+
+ if fail:
+ self.assertIn(response.status_code, (403, 404, 302))
+ else:
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response['Content-Type'], 'application/pdf')
+ self.assertEqual(response['Content-Disposition'],
+ 'attachment; filename=Schedule-3-log.pdf')
+
+ # Approximate size only
+ self.assertGreater(int(response['Content-Length']), 29000)
+ self.assertLess(int(response['Content-Length']), 35000)
+
+ def export_pdf_with_images_and_comments(self, fail=False):
+ '''
+ 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,
+ 'images': 1,
+ 'comments': 1,
+ 'uidb64': uid,
+ 'token': token}))
+
+ if fail:
+ self.assertIn(response.status_code, (403, 404, 302))
+ else:
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response['Content-Type'], 'application/pdf')
+ self.assertEqual(response['Content-Disposition'],
+ 'attachment; filename=Schedule-3-log.pdf')
+
+ # Approximate size only
+ self.assertGreater(int(response['Content-Length']), 29000)
+ self.assertLess(int(response['Content-Length']), 35000)
+
def test_export_pdf_anonymous(self):
'''
Tests exporting a workout as a pdf as an anonymous user
@@ -554,6 +628,29 @@ class SchedulePdfLogExportTestCase(WorkoutManagerTestCase):
self.export_pdf(fail=True)
self.export_pdf_token()
+ def test_export_pdf_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)
+ self.export_pdf_token()
+
+ def test_export_pdf_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)
+ self.export_pdf_token()
+
+ def test_export_pdf_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)
+ self.export_pdf_token()
class ScheduleApiTestCase(api_base_test.ApiBaseResourceTestCase):
'''