Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add tests for PDF output and workout sets

Roland Geider8e31556782c2
diff --git a/wger/manager/tests/__init__.py b/wger/manager/tests/__init__.py
index 81eab5637..98e8f139e 100644
--- a/wger/manager/tests/__init__.py
+++ b/wger/manager/tests/__init__.py
@@ -1,8 +1,11 @@
from wger.manager.tests.index import *
+from wger.manager.tests.demo_user import *
+from wger.manager.tests.registration import *
+from wger.manager.tests.preferences import *
+
from wger.manager.tests.workout import *
from wger.manager.tests.day import *
+from wger.manager.tests.set import *
from wger.manager.tests.weight_log import *
from wger.manager.tests.copy_workout import *
-from wger.manager.tests.demo_user import *
-from wger.manager.tests.registration import *
-from wger.manager.tests.preferences import *
+from wger.manager.tests.pdf import *
diff --git a/wger/manager/tests/pdf.py b/wger/manager/tests/pdf.py
new file mode 100644
index 000000000..4a14690fe
--- /dev/null
+++ b/wger/manager/tests/pdf.py
@@ -0,0 +1,64 @@
+# This file is part of Workout Manager.
+#
+# Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+
+from django.core.urlresolvers import reverse
+
+from wger.manager.tests.testcase import WorkoutManagerTestCase
+
+
+class WorkoutPdfExportTestCase(WorkoutManagerTestCase):
+ '''
+ Tests exporting a workout as a pdf
+ '''
+
+ def export_pdf(self, fail=False):
+ '''
+ Helper function to test exporting a workout as a pdf
+ '''
+
+ # Create a workout
+ response = self.client.get(reverse('wger.manager.pdf.workout_log', kwargs={'id': 3}))
+
+ if fail:
+ self.assertIn(response.status_code, (404, 302))
+ else:
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response['Content-Type'], 'application/pdf')
+ self.assertEqual(response['Content-Disposition'], 'attachment; filename=Workout.pdf')
+
+ # Approximate size, there's a timestamp in the document
+ self.assertGreater(len(response.content), 3200)
+
+ def test_export_pdf_anonymous(self):
+ '''
+ Tests exporting a workout as a pdf as an anonymous user
+ '''
+
+ self.export_pdf(fail=True)
+
+ def test_export_pdf_owner(self):
+ '''
+ Tests exporting a workout as a pdf as the owner user
+ '''
+
+ self.user_login('test')
+ self.export_pdf(fail=False)
+
+ def test_export_pdf_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)
diff --git a/wger/manager/tests/set.py b/wger/manager/tests/set.py
new file mode 100644
index 000000000..a30169c14
--- /dev/null
+++ b/wger/manager/tests/set.py
@@ -0,0 +1,72 @@
+# This file is part of Workout Manager.
+#
+# Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+
+import logging
+
+from django.core.urlresolvers import reverse
+
+from wger.manager.models import Set
+
+from wger.manager.tests.testcase import WorkoutManagerTestCase
+
+logger = logging.getLogger('workout_manager.custom')
+
+
+class SetDeleteTestCase(WorkoutManagerTestCase):
+ '''
+ Tests deleting a set from a workout
+ '''
+
+ def delete_set(self, fail=True):
+ '''
+ Helper function to test deleting a set from a workout
+ '''
+
+ # Fetch the overview page
+ count_before = Set.objects.count()
+ response = self.client.get(reverse('wger.manager.views.delete_set', kwargs={'id': 3,
+ 'day_id': 5,
+ 'set_id': 3}))
+ count_after = Set.objects.count()
+
+ if fail:
+ self.assertTrue(response.status_code in (302, 403))
+ self.assertEqual(count_before, count_after)
+ else:
+ self.assertEqual(response.status_code, 302)
+ self.assertEqual(count_before - 1, count_after)
+ self.assertRaises(Set.DoesNotExist, Set.objects.get, pk=3)
+
+ def test_delete_set_anonymous(self):
+ '''
+ Tests deleting a set from a workout as an anonymous user
+ '''
+
+ self.delete_set(fail=True)
+
+ def test_delete_set_owner(self):
+ '''
+ Tests deleting a set from a workout as the owner user
+ '''
+
+ self.user_login('admin')
+ self.delete_set(fail=True)
+
+ def test_delete_set_other(self):
+ '''
+ Tests deleting a set from a workout as a logged user not owning the data
+ '''
+
+ self.user_login('test')
+ self.delete_set(fail=False)
diff --git a/wger/manager/tests/weight_log.py b/wger/manager/tests/weight_log.py
index dc3b99788..5c3ea3461 100644
--- a/wger/manager/tests/weight_log.py
+++ b/wger/manager/tests/weight_log.py
@@ -20,7 +20,6 @@ from django.core.urlresolvers import reverse
from wger.manager.models import WorkoutLog
from wger.manager.tests.testcase import WorkoutManagerTestCase
-from wger.manager.tests.testcase import WorkoutManagerLiveServerTestCase
logger = logging.getLogger('workout_manager.custom')
@@ -111,6 +110,13 @@ class WeightLogEntryTestCase(WorkoutManagerTestCase):
Helper function to test edit log entries
'''
+ response = self.client.get(reverse('workout-log-edit', kwargs={'pk': 1}))
+ if fail:
+ self.assertTrue(response.status_code in (302, 403))
+
+ else:
+ self.assertEqual(response.status_code, 200)
+
date_before = WorkoutLog.objects.get(pk=1).date
response = self.client.post(reverse('workout-log-edit', kwargs={'pk': 1}),
{'date': '2012-01-01',