Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
6660f982
Commit
6660f982
authored
Mar 10, 2016
by
Omar Khan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test report downloads
parent
594f1f28
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
31 deletions
+43
-31
problem_builder/tests/integration/test_dashboard.py
+43
-31
No files found.
problem_builder/tests/integration/test_dashboard.py
View file @
6660f982
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment