Commit 6d94b712 by Ned Batchelder

Clean up test files, no substantive changes.

These changes prepare for the changes to the tests that are coming, but
make no change to the behavior themselves.
parent 8d01a36e
...@@ -8,9 +8,10 @@ Tests of the Capa XModule ...@@ -8,9 +8,10 @@ Tests of the Capa XModule
#pylint: disable=C0302 #pylint: disable=C0302
import datetime import datetime
import unittest
import random
import json import json
import random
import textwrap
import unittest
from mock import Mock, patch from mock import Mock, patch
from webob.multidict import MultiDict from webob.multidict import MultiDict
...@@ -33,42 +34,47 @@ class CapaFactory(object): ...@@ -33,42 +34,47 @@ class CapaFactory(object):
A helper class to create problem modules with various parameters for testing. A helper class to create problem modules with various parameters for testing.
""" """
sample_problem_xml = """<?xml version="1.0"?> sample_problem_xml = textwrap.dedent("""\
<problem> <?xml version="1.0"?>
<text> <problem>
<p>What is pi, to two decimal placs?</p> <text>
</text> <p>What is pi, to two decimal places?</p>
<numericalresponse answer="3.14"> </text>
<textline math="1" size="30"/> <numericalresponse answer="3.14">
</numericalresponse> <textline math="1" size="30"/>
</problem> </numericalresponse>
""" </problem>
""")
num = 0 num = 0
@staticmethod @classmethod
def next_num(): def next_num(cls):
CapaFactory.num += 1 cls.num += 1
return CapaFactory.num return cls.num
@staticmethod @classmethod
def input_key(): def input_key(cls, input_num=2):
""" """
Return the input key to use when passing GET parameters Return the input key to use when passing GET parameters
""" """
return ("input_" + CapaFactory.answer_key()) return ("input_" + cls.answer_key(input_num))
@staticmethod @classmethod
def answer_key(): def answer_key(cls, input_num=2):
""" """
Return the key stored in the capa problem answer dict Return the key stored in the capa problem answer dict
""" """
return ("-".join(['i4x', 'edX', 'capa_test', 'problem', return (
'SampleProblem%d' % CapaFactory.num]) + "%s_%d_1" % (
"_2_1") "-".join(['i4x', 'edX', 'capa_test', 'problem', 'SampleProblem%d' % cls.num]),
input_num,
)
)
@staticmethod @classmethod
def create(graceperiod=None, def create(cls,
graceperiod=None,
due=None, due=None,
max_attempts=None, max_attempts=None,
showanswer=None, showanswer=None,
...@@ -97,8 +103,8 @@ class CapaFactory(object): ...@@ -97,8 +103,8 @@ class CapaFactory(object):
attempts: also added to instance state. Will be converted to an int. attempts: also added to instance state. Will be converted to an int.
""" """
location = Location(["i4x", "edX", "capa_test", "problem", location = Location(["i4x", "edX", "capa_test", "problem",
"SampleProblem{0}".format(CapaFactory.next_num())]) "SampleProblem{0}".format(cls.next_num())])
field_data = {'data': CapaFactory.sample_problem_xml} field_data = {'data': cls.sample_problem_xml}
if graceperiod is not None: if graceperiod is not None:
field_data['graceperiod'] = graceperiod field_data['graceperiod'] = graceperiod
......
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