Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add test case for exporting a nutritional plan as a PDF

Roland Geiderde221d0efeb6
diff --git a/wger/nutrition/tests/__init__.py b/wger/nutrition/tests/__init__.py
index b5c57c6ab..39b35a6ec 100644
--- a/wger/nutrition/tests/__init__.py
+++ b/wger/nutrition/tests/__init__.py
@@ -1,5 +1,6 @@
from wger.nutrition.tests.plan import *
from wger.nutrition.tests.copy_plan import *
+from wger.nutrition.tests.pdf import *
from wger.nutrition.tests.ingredient import *
from wger.nutrition.tests.ingredient_overview import *
diff --git a/wger/nutrition/tests/pdf.py b/wger/nutrition/tests/pdf.py
new file mode 100644
index 000000000..8205cc6bb
--- /dev/null
+++ b/wger/nutrition/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 NutritionalPlanPdfExportTestCase(WorkoutManagerTestCase):
+ '''
+ Tests exporting a nutritional plan as a pdf
+ '''
+
+ def export_pdf(self, fail=False):
+ '''
+ Helper function to test exporting a nutritional plan as a pdf
+ '''
+
+ # Create a workout
+ response = self.client.get(reverse('wger.nutrition.views.export_pdf', kwargs={'id': 4}))
+
+ 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=nutritional-plan.pdf')
+
+ # Approximate size, there's a timestamp in the document
+ self.assertGreater(len(response.content), 2800)
+
+ def test_export_pdf_anonymous(self):
+ '''
+ Tests exporting a nutritional plan as a pdf as an anonymous user
+ '''
+
+ self.export_pdf(fail=True)
+
+ def test_export_pdf_owner(self):
+ '''
+ Tests exporting a nutritional plan 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 nutritional plan as a pdf as a logged user not owning the data
+ '''
+
+ self.user_login('admin')
+ self.export_pdf(fail=True)