Commit 6088a926 by Victor Shnayder

Add showanswer="past_due" and tests

parent ea091a6e
......@@ -389,38 +389,43 @@ class CapaModule(XModule):
})
return json.dumps(d, cls=ComplexEncoder)
def is_past_due(self):
"""
Is it now past this problem's due date, including grace period?
"""
return (self.close_date is not None and
datetime.datetime.utcnow() > self.close_date)
def closed(self):
''' Is the student still allowed to submit answers? '''
if self.attempts == self.max_attempts:
return True
if self.close_date is not None and datetime.datetime.utcnow() > self.close_date:
if self.is_past_due():
return True
return False
def answer_available(self):
''' Is the user allowed to see an answer?
'''
Is the user allowed to see an answer?
'''
if self.show_answer == '':
return False
if self.show_answer == "never":
elif self.show_answer == "never":
return False
# Admins can see the answer, unless the problem explicitly prevents it
if self.system.user_is_staff:
elif self.system.user_is_staff:
# This i after the 'never' check because admins can see the answer
# unless the problem explicitly prevents it
return True
if self.show_answer == 'attempted':
elif self.show_answer == 'attempted':
return self.attempts > 0
if self.show_answer == 'answered':
elif self.show_answer == 'answered':
return self.lcp.done
if self.show_answer == 'closed':
elif self.show_answer == 'closed':
return self.closed()
if self.show_answer == 'always':
elif self.show_answer == 'past_due':
return self.is_past_due()
elif self.show_answer == 'always':
return True
return False
......
......@@ -138,10 +138,11 @@ class CapaModuleTest(unittest.TestCase):
def test_showanswer_closed(self):
# can see after attempts used up
# can see after attempts used up, even with due date in the future
used_all_attempts = CapaFactory.create(showanswer='closed',
max_attempts="1",
attempts="1")
attempts="1",
due=self.tomorrow_str)
self.assertTrue(used_all_attempts.answer_available())
......@@ -152,6 +153,7 @@ class CapaModuleTest(unittest.TestCase):
due=self.yesterday_str)
self.assertTrue(after_due_date.answer_available())
# can't see because attempts left
attempts_left_open = CapaFactory.create(showanswer='closed',
max_attempts="1",
......@@ -169,4 +171,45 @@ class CapaModuleTest(unittest.TestCase):
def test_showanswer_past_due(self):
"""
With showanswer="past_due" should only show answer after the problem is closed
for everyone--e.g. after due date + grace period.
"""
# can see after attempts used up, even with due date in the future
used_all_attempts = CapaFactory.create(showanswer='past_due',
max_attempts="1",
attempts="1",
due=self.tomorrow_str)
self.assertFalse(used_all_attempts.answer_available())
# can see after due date
past_due_date = CapaFactory.create(showanswer='past_due',
max_attempts="1",
attempts="0",
due=self.yesterday_str)
self.assertTrue(past_due_date.answer_available())
# can't see because attempts left
attempts_left_open = CapaFactory.create(showanswer='past_due',
max_attempts="1",
attempts="0",
due=self.tomorrow_str)
self.assertFalse(attempts_left_open.answer_available())
# Can't see because grace period hasn't expired, even though have no more
# attempts.
still_in_grace = CapaFactory.create(showanswer='past_due',
max_attempts="1",
attempts="1",
due=self.yesterday_str,
graceperiod=self.two_day_delta_str)
self.assertFalse(still_in_grace.answer_available())
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