Commit 86c9db9c by Xavier Antoviaque

Adds tests for <quizz> block

parent 7ba0c8d2
# Imports ###########################################################
import time
from mentoring.test_base import MentoringBaseTest
# Classes ###########################################################
class QuizzBlockTest(MentoringBaseTest):
def test_quizz_choices_rating(self):
link = self.browser.find_element_by_link_text('Quizz 1')
link.click()
# Mentoring block
vertical = self.browser.find_element_by_css_selector('div.vertical')
mentoring = vertical.find_element_by_css_selector('div.mentoring')
# Initial quizzes status
quizz1 = mentoring.find_element_by_css_selector('fieldset.choices')
quizz2 = mentoring.find_element_by_css_selector('fieldset.rating')
messages = mentoring.find_element_by_css_selector('.messages')
progress = mentoring.find_element_by_css_selector('.progress > .indicator')
self.assertEqual(messages.text, '')
self.assertFalse(messages.find_elements_by_xpath('./*'))
self.assertEqual(progress.text, '(Not completed)')
self.assertFalse(progress.find_elements_by_xpath('./*'))
quizz1_legend = quizz1.find_element_by_css_selector('legend')
quizz2_legend = quizz2.find_element_by_css_selector('legend')
self.assertEqual(quizz1_legend.text, 'Do you like this quizz?')
self.assertEqual(quizz2_legend.text, 'How much do you rate this quizz?')
quizz1_choices = quizz1.find_elements_by_css_selector('.choices .choice label')
quizz2_choices = quizz2.find_elements_by_css_selector('.choices .choice label')
self.assertEqual(len(quizz1_choices), 3)
self.assertEqual(len(quizz2_choices), 6)
self.assertEqual(quizz1_choices[0].text, 'Yes')
self.assertEqual(quizz1_choices[1].text, 'Maybe not')
self.assertEqual(quizz1_choices[2].text, "I don't understand")
self.assertEqual(quizz2_choices[0].text, '1')
self.assertEqual(quizz2_choices[1].text, '2')
self.assertEqual(quizz2_choices[2].text, '3')
self.assertEqual(quizz2_choices[3].text, '4')
self.assertEqual(quizz2_choices[4].text, '5')
self.assertEqual(quizz2_choices[5].text, "I don't want to rate it")
quizz1_choices_input = [
quizz1_choices[0].find_element_by_css_selector('input'),
quizz1_choices[1].find_element_by_css_selector('input'),
quizz1_choices[2].find_element_by_css_selector('input'),
]
quizz2_choices_input = [
quizz2_choices[0].find_element_by_css_selector('input'),
quizz2_choices[1].find_element_by_css_selector('input'),
quizz2_choices[2].find_element_by_css_selector('input'),
quizz2_choices[3].find_element_by_css_selector('input'),
quizz2_choices[4].find_element_by_css_selector('input'),
quizz2_choices[5].find_element_by_css_selector('input'),
]
self.assertEqual(quizz1_choices_input[0].get_attribute('value'), 'yes')
self.assertEqual(quizz1_choices_input[1].get_attribute('value'), 'maybenot')
self.assertEqual(quizz1_choices_input[2].get_attribute('value'), 'understand')
self.assertEqual(quizz2_choices_input[0].get_attribute('value'), '1')
self.assertEqual(quizz2_choices_input[1].get_attribute('value'), '2')
self.assertEqual(quizz2_choices_input[2].get_attribute('value'), '3')
self.assertEqual(quizz2_choices_input[3].get_attribute('value'), '4')
self.assertEqual(quizz2_choices_input[4].get_attribute('value'), '5')
self.assertEqual(quizz2_choices_input[5].get_attribute('value'), 'notwant')
# Submit without selecting anything
submit = mentoring.find_element_by_css_selector('input.submit')
submit.click()
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(len(tips), 2)
self.assertEqual(tips[0].text, 'To the question "Do you like 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.')
self.assertEqual(progress.text, '(Not completed)')
self.assertFalse(progress.find_elements_by_xpath('./*'))
# Select only one option
quizz1_choices_input[1].click()
submit.click()
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(len(tips), 2)
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you answered "Maybe not".\nAh, damn.')
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you have not provided an answer.')
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
quizz1_choices_input[0].click()
quizz2_choices_input[2].click()
submit.click()
time.sleep(1)
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(len(tips), 2)
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!')
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you answered "3".\nWill do better next time...')
self.assertEqual(progress.text, '(Not completed)')
self.assertFalse(progress.find_elements_by_xpath('./*'))
# Only display tips, to allow to complete
quizz1_choices_input[0].click()
quizz2_choices_input[3].click()
submit.click()
time.sleep(1)
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(len(tips), 3)
self.assertEqual(tips[0].text, 'To the question "Do you like this quizz?", you answered "Yes".\nGreat!')
self.assertEqual(tips[1].text, 'To the question "How much do you rate this quizz?", you answered "4".\nI love good grades.')
self.assertEqual(tips[2].text, 'All is good now - congratulations!')
self.assertEqual(progress.text, '')
self.assertTrue(progress.find_elements_by_css_selector('img'))
<vertical>
<mentoring url_name="quizz_1" enforce_dependency="false">
<quizz name="quizz_1_1" type="choices">
<question>Do you like this quizz?</question>
<choice value="yes">Yes</choice>
<choice value="maybenot">Maybe not</choice>
<choice value="understand">I don't understand</choice>
<tip display="yes">Great!</tip>
<tip reject="maybenot">Ah, damn.</tip>
<tip reject="understand"><html><div id="test-custom-html">Really?</div></html></tip>
</quizz>
<quizz name="quizz_1_2" type="rating" low="Not good at all" high="Extremely good">
<question>How much do you rate this quizz?</question>
<choice value="notwant">I don't want to rate it</choice>
<tip display="4,5">I love good grades.</tip>
<tip reject="1,2,3">Will do better next time...</tip>
<tip reject="notwant">Your loss!</tip>
</quizz>
<message type="completed">All is good now - congratulations!</message>
</mentoring>
</vertical>
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