Commit 6ec3b94d by Will Daly

Added test for capa module closed() method; modified

closed() to handle edge cases
parent 49784009
...@@ -419,7 +419,7 @@ class CapaModule(XModule): ...@@ -419,7 +419,7 @@ class CapaModule(XModule):
def closed(self): def closed(self):
''' Is the student still allowed to submit answers? ''' ''' Is the student still allowed to submit answers? '''
if self.attempts == self.max_attempts: if self.max_attempts is not None and self.attempts >= self.max_attempts:
return True return True
if self.is_past_due(): if self.is_past_due():
return True return True
......
...@@ -286,6 +286,34 @@ class CapaModuleTest(unittest.TestCase): ...@@ -286,6 +286,34 @@ class CapaModuleTest(unittest.TestCase):
self.assertTrue(still_in_grace.answer_available()) self.assertTrue(still_in_grace.answer_available())
def test_closed(self):
# Attempts < Max attempts --> NOT closed
module = CapaFactory.create(max_attempts="1", attempts="0")
self.assertFalse(module.closed())
# Attempts < Max attempts --> NOT closed
module = CapaFactory.create(max_attempts="2", attempts="1")
self.assertFalse(module.closed())
# Attempts = Max attempts --> closed
module = CapaFactory.create(max_attempts="1", attempts="1")
self.assertTrue(module.closed())
# Attempts > Max attempts --> closed
module = CapaFactory.create(max_attempts="1", attempts="2")
self.assertTrue(module.closed())
# Max attempts = 0 --> closed
module = CapaFactory.create(max_attempts="0", attempts="2")
self.assertTrue(module.closed())
# Past due --> closed
module = CapaFactory.create(max_attempts="1", attempts="0",
due=self.yesterday_str)
self.assertTrue(module.closed())
def test_parse_get_params(self): def test_parse_get_params(self):
# Valid GET param dict # Valid GET param dict
...@@ -522,3 +550,21 @@ class CapaModuleTest(unittest.TestCase): ...@@ -522,3 +550,21 @@ class CapaModuleTest(unittest.TestCase):
# Expect that the problem was NOT reset # Expect that the problem was NOT reset
self.assertTrue('success' in result and not result['success']) self.assertTrue('success' in result and not result['success'])
def test_save_problem(self):
module = CapaFactory.create()
# Simulate
def test_save_problem_closed(self):
self.fail()
def test_save_problem_submitted_with_randomize(self):
self.fail()
def test_save_problem_submitted_no_randomize(self):
self.fail()
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