Commit 6660f982 by Omar Khan

Test report downloads

parent 594f1f28
......@@ -17,6 +17,7 @@
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
from functools import wraps
from textwrap import dedent
from mock import Mock, patch
from .base_test import ProblemBuilderBaseTest
......@@ -52,6 +53,33 @@ class MockSubmissionsAPI(object):
return []
def check_dashboard_and_report(fixture, set_mentoring_values=True):
"""
Decorator for dashboard test methods.
- Sets up the given fixture
- Runs the decorated test
- Clicks the download link
- Opens the report
- Runs the decorated test again against the report
"""
def wrapper(test):
@wraps(test)
def wrapped(test_case):
test_case._install_fixture(fixture)
if set_mentoring_values:
test_case._set_mentoring_values()
test_case.go_to_view('student_view')
test(test_case)
download_link = test_case.browser.find_element_by_css_selector('.report-download-link')
download_link.click()
test_case.browser.get(download_link.get_attribute('href'))
test_case.assertRegexpMatches(test_case.browser.current_url, r'^data:text/html;base64,')
test(test_case)
return wrapped
return wrapper
class TestDashboardBlock(ProblemBuilderBaseTest):
"""
Test the Student View of a dashboard XBlock linked to some problem builder blocks
......@@ -128,12 +156,21 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
def _format_sr_text(self, visible_text):
return "Score: {value}".format(value=visible_text)
def _set_mentoring_values(self):
pbs = self.browser.find_elements_by_css_selector('.mentoring')
for pb in pbs:
mcqs = pb.find_elements_by_css_selector('fieldset.choices')
for idx, mcq in enumerate(mcqs):
choices = mcq.find_elements_by_css_selector('.choices .choice label')
choices[idx].click()
self.click_submit(pb)
@check_dashboard_and_report(SIMPLE_DASHBOARD, set_mentoring_values=False)
def test_empty_dashboard(self):
"""
Test that when the student has not submitted any question answers, we still see
the dashboard, and its lists all the MCQ questions in the way we expect.
"""
self._install_fixture(self.SIMPLE_DASHBOARD)
dashboard = self.browser.find_element_by_css_selector('.pb-dashboard')
step_headers = dashboard.find_elements_by_css_selector('thead')
self.assertEqual(len(step_headers), 3)
......@@ -148,24 +185,11 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
cell = mcq.find_element_by_css_selector('td:last-child')
self._assert_cell_contents(cell, '', 'No value yet')
def _set_mentoring_values(self):
pbs = self.browser.find_elements_by_css_selector('.mentoring')
for pb in pbs:
mcqs = pb.find_elements_by_css_selector('fieldset.choices')
for idx, mcq in enumerate(mcqs):
choices = mcq.find_elements_by_css_selector('.choices .choice label')
choices[idx].click()
self.click_submit(pb)
@check_dashboard_and_report(SIMPLE_DASHBOARD)
def test_dashboard(self):
"""
Submit an answer to each MCQ, then check that the dashboard reflects those answers.
"""
self._install_fixture(self.SIMPLE_DASHBOARD)
self._set_mentoring_values()
# Reload the page:
self.go_to_view("student_view")
dashboard = self.browser.find_element_by_css_selector('.pb-dashboard')
headers = dashboard.find_elements_by_class_name('report-header')
self.assertEqual(len(headers), 0)
......@@ -191,6 +215,7 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
expected_average = {0: "2", 1: "3", 2: "1"}[step_num]
self._assert_cell_contents(right_col, expected_average, self._format_sr_text(expected_average))
@check_dashboard_and_report(ALTERNATIVE_DASHBOARD)
def test_dashboard_alternative(self):
"""
Submit an answer to each MCQ, then check that the dashboard reflects those answers with alternative
......@@ -200,11 +225,6 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
* Numerical values are not shown
* Include HTML header and footer snippets
"""
self._install_fixture(self.ALTERNATIVE_DASHBOARD)
self._set_mentoring_values()
# Reload the page:
self.go_to_view("student_view")
dashboard = self.browser.find_element_by_css_selector('.pb-dashboard')
header_p = dashboard.find_element_by_id('header-paragraph')
self.assertEquals(header_p.text, 'Header')
......@@ -233,17 +253,13 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
self.assertEqual(left_col.text, average_labels[step_num])
right_col = avg_row.find_element_by_css_selector('.value')
expected_average = {0: "2", 1: "3", 2: "1"}[step_num]
self._assert_cell_contents(right_col, '', self._format_sr_text(expected_average))
self._assert_cell_contents(right_col, '', self._format_sr_text(expected_average))
@check_dashboard_and_report(HIDE_QUESTIONS_DASHBOARD)
def test_dashboard_exclude_questions(self):
"""
Submit an answer to each MCQ, then check that the dashboard ignores questions it is configured to ignore
"""
self._install_fixture(self.HIDE_QUESTIONS_DASHBOARD)
self._set_mentoring_values()
# Reload the page:
self.go_to_view("student_view")
dashboard = self.browser.find_element_by_css_selector('.pb-dashboard')
steps = dashboard.find_elements_by_css_selector('tbody')
self.assertEqual(len(steps), 3)
......@@ -267,15 +283,11 @@ class TestDashboardBlock(ProblemBuilderBaseTest):
expected_average = {0: "1", 1: "3", 2: "1"}[step_num]
self._assert_cell_contents(right_col, expected_average, self._format_sr_text(expected_average))
@check_dashboard_and_report(MALFORMED_HIDE_QUESTIONS_DASHBOARD)
def test_dashboard_malformed_exclude_questions(self):
"""
Submit an answer to each MCQ, then check that the dashboard ignores questions it is configured to ignore
"""
self._install_fixture(self.MALFORMED_HIDE_QUESTIONS_DASHBOARD)
self._set_mentoring_values()
# Reload the page:
self.go_to_view("student_view")
dashboard = self.browser.find_element_by_css_selector('.pb-dashboard')
steps = dashboard.find_elements_by_css_selector('tbody')
self.assertEqual(len(steps), 3)
......
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