Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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
edx
edx-ora2
Commits
57ca8732
Commit
57ca8732
authored
Jan 21, 2015
by
Usman Khalid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for reading older format submission data.
TNL-708
parent
ba7eaa1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
6 deletions
+115
-6
openassessment/xblock/test/test_data_conversion.py
+30
-1
openassessment/xblock/test/test_submission.py
+54
-4
openassessment/xblock/test/test_validation.py
+31
-1
No files found.
openassessment/xblock/test/test_data_conversion.py
View file @
57ca8732
...
...
@@ -9,7 +9,7 @@ import mock
from
django.test
import
TestCase
from
openassessment.xblock.data_conversion
import
(
create_prompts_list
,
create_prompts_list
,
create_submission_dict
,
prepare_submission_for_serialization
)
@ddt.ddt
...
...
@@ -23,3 +23,32 @@ class DataConversionTest(TestCase):
@ddt.unpack
def
test_create_prompts_list
(
self
,
input
,
output
):
self
.
assertEqual
(
create_prompts_list
(
input
),
output
)
@ddt.data
(
(
{
'answer'
:
{
'text'
:
'a'
}},
[{
'description'
:
'1'
}],
{
'answer'
:
{
'parts'
:
[{
'prompt'
:
{
'description'
:
'1'
},
'text'
:
'a'
}]}}
),
(
{
'answer'
:
{
'parts'
:
[{
'text'
:
'a'
}]}},
[{
'description'
:
'1'
}],
{
'answer'
:
{
'parts'
:
[{
'prompt'
:
{
'description'
:
'1'
},
'text'
:
'a'
}]}}
),
(
{
'answer'
:
{
'parts'
:
[{
'text'
:
'a'
}]}},
[{
'description'
:
'1'
},
{
'description'
:
'2'
}],
{
'answer'
:
{
'parts'
:
[{
'prompt'
:
{
'description'
:
'1'
},
'text'
:
'a'
},
{
'prompt'
:
{
'description'
:
'2'
},
'text'
:
''
}]}}
)
)
@ddt.unpack
def
test_create_submission_dict
(
self
,
input_submission
,
input_prompts
,
output
):
self
.
assertEqual
(
create_submission_dict
(
input_submission
,
input_prompts
),
output
)
@ddt.data
(
([
''
],
{
'parts'
:
[{
'text'
:
''
}]}),
([
'a'
,
'b'
],
{
'parts'
:
[{
'text'
:
'a'
},
{
'text'
:
'b'
}]})
)
@ddt.unpack
def
test_prepare_submission_for_serialization
(
self
,
input
,
output
):
self
.
assertEqual
(
prepare_submission_for_serialization
(
input
),
output
)
openassessment/xblock/test/test_submission.py
View file @
57ca8732
...
...
@@ -12,6 +12,7 @@ from submissions import api as sub_api
from
submissions.api
import
SubmissionRequestError
,
SubmissionInternalError
from
openassessment.workflow
import
api
as
workflow_api
from
openassessment.xblock.openassessmentblock
import
OpenAssessmentBlock
from
openassessment.xblock.data_conversion
import
create_submission_dict
,
prepare_submission_for_serialization
from
.base
import
XBlockHandlerTestCase
,
scenario
...
...
@@ -208,6 +209,30 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
)
@scenario
(
'data/submission_open.xml'
,
user_id
=
"Bob"
)
def
test_open_saved_response_old_format
(
self
,
xblock
):
# Save a response
xblock
.
prompts
=
[{
'description'
:
'One prompt.'
}]
xblock
.
saved_response
=
"An old format response."
xblock
.
has_saved
=
True
self
.
_assert_path_and_context
(
xblock
,
'openassessmentblock/response/oa_response.html'
,
{
'allow_file_upload'
:
False
,
'saved_response'
:
create_submission_dict
({
'answer'
:
prepare_submission_for_serialization
(
(
'An old format response.'
,)
)
},
xblock
.
prompts
),
'save_status'
:
'This response has been saved but not submitted.'
,
'submit_enabled'
:
True
,
'submission_due'
:
dt
.
datetime
(
2999
,
5
,
6
)
.
replace
(
tzinfo
=
pytz
.
utc
),
'has_peer'
:
True
,
'has_self'
:
True
,
'allow_latex'
:
False
,
}
)
@scenario
(
'data/submission_open.xml'
,
user_id
=
"Bob"
)
def
test_open_submitted
(
self
,
xblock
):
submission
=
xblock
.
create_submission
(
xblock
.
get_student_item_dict
(),
...
...
@@ -230,7 +255,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
student_item
=
xblock
.
get_student_item_dict
()
submission
=
xblock
.
create_submission
(
student_item
,
'A man must have a code'
(
'A man must have a code'
,
'A man must have an umbrella too.'
)
)
xblock
.
get_workflow_info
=
Mock
(
return_value
=
{
'status'
:
'cancelled'
,
...
...
@@ -249,12 +274,12 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
self
.
_assert_path_and_context
(
xblock
,
'openassessmentblock/response/oa_response_cancelled.html'
,
{
'submission_due'
:
dt
.
datetime
(
2999
,
5
,
6
)
.
replace
(
tzinfo
=
pytz
.
utc
),
'student_submission'
:
submission
,
'allow_file_upload'
:
False
,
'allow_latex'
:
False
,
'has_peer'
:
True
,
'has_self'
:
True
,
'allow_latex'
:
False
,
'submission_due'
:
dt
.
datetime
(
2999
,
5
,
6
)
.
replace
(
tzinfo
=
pytz
.
utc
),
'student_submission'
:
submission
,
'workflow_cancellation'
:
{
'comments'
:
'Inappropriate language'
,
'cancelled_by_id'
:
'Bob'
,
...
...
@@ -264,6 +289,31 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
}
)
@patch.object
(
OpenAssessmentBlock
,
'get_user_submission'
)
@scenario
(
'data/submission_open.xml'
,
user_id
=
"Bob"
)
def
test_open_submitted_old_format
(
self
,
xblock
,
mock_get_user_submission
):
submission
=
xblock
.
create_submission
(
xblock
.
get_student_item_dict
(),
(
'A man must have a code'
,
'A man must have an umbrella too.'
)
)
mock_get_user_submission
.
return_value
=
{
"answer"
:
{
"text"
:
"An old format response."
}}
xblock
.
prompts
=
[{
'description'
:
'One prompt.'
}]
self
.
_assert_path_and_context
(
xblock
,
'openassessmentblock/response/oa_response_submitted.html'
,
{
'submission_due'
:
dt
.
datetime
(
2999
,
5
,
6
)
.
replace
(
tzinfo
=
pytz
.
utc
),
'student_submission'
:
{
"answer"
:
{
"parts"
:
[
{
"prompt"
:
{
'description'
:
'One prompt.'
},
"text"
:
"An old format response."
}
]}},
'allow_file_upload'
:
False
,
'has_peer'
:
True
,
'has_self'
:
True
,
'allow_latex'
:
False
,
}
)
@scenario
(
'data/submission_closed.xml'
,
user_id
=
"Bob"
)
def
test_closed_incomplete
(
self
,
xblock
):
self
.
_assert_path_and_context
(
...
...
openassessment/xblock/test/test_validation.py
View file @
57ca8732
...
...
@@ -12,7 +12,7 @@ from django.test import TestCase
from
openassessment.xblock.openassessmentblock
import
OpenAssessmentBlock
from
openassessment.xblock.validation
import
(
validator
,
validate_assessments
,
validate_rubric
,
validate_dates
,
validate_assessment_examples
validate_dates
,
validate_assessment_examples
,
validate_submission
)
STUB_I18N
=
lambda
x
:
x
...
...
@@ -365,3 +365,33 @@ class ValidationIntegrationTest(TestCase):
else
:
self
.
assertFalse
(
is_valid
,
msg
=
"Leaderboard num {num} should be invalid"
.
format
(
num
=
num
))
self
.
assertEqual
(
msg
,
'Leaderboard number is invalid.'
)
class
ValidationSubmissionTest
(
TestCase
):
"""
Test validate_submission function.
"""
PROMPT
=
[{
"description"
:
"A prompt."
},
{
"description"
:
"Another prompt."
}]
def
test_valid_submissions
(
self
):
success
,
msg
=
validate_submission
([
u"A response."
],
[{
"description"
:
"A prompt."
}],
STUB_I18N
)
self
.
assertTrue
(
success
)
success
,
msg
=
validate_submission
(
[
u"Response 1."
,
u"Response 2"
],
self
.
PROMPT
,
STUB_I18N
)
self
.
assertTrue
(
success
)
def
test_invalid_submissions
(
self
):
# Submission is not list.
success
,
msg
=
validate_submission
(
u"A response."
,
self
.
PROMPT
,
STUB_I18N
)
self
.
assertFalse
(
success
)
# Submission count does not match prompt count.
success
,
msg
=
validate_submission
([
u"A response."
],
self
.
PROMPT
,
STUB_I18N
)
self
.
assertFalse
(
success
)
# Submission is not unicode.
success
,
msg
=
validate_submission
([
u"A response."
,
"Another response"
],
self
.
PROMPT
,
STUB_I18N
)
self
.
assertFalse
(
success
)
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