Commit f6db73e2 by Usman Khalid

Fixed submission_mixin tests.

TNL-708
parent f2e0dbda
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
<prompt> <prompt>
<description>Given the state of the world today, what do you think should be done to combat poverty? Please answer in a short essay of 200-300 words.</description> <description>Given the state of the world today, what do you think should be done to combat poverty? Please answer in a short essay of 200-300 words.</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts> </prompts>
<rubric> <rubric>
<criterion> <criterion>
......
<openassessment submission_due="2014-03-05"> <openassessment submission_due="2014-03-05">
<title>Open Assessment Test</title> <title>Open Assessment Test</title>
<prompt> <prompts>
Given the state of the world today, what do you think should be done to <prompt>
combat poverty? Please answer in a short essay of 200-300 words. <description>Given the state of the world today, what do you think should be done to combat poverty?</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric> <rubric>
<prompt>Read for conciseness, clarity of thought, and form.</prompt>
<criterion> <criterion>
<name>𝓒𝓸𝓷𝓬𝓲𝓼𝓮</name> <name>𝓒𝓸𝓷𝓬𝓲𝓼𝓮</name>
<prompt>How concise is it?</prompt> <prompt>How concise is it?</prompt>
......
<openassessment submission_start="2014-04-01" submission_due="2014-04-05"> <openassessment submission_start="2014-04-01" submission_due="2014-04-05">
<title>Open Assessment Test</title> <title>Open Assessment Test</title>
<prompt> <prompts>
Given the state of the world today, what do you think should be done to <prompt>
combat poverty? Please answer in a short essay of 200-300 words. <description>Given the state of the world today, what do you think should be done to combat poverty?</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric> <rubric>
<prompt>Read for conciseness, clarity of thought, and form.</prompt>
<criterion> <criterion>
<name>Concise</name> <name>Concise</name>
<prompt>How concise is it?</prompt> <prompt>How concise is it?</prompt>
......
<openassessment> <openassessment>
<title>Open Assessment Test</title> <title>Open Assessment Test</title>
<prompt> <prompts>
Given the state of the world today, what do you think should be done to <prompt>
combat poverty? Please answer in a short essay of 200-300 words. <description>Given the state of the world today, what do you think should be done to combat poverty?</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric> <rubric>
<prompt>Read for conciseness, clarity of thought, and form.</prompt>
<criterion> <criterion>
<name>Concise</name> <name>Concise</name>
<prompt>How concise is it?</prompt> <prompt>How concise is it?</prompt>
......
<openassessment submission_start="2014-04-01" submission_due="2999-05-06"> <openassessment submission_start="2014-04-01" submission_due="2999-05-06">
<title>Open Assessment Test</title> <title>Open Assessment Test</title>
<prompt> <prompts>
Given the state of the world today, what do you think should be done to <prompt>
combat poverty? Please answer in a short essay of 200-300 words. <description>Given the state of the world today, what do you think should be done to combat poverty?</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric> <rubric>
<prompt>Read for conciseness, clarity of thought, and form.</prompt>
<criterion> <criterion>
<name>Concise</name> <name>Concise</name>
<prompt>How concise is it?</prompt> <prompt>How concise is it?</prompt>
......
<openassessment submission_start="4999-04-01"> <openassessment submission_start="4999-04-01">
<title>Open Assessment Test</title> <title>Open Assessment Test</title>
<prompt> <prompts>
Given the state of the world today, what do you think should be done to <prompt>
combat poverty? Please answer in a short essay of 200-300 words. <description>Given the state of the world today, what do you think should be done to combat poverty?</description>
</prompt> </prompt>
<prompt>
<description>Given the state of the world today, what do you think should be done to combat pollution?</description>
</prompt>
</prompts>
<rubric> <rubric>
<prompt>Read for conciseness, clarity of thought, and form.</prompt> <prompt>Read for conciseness, clarity of thought, and form.</prompt>
<criterion> <criterion>
......
...@@ -5,17 +5,23 @@ Test submission to the OpenAssessment XBlock. ...@@ -5,17 +5,23 @@ Test submission to the OpenAssessment XBlock.
import json import json
import datetime as dt import datetime as dt
import pytz
from mock import patch, Mock from mock import patch, Mock
from openassessment.workflow import api as workflow_api import pytz
from submissions import api as sub_api from submissions import api as sub_api
from submissions.api import SubmissionRequestError, SubmissionInternalError from submissions.api import SubmissionRequestError, SubmissionInternalError
from openassessment.workflow import api as workflow_api
from openassessment.xblock.data_conversion import create_submission_dict, prepare_submission_for_serialization
from .base import XBlockHandlerTestCase, scenario from .base import XBlockHandlerTestCase, scenario
class SubmissionTest(XBlockHandlerTestCase): class SubmissionTest(XBlockHandlerTestCase):
SUBMISSION = json.dumps({"submission": "This is my answer to this test question!"}) SUBMISSION = json.dumps({
"submission": ["This is my answer to the first question!", "This is my answer to the second question!"]
})
@scenario('data/basic_scenario.xml', user_id='Bob') @scenario('data/basic_scenario.xml', user_id='Bob')
def test_submit_submission(self, xblock): def test_submit_submission(self, xblock):
...@@ -26,7 +32,7 @@ class SubmissionTest(XBlockHandlerTestCase): ...@@ -26,7 +32,7 @@ class SubmissionTest(XBlockHandlerTestCase):
def test_submit_answer_too_long(self, xblock): def test_submit_answer_too_long(self, xblock):
# Maximum answer length is 100K, once the answer has been JSON-encoded # Maximum answer length is 100K, once the answer has been JSON-encoded
long_submission = json.dumps({ long_submission = json.dumps({
'submission': 'longcat is long ' * 100000 "submission": ["This is my answer to the first question!" * 100000, "This is my answer to the second question!"]
}) })
resp = self.request(xblock, 'submit', long_submission, response_format='json') resp = self.request(xblock, 'submit', long_submission, response_format='json')
self.assertFalse(resp[0]) self.assertFalse(resp[0])
...@@ -117,12 +123,12 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -117,12 +123,12 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
# the submission. # the submission.
submission = xblock.create_submission( submission = xblock.create_submission(
xblock.get_student_item_dict(), xblock.get_student_item_dict(),
'A man must have a code' ('A man must have a code', 'A man must have an umbrella too.')
) )
self._assert_path_and_context( self._assert_path_and_context(
xblock, 'openassessmentblock/response/oa_response_submitted.html', xblock, 'openassessmentblock/response/oa_response_submitted.html',
{ {
'student_submission': submission, 'student_submission': create_submission_dict(submission, xblock.prompts),
'allow_file_upload': False, 'allow_file_upload': False,
'has_peer': True, 'has_peer': True,
'has_self': True, 'has_self': True,
...@@ -136,7 +142,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -136,7 +142,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
xblock, 'openassessmentblock/response/oa_response.html', xblock, 'openassessmentblock/response/oa_response.html',
{ {
'allow_file_upload': False, 'allow_file_upload': False,
'saved_response': '', 'saved_response': create_submission_dict({
'answer': prepare_submission_for_serialization(
("", "")
)
}, xblock.prompts),
'save_status': 'This response has not been saved.', 'save_status': 'This response has not been saved.',
'submit_enabled': False, 'submit_enabled': False,
'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc),
...@@ -152,7 +162,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -152,7 +162,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
xblock, 'openassessmentblock/response/oa_response.html', xblock, 'openassessmentblock/response/oa_response.html',
{ {
'allow_file_upload': False, 'allow_file_upload': False,
'saved_response': '', 'saved_response': create_submission_dict({
'answer': prepare_submission_for_serialization(
("", "")
)
}, xblock.prompts),
'save_status': 'This response has not been saved.', 'save_status': 'This response has not been saved.',
'submit_enabled': False, 'submit_enabled': False,
'has_peer': True, 'has_peer': True,
...@@ -164,7 +178,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -164,7 +178,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
@scenario('data/submission_open.xml', user_id="Bob") @scenario('data/submission_open.xml', user_id="Bob")
def test_open_saved_response(self, xblock): def test_open_saved_response(self, xblock):
# Save a response # Save a response
payload = json.dumps({'submission': 'A man must have a code'}) payload = json.dumps({'submission': ('A man must have a code', 'A man must have an umbrella too.')})
resp = self.request(xblock, 'save_submission', payload, response_format='json') resp = self.request(xblock, 'save_submission', payload, response_format='json')
self.assertTrue(resp['success']) self.assertTrue(resp['success'])
...@@ -172,7 +186,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -172,7 +186,11 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
xblock, 'openassessmentblock/response/oa_response.html', xblock, 'openassessmentblock/response/oa_response.html',
{ {
'allow_file_upload': False, 'allow_file_upload': False,
'saved_response': 'A man must have a code', 'saved_response': create_submission_dict({
'answer': prepare_submission_for_serialization(
('A man must have a code', 'A man must have an umbrella too.')
)
}, xblock.prompts),
'save_status': 'This response has been saved but not submitted.', 'save_status': 'This response has been saved but not submitted.',
'submit_enabled': True, 'submit_enabled': True,
'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc),
...@@ -186,13 +204,13 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -186,13 +204,13 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
def test_open_submitted(self, xblock): def test_open_submitted(self, xblock):
submission = xblock.create_submission( submission = xblock.create_submission(
xblock.get_student_item_dict(), xblock.get_student_item_dict(),
'A man must have a code' ('A man must have a code', 'A man must have an umbrella too.')
) )
self._assert_path_and_context( self._assert_path_and_context(
xblock, 'openassessmentblock/response/oa_response_submitted.html', xblock, 'openassessmentblock/response/oa_response_submitted.html',
{ {
'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc),
'student_submission': submission, 'student_submission': create_submission_dict(submission, xblock.prompts),
'allow_file_upload': False, 'allow_file_upload': False,
'has_peer': True, 'has_peer': True,
'has_self': True, 'has_self': True,
...@@ -256,13 +274,13 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -256,13 +274,13 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
def test_closed_submitted(self, xblock): def test_closed_submitted(self, xblock):
submission = xblock.create_submission( submission = xblock.create_submission(
xblock.get_student_item_dict(), xblock.get_student_item_dict(),
'A man must have a code' ('A man must have a code', 'A man must have an umbrella too.')
) )
self._assert_path_and_context( self._assert_path_and_context(
xblock, 'openassessmentblock/response/oa_response_submitted.html', xblock, 'openassessmentblock/response/oa_response_submitted.html',
{ {
'submission_due': dt.datetime(2014, 4, 5).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2014, 4, 5).replace(tzinfo=pytz.utc),
'student_submission': submission, 'student_submission': create_submission_dict(submission, xblock.prompts),
'allow_file_upload': False, 'allow_file_upload': False,
'has_peer': False, 'has_peer': False,
'has_self': True, 'has_self': True,
...@@ -275,7 +293,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -275,7 +293,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
# Create a submission # Create a submission
submission = xblock.create_submission( submission = xblock.create_submission(
xblock.get_student_item_dict(), xblock.get_student_item_dict(),
'A man must have a code' ('A man must have a code', 'A man must have an umbrella too.')
) )
# Simulate the user receiving a grade # Simulate the user receiving a grade
...@@ -288,7 +306,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -288,7 +306,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
xblock, 'openassessmentblock/response/oa_response_graded.html', xblock, 'openassessmentblock/response/oa_response_graded.html',
{ {
'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2999, 5, 6).replace(tzinfo=pytz.utc),
'student_submission': submission, 'student_submission': create_submission_dict(submission, xblock.prompts),
'allow_file_upload': False, 'allow_file_upload': False,
'has_peer': True, 'has_peer': True,
'has_self': True, 'has_self': True,
...@@ -301,7 +319,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -301,7 +319,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
# Create a submission # Create a submission
submission = xblock.create_submission( submission = xblock.create_submission(
xblock.get_student_item_dict(), xblock.get_student_item_dict(),
'A man must have a code' ('A man must have a code', 'A man must have an umbrella too.')
) )
# Simulate the user receiving a grade # Simulate the user receiving a grade
...@@ -314,7 +332,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -314,7 +332,7 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
xblock, 'openassessmentblock/response/oa_response_graded.html', xblock, 'openassessmentblock/response/oa_response_graded.html',
{ {
'submission_due': dt.datetime(2014, 4, 5).replace(tzinfo=pytz.utc), 'submission_due': dt.datetime(2014, 4, 5).replace(tzinfo=pytz.utc),
'student_submission': submission, 'student_submission': create_submission_dict(submission, xblock.prompts),
'allow_file_upload': False, 'allow_file_upload': False,
'has_peer': False, 'has_peer': False,
'has_self': True, 'has_self': True,
...@@ -330,7 +348,10 @@ class SubmissionRenderTest(XBlockHandlerTestCase): ...@@ -330,7 +348,10 @@ class SubmissionRenderTest(XBlockHandlerTestCase):
self.assertIn('Monday, May 6, 2999 00:00 UTC', resp) self.assertIn('Monday, May 6, 2999 00:00 UTC', resp)
# Create a submission for the user # Create a submission for the user
xblock.create_submission(xblock.get_student_item_dict(), u'Ⱥ mȺn mᵾsŧ ħȺvɇ Ⱥ ȼøđɇ.') xblock.create_submission(
xblock.get_student_item_dict(),
(u'Ⱥ mȺn mᵾsŧ ħȺvɇ Ⱥ ȼøđɇ.', u'∀ ɯɐu ɯnsʇ ɥɐʌǝ ɐu nɯqɹǝllɐ ʇoo˙'),
)
# Expect that the response step is "submitted" # Expect that the response step is "submitted"
resp = self.request(xblock, 'render_submission', json.dumps(dict())) resp = self.request(xblock, 'render_submission', json.dumps(dict()))
......
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