Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Expand the nutrition selenium tests

Roland Geiderd6c90021effe
diff --git a/manager/tests/testcase.py b/manager/tests/testcase.py
index c925a573f..5b1d8d192 100644
--- a/manager/tests/testcase.py
+++ b/manager/tests/testcase.py
@@ -39,7 +39,7 @@ class WorkoutManagerLiveServerTestCase(LiveServerTestCase):
Live server test case, will be used with the selenium webdriver
"""
- fixtures = ['tests-user-data', 'test-exercises', ]
+ fixtures = ['tests-user-data', 'test-exercises', 'tests-ingredients']
def setUp(self):
@@ -59,12 +59,13 @@ class WorkoutManagerLiveServerTestCase(LiveServerTestCase):
self.browser.quit()
- def user_login(self, user='admin'):
+ def user_login(self, user='admin', explicit_login=True):
"""
Login the user
"""
- self.browser.get(self.live_server_url + reverse('manager.views.login'))
+ if explicit_login:
+ self.browser.get(self.live_server_url + reverse('manager.views.login'))
username_field = self.browser.find_element_by_id('id_username')
username_field.send_keys('admin')
diff --git a/nutrition/fixtures/tests-ingredients.json b/nutrition/fixtures/tests-ingredients.json
new file mode 100644
index 000000000..2f8bfadab
--- /dev/null
+++ b/nutrition/fixtures/tests-ingredients.json
@@ -0,0 +1,34 @@
+[
+ {
+ "pk": 1,
+ "model": "nutrition.ingredient",
+ "fields": {
+ "name": "Test ingredient 1",
+ "language": 2,
+ "sodium": 0.549,
+ "energy": 176,
+ "fat": 8.19,
+ "carbohydrates_sugar": 0.0,
+ "fat_saturated": 3.244,
+ "fibres": 0.0,
+ "protein": 25.63,
+ "carbohydrates": 0.0
+ }
+ },
+ {
+ "pk": 2,
+ "model": "nutrition.ingredient",
+ "fields": {
+ "name": "Ingredient, test, 2, organic, raw",
+ "language": 2,
+ "sodium": 0.1,
+ "energy": 300,
+ "fat": 9,
+ "carbohydrates_sugar": 1,
+ "fat_saturated": 3,
+ "fibres": 5.0,
+ "protein": 25.63,
+ "carbohydrates": 0.0
+ }
+ }
+]
diff --git a/nutrition/tests.py b/nutrition/tests.py
index d2480a9f5..7305636d1 100644
--- a/nutrition/tests.py
+++ b/nutrition/tests.py
@@ -28,12 +28,13 @@ logger = logging.getLogger('workout_manager.custom')
class NutritionTest(WorkoutManagerLiveServerTestCase):
- def create_plan(self, time='8:00'):
+ def test_create_plan(self):
"""
- Helper function that creates a nutrition plan
+ Tests that it's possible to create a complete nutritional plan
"""
self.browser.get(self.live_server_url + reverse('nutrition.views.overview'))
+ self.user_login(explicit_login=False)
# No plans, there is a warning box
box = self.browser.find_elements_by_id('nutrition-box-warning')
@@ -44,13 +45,11 @@ class NutritionTest(WorkoutManagerLiveServerTestCase):
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
+ # Clink on the link and enter the time in the modal dialog
create_link = box.find_elements_by_tag_name('a')
self.assertTrue(create_link)
create_link[0].click()
@@ -58,11 +57,10 @@ class NutritionTest(WorkoutManagerLiveServerTestCase):
# Check that there is a modal dialog
(dialog_title, dialog_content) = self.check_modal_dialog()
-
- # Put some number into the weight input
+ # Put some number into the time field
weight_input = dialog_content.find_elements_by_id('id_time')[0]
self.assertTrue(weight_input)
- weight_input.send_keys(time)
+ weight_input.send_keys('8:00')
save_button = dialog_content.find_element_by_id('form-save')
save_button.click()
@@ -72,25 +70,41 @@ class NutritionTest(WorkoutManagerLiveServerTestCase):
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)
+ box = self.browser.find_elements_by_class_name('ingredient-box-warning')
+ self.assertEqual(len(box), 1)
# Click on the link to add a new ingredient
- create_link = box.find_elements_by_tag_name('a')[0]
+ create_link = box[0].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 it's possible to add a weight entry and that this appears
- in the overview
- """
+ # Set the data
+ #id_amount_gramm
+ amount_input = dialog_content.find_elements_by_id('id_amount_gramm')[0]
+ self.assertTrue(amount_input)
+ amount_input.send_keys('150')
- self.user_login()
- self.browser.get(self.live_server_url + reverse('nutrition.views.overview'))
- self.create_plan()
-
+ ingredient_autocomplete = dialog_content.find_elements_by_id('id_ingredient_searchfield')[0]
+ self.assertTrue(ingredient_autocomplete)
+
+ #We want to find "Ingredient, test, 2, organic, raw"
+ # TODO: the autocompleter doesnt open
+ ingredient_autocomplete.send_keys('raw')
+ autocompleter_input = dialog_content.find_elements_by_id('ui-id-6')[0]
+ self.assertTrue(amount_input, 'Ingredient autocompleter not found')
+ # thre is one result
+ autocompleter_result = self.browser.find_elements_by_class_name('ui-menu-item')
+ self.assertEqual(len(autocompleter_result), 1)
+
+ #
+
+ save_button = dialog_content.find_element_by_id('form-save')
+ save_button.click()
+
+
+
+ # TODO
+ self.assertTrue(False, 'TODO: continue here')