Commit 5028cdfb by E. Kolpakov

Submit test for mcr and mrq with html in choices

parent a70c391c
ddt
-e . -e .
unicodecsv==0.9.4 unicodecsv==0.9.4
-e git://github.com/nosedjango/nosedjango.git@ed7d7f9aa969252ff799ec159f828eaa8c1cbc5a#egg=nosedjango-dev -e git://github.com/nosedjango/nosedjango.git@ed7d7f9aa969252ff799ec159f828eaa8c1cbc5a#egg=nosedjango-dev
......
...@@ -317,4 +317,6 @@ class MentoringAssessmentTest(MentoringBaseTest): ...@@ -317,4 +317,6 @@ class MentoringAssessmentTest(MentoringBaseTest):
self.peek_at_review(mentoring, controls, expected_results) self.peek_at_review(mentoring, controls, expected_results)
controls.try_again.click() controls.try_again.click()
# this is a wait and assertion all together - it waits until expected text is in mentoring block
# and it fails with PrmoiseFailed exception if it's not
self.wait_until_text_in(self.question_text(0), mentoring) self.wait_until_text_in(self.question_text(0), mentoring)
\ No newline at end of file
...@@ -23,12 +23,14 @@ ...@@ -23,12 +23,14 @@
# Imports ########################################################### # Imports ###########################################################
import ddt
from .base_test import MentoringBaseTest from .base_test import MentoringBaseTest
# Classes ########################################################### # Classes ###########################################################
@ddt.ddt
class MCQBlockTest(MentoringBaseTest): class MCQBlockTest(MentoringBaseTest):
def _selenium_bug_workaround_scroll_to(self, mcq_legend): def _selenium_bug_workaround_scroll_to(self, mcq_legend):
...@@ -46,6 +48,10 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -46,6 +48,10 @@ class MCQBlockTest(MentoringBaseTest):
def _get_inputs(self, choices): def _get_inputs(self, choices):
return [choice.find_element_by_css_selector('input') for choice in choices] return [choice.find_element_by_css_selector('input') for choice in choices]
def assert_messages_empty(self, messages):
self.assertEqual(messages.text, '')
self.assertFalse(messages.find_elements_by_xpath('./*'))
def test_mcq_choices_rating(self): def test_mcq_choices_rating(self):
""" """
Mentoring MCQ should display tips according to user choice Mentoring MCQ should display tips according to user choice
...@@ -57,8 +63,7 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -57,8 +63,7 @@ class MCQBlockTest(MentoringBaseTest):
messages = mentoring.find_element_by_css_selector('.messages') messages = mentoring.find_element_by_css_selector('.messages')
submit = mentoring.find_element_by_css_selector('.submit input.input-main') submit = mentoring.find_element_by_css_selector('.submit input.input-main')
self.assertEqual(messages.text, '') self.assert_messages_empty(messages)
self.assertFalse(messages.find_elements_by_xpath('./*'))
self.assertFalse(submit.is_enabled()) self.assertFalse(submit.is_enabled())
mcq1_legend = mcq1.find_element_by_css_selector('legend') mcq1_legend = mcq1.find_element_by_css_selector('legend')
...@@ -184,20 +189,48 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -184,20 +189,48 @@ class MCQBlockTest(MentoringBaseTest):
mentoring.click() mentoring.click()
self.assertFalse(item_feedback_popup.is_displayed()) self.assertFalse(item_feedback_popup.is_displayed())
def test_mcq_html_choices(self): def _get_questionnaire_options(self, questionnaire):
mentoring = self.go_to_page('Mrq With Html Choices') result = []
# this could be a list comprehension, but a bit complicated one - hence explicit loop
for choice_wrapper in questionnaire.find_elements_by_css_selector(".choice"):
choice_label = choice_wrapper.find_element_by_css_selector(".choice-label .choice-text")
light_child = choice_label.find_element_by_css_selector(".xblock-light-child")
result.append(light_child.find_element_by_css_selector("div").get_attribute('innerHTML'))
return result
@ddt.data(
'Mrq With Html Choices',
'Mcq With Html Choices'
)
def test_questionnaire_html_choices(self, page):
mentoring = self.go_to_page(page)
choices_list = mentoring.find_element_by_css_selector(".choices-list") choices_list = mentoring.find_element_by_css_selector(".choices-list")
messages = mentoring.find_element_by_css_selector('.messages')
contents = [ expected_options = [
"<b>Its elegance</b>", "<b>Its elegance</b>",
"<i>Its beauty</i>", "<i>Its beauty</i>",
"<strong>Its gracefulness</strong>", "<strong>Its gracefulness</strong>",
'<span style="font-color:red">Its bugs</span>' '<span style="font-color:red">Its bugs</span>'
] ]
for index, expected_content in enumerate(contents): options = self._get_questionnaire_options(choices_list)
choice_wrapper = choices_list.find_elements_by_css_selector(".choice")[index] self.assertEqual(expected_options, options)
choice_label = choice_wrapper.find_element_by_css_selector(".choice-label .choice-text")
light_child = choice_label.find_element_by_css_selector(".xblock-light-child") self.assert_messages_empty(messages)
content = light_child.find_element_by_css_selector("div").get_attribute('innerHTML')
self.assertEqual(content, expected_content) submit = mentoring.find_element_by_css_selector('.submit input.input-main')
self.assertFalse(submit.is_enabled())
inputs = choices_list.find_elements_by_css_selector('input.choice-selector')
self._selenium_bug_workaround_scroll_to(choices_list)
inputs[0].click()
inputs[1].click()
inputs[2].click()
self.assertTrue(submit.is_enabled())
submit.click()
self.wait_until_disabled(submit)
self.assertIn('Congratulations!', messages.text)
\ No newline at end of file
<vertical_demo>
<mentoring url_name="mcq_with_comments" display_name="MCQ Exercise 7" weight="1" enforce_dependency="false">
<title>MRQ With Resizable popups</title>
<mcq name="mrq_1_1_7" type="choices">
<question>What do you like in this MRQ?</question>
<choice value="elegance"><html><b>Its elegance</b></html></choice>
<choice value="beauty"><html><i>Its beauty</i></html></choice>
<choice value="gracefulness"><html><strong>Its gracefulness</strong></html></choice>
<choice value="bugs"><html><span style="font-color:red">Its bugs</span></html></choice>
<tip require="gracefulness" width ="200" height = "200">This MRQ is indeed very graceful</tip>
<tip require="elegance" width ="600" height = "800">This is something everyone has to like about this MRQ</tip>
<tip require="beauty" width ="400" height = "600">This is something everyone has to like about beauty</tip>
<tip reject="bugs" width = "100" height = "200">Nah, there isn\'t any!</tip>
</mcq>
<message type="completed">
<html><p>Congratulations!</p></html>
</message>
<message type="incomplete">
<html><p>Still some work to do...</p></html>
</message>
</mentoring>
</vertical_demo>
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