Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add selenium tests for nutrition application
Roland Geider6fb8331ef807
diff --git a/manager/tests/testcase.py b/manager/tests/testcase.pyindex 6221081db..c925a573f 100644--- a/manager/tests/testcase.py+++ b/manager/tests/testcase.py@@ -78,4 +78,22 @@ class WorkoutManagerLiveServerTestCase(LiveServerTestCase):"""self.browser.get(self.live_server_url + reverse('manager.views.logout'))-\ No newline at end of file++ def check_modal_dialog(self):+ """+ Helper function that checks the modal dialogs+ """++ # There is a modal dialog+ modal_dialog = self.browser.find_elements_by_class_name('ui-dialog')[0]+ self.assertTrue(modal_dialog)++ # Found the title+ dialog_title = modal_dialog.find_elements_by_id('ui-id-1')[0]+ self.assertTrue(dialog_title)++ # Found the content+ dialog_content = modal_dialog.find_elements_by_id('ajax-info')[0]+ self.assertTrue(dialog_content)++ return(dialog_title, dialog_content)diff --git a/nutrition/templates/nutrition_overview.html b/nutrition/templates/nutrition_overview.htmlindex 8d12af4ab..071961488 100644--- a/nutrition/templates/nutrition_overview.html+++ b/nutrition/templates/nutrition_overview.html@@ -25,7 +25,7 @@{% endfor %}</ul>{% else %}- <div class="box warning">+ <div class="box warning" id="nutrition-box-warning">{% trans "No nutrition plans." %} {% trans "Use link to add one." %}</div>{% endif %}@@ -37,7 +37,7 @@{% block sidebar%}<h3>{% trans "Options" %}</h3><p>- <a href="{% url nutrition.views.add %}">+ <a href="{% url nutrition.views.add %}" id="nutrition-create-new"><img src="{% static 'images/icons/new.svg' %}"width="32"height="32"@@ -47,7 +47,7 @@</p><p>- <a href="{% url nutrition.views.ingredient_overview %}">+ <a href="{% url nutrition.views.ingredient_overview %}" id="ingredient-overview"><img src="{% static 'images/icons/list.svg' %}"width="32"height="32"diff --git a/nutrition/templates/view_nutrition_plan.html b/nutrition/templates/view_nutrition_plan.htmlindex dce44e18c..99e986a7e 100644--- a/nutrition/templates/view_nutrition_plan.html+++ b/nutrition/templates/view_nutrition_plan.html@@ -121,7 +121,7 @@ $(document).ready(function() {</span></li>{% empty %}- <div class="box warning">+ <div class="box warning ingredient-box-warning">{% trans "No items for this meal." %}<a href="{% url nutrition.views.edit_meal_item plan.id meal.id item.id %}"title="{% trans 'Edit' %}"@@ -135,7 +135,7 @@ $(document).ready(function() {</tr>{% empty %}- <div class="box warning">+ <div class="box warning" id="meal-box-warning">{% trans "No meals for this plan." %}<a href="{% url meal-add plan.id %}"class="modal-dialog">diff --git a/nutrition/tests.py b/nutrition/tests.pyindex 501deb776..d2480a9f5 100644--- a/nutrition/tests.py+++ b/nutrition/tests.py@@ -1,16 +1,96 @@-"""-This file demonstrates writing tests using the unittest module. These will pass-when you run "manage.py test".+# -*- coding: utf-8 -*--Replace this with more appropriate tests for your application.-"""+# 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 loggingfrom django.test import TestCase+from django.test import LiveServerTestCase+from django.core.urlresolvers import reverse+from selenium.webdriver.common.keys import Keys-class SimpleTest(TestCase):- def test_basic_addition(self):+from manager.tests.testcase import WorkoutManagerLiveServerTestCase++logger = logging.getLogger('workout_manager.custom')+++class NutritionTest(WorkoutManagerLiveServerTestCase):++ def create_plan(self, time='8:00'):+ """+ Helper function that creates a nutrition plan+ """++ self.browser.get(self.live_server_url + reverse('nutrition.views.overview'))++ # No plans, there is a warning box+ box = self.browser.find_elements_by_id('nutrition-box-warning')+ self.assertTrue(box)++ # Clink on the link and enter the weight in the modal dialog+ create_link = self.browser.find_elements_by_id('nutrition-create-new')+ self.assertTrue(create_link)+ create_link[0].click()++ # TODO: check that we are redirected to the correct URL++ # No meals, there is a warning box+ box = self.browser.find_elements_by_id('meal-box-warning')[0]+ self.assertTrue(box)++ # Clink on the link and enter the weight in the modal dialog+ create_link = box.find_elements_by_tag_name('a')+ self.assertTrue(create_link)+ create_link[0].click()++ # Check that there is a modal dialog+ (dialog_title, dialog_content) = self.check_modal_dialog()+++ # Put some number into the weight input+ weight_input = dialog_content.find_elements_by_id('id_time')[0]+ self.assertTrue(weight_input)+ weight_input.send_keys(time)++ save_button = dialog_content.find_element_by_id('form-save')+ save_button.click()++ # Warning box for meals has disappeared+ box = self.browser.find_elements_by_id('meal-box-warning')+ self.assertFalse(box)++ # There is now 1 warning box for ingredients+ box = self.browser.find_elements_by_class_name('ingredient-box-warning')[0]+ self.assertTrue(box)++ # Click on the link to add a new ingredient+ create_link = box.find_elements_by_tag_name('a')[0]+ self.assertTrue(create_link)+ create_link.click()++ # Check that there is a modal dialog+ (dialog_title, dialog_content) = self.check_modal_dialog()+++ def test_create_plan(self):"""- Tests that 1 + 1 always equals 2.+ Tests that it's possible to add a weight entry and that this appears+ in the overview"""- self.assertEqual(1 + 1, 2)++ self.user_login()+ self.browser.get(self.live_server_url + reverse('nutrition.views.overview'))+ self.create_plan()+diff --git a/weight/tests.py b/weight/tests.pyindex 6f43a7df4..e11a66240 100644--- a/weight/tests.py+++ b/weight/tests.py@@ -1,9 +1,19 @@-"""-This file demonstrates writing tests using the unittest module. These will pass-when you run "manage.py test".+# -*- coding: utf-8 -*-++# 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-Replace this with more appropriate tests for your application.-"""import loggingfrom django.test import TestCase