Commit d92c56bd by dragonfi

Refactor assert_tips_present in test_quizz

parent 884aef2d
...@@ -31,6 +31,12 @@ from mentoring.test_base import MentoringBaseTest ...@@ -31,6 +31,12 @@ from mentoring.test_base import MentoringBaseTest
# Classes ########################################################### # Classes ###########################################################
class QuizzBlockTest(MentoringBaseTest): class QuizzBlockTest(MentoringBaseTest):
def assert_tips_present(self, messages, *args):
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(len(tips), len(args)+1)
self.assertEqual(tips[0].text, 'FEEDBACK')
for i in range(len(args)):
self.assertEqual(tips[i+1].text, args[i])
def test_quizz_choices_rating(self): def test_quizz_choices_rating(self):
""" """
...@@ -95,13 +101,13 @@ class QuizzBlockTest(MentoringBaseTest): ...@@ -95,13 +101,13 @@ class QuizzBlockTest(MentoringBaseTest):
submit = mentoring.find_element_by_css_selector('input.submit') submit = mentoring.find_element_by_css_selector('input.submit')
submit.click() submit.click()
tips = messages.find_elements_by_css_selector('.quizz-tip') self.assert_tips_present(messages,
self.assertEqual(len(tips), 2) 'To the question "Do you like this quizz?", you have not provided an answer.',
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you have not provided an answer.') 'To the question "How much do you rate this quizz?", you have not provided an answer.',
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you have not provided an answer.') )
# TODO: Cannot test rejection of partial answers, as partial answers # TODO: Test rejection of partial answers. Unable to do, since
# are allowed when dependencies are not enforced, even if the block # partial answers are allowed when dependencies are not enforced,
# reports non-completion. # even if the block reports non-completion.
#self.assertEqual(progress.text, '(Not completed)') #self.assertEqual(progress.text, '(Not completed)')
#self.assertFalse(progress.find_elements_by_xpath('./*')) #self.assertFalse(progress.find_elements_by_xpath('./*'))
...@@ -110,15 +116,11 @@ class QuizzBlockTest(MentoringBaseTest): ...@@ -110,15 +116,11 @@ class QuizzBlockTest(MentoringBaseTest):
submit.click() submit.click()
time.sleep(1) time.sleep(1)
tips = messages.find_elements_by_css_selector('.quizz-tip') self.assert_tips_present(messages,
self.assertEqual(len(tips), 2) 'To the question "Do you like this quizz?", you answered "Maybe not".\nAh, damn.',
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you answered "Maybe not".\nAh, damn.') 'To the question "How much do you rate this quizz?", you have not provided an answer.',
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you have not provided an answer.') )
# TODO: Cannot test rejection of partial answers, as partial answers # TODO: Test rejection of partial answers
# are allowed when dependencies are not enforced, even if the block
# reports non-completion.
#self.assertEqual(progress.text, '(Not completed)')
#self.assertFalse(progress.find_elements_by_xpath('./*'))
# One with only display tip, one with reject tip - should not complete # One with only display tip, one with reject tip - should not complete
quizz1_choices_input[0].click() quizz1_choices_input[0].click()
...@@ -126,15 +128,11 @@ class QuizzBlockTest(MentoringBaseTest): ...@@ -126,15 +128,11 @@ class QuizzBlockTest(MentoringBaseTest):
submit.click() submit.click()
time.sleep(1) time.sleep(1)
tips = messages.find_elements_by_css_selector('.quizz-tip') self.assert_tips_present(messages,
self.assertEqual(len(tips), 2) 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!',
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!') 'To the question "How much do you rate this quizz?", you answered "3".\nWill do better next time...',
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you answered "3".\nWill do better next time...') )
# TODO: Cannot test rejection of partial answers, as partial answers # TODO: Test rejection of partial answers
# are allowed when dependencies are not enforced, even if the block
# reports non-completion.
#self.assertEqual(progress.text, '(Not completed)')
#self.assertFalse(progress.find_elements_by_xpath('./*'))
# Only display tips, to allow to complete # Only display tips, to allow to complete
quizz1_choices_input[0].click() quizz1_choices_input[0].click()
...@@ -142,12 +140,11 @@ class QuizzBlockTest(MentoringBaseTest): ...@@ -142,12 +140,11 @@ class QuizzBlockTest(MentoringBaseTest):
submit.click() submit.click()
time.sleep(1) time.sleep(1)
tips = messages.find_elements_by_xpath('./*') self.assert_tips_present(messages,
self.assertEqual(len(tips), 4) 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!',
self.assertEqual(tips[0].text, 'FEEDBACK') 'To the question "How much do you rate this quizz?", you answered "4".\nI love good grades.',
self.assertEqual(tips[1].text, 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!') 'Congratulations!\nAll is good now...',
self.assertEqual(tips[2].text, 'To the question "How much do you rate this quizz?", you answered "4".\nI love good grades.') )
self.assertEqual(tips[3].text, 'Congratulations!\nAll is good now...') # Includes child <html>
self.assertEqual(progress.text, '') self.assertEqual(progress.text, '')
self.assertTrue(progress.find_elements_by_css_selector('img')) self.assertTrue(progress.find_elements_by_css_selector('img'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment