Commit 94f6e685 by Ned Batchelder

Mock the response from the snuggletex server, and unskip the SymbolicResponse test.

parent c04f3e09
...@@ -10,6 +10,7 @@ import os ...@@ -10,6 +10,7 @@ import os
import random import random
import unittest import unittest
import textwrap import textwrap
import mock
from . import test_system from . import test_system
...@@ -186,7 +187,6 @@ class ImageResponseTest(ResponseTest): ...@@ -186,7 +187,6 @@ class ImageResponseTest(ResponseTest):
class SymbolicResponseTest(unittest.TestCase): class SymbolicResponseTest(unittest.TestCase):
def test_sr_grade(self): def test_sr_grade(self):
raise SkipTest() # This test fails due to dependencies on a local copy of snuggletex-webapp. Until we have figured that out, we'll just skip this test
symbolicresponse_file = os.path.dirname(__file__) + "/test_files/symbolicresponse.xml" symbolicresponse_file = os.path.dirname(__file__) + "/test_files/symbolicresponse.xml"
test_lcp = lcp.LoncapaProblem(open(symbolicresponse_file).read(), '1', system=test_system) test_lcp = lcp.LoncapaProblem(open(symbolicresponse_file).read(), '1', system=test_system)
correct_answers = {'1_2_1': 'cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]', correct_answers = {'1_2_1': 'cos(theta)*[[1,0],[0,1]] + i*sin(theta)*[[0,1],[1,0]]',
...@@ -264,14 +264,25 @@ class SymbolicResponseTest(unittest.TestCase): ...@@ -264,14 +264,25 @@ class SymbolicResponseTest(unittest.TestCase):
} }
wrong_answers = {'1_2_1': '2', wrong_answers = {'1_2_1': '2',
'1_2_1_dynamath': ''' '1_2_1_dynamath': '''
<math xmlns="http://www.w3.org/1998/Math/MathML"> <math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true"> <mstyle displaystyle="true">
<mn>2</mn> <mn>2</mn>
</mstyle> </mstyle>
</math>''', </math>''',
} }
self.assertEquals(test_lcp.grade_answers(correct_answers).get_correctness('1_2_1'), 'correct')
self.assertEquals(test_lcp.grade_answers(wrong_answers).get_correctness('1_2_1'), 'incorrect') import requests
d = os.path.dirname(__file__)
correct_snuggletex_response = open(os.path.join(d, "test_files/snuggletex_correct.html")).read().decode('utf8')
wrong_snuggletex_response = open(os.path.join(d, "test_files/snuggletex_wrong.html")).read().decode('utf8')
with mock.patch.object(requests, 'post') as mock_post:
mock_post.return_value.text = correct_snuggletex_response
self.assertEquals(test_lcp.grade_answers(correct_answers).get_correctness('1_2_1'), 'correct')
with mock.patch.object(requests, 'post') as mock_post:
mock_post.return_value.text = wrong_snuggletex_response
self.assertEquals(test_lcp.grade_answers(wrong_answers).get_correctness('1_2_1'), 'incorrect')
class OptionResponseTest(ResponseTest): class OptionResponseTest(ResponseTest):
......
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