Skip to content

Commit

Permalink
feat: create ORA "date_config_type" field (#2013)
Browse files Browse the repository at this point in the history
* feat: add date_config_type field
  • Loading branch information
leangseu-edx authored Aug 17, 2023
1 parent 4550e49 commit 0c3f7b3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions openassessment/xblock/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,7 @@
DEFAULT_SELF_ASSESSMENT,
ACTIVE_STAFF_ASSESSMENT,
]

DATE_CONFIG_MANUAL = 'manual'
DATE_CONFIG_SUBSECTION = 'subsection'
DATE_CONFIG_COURSE_END = 'course_end'
13 changes: 13 additions & 0 deletions openassessment/xblock/openassessmentblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ class OpenAssessmentBlock(
help="Should the rubric be visible to learners in the response section?"
)

date_config_type = String(
default=DATE_CONFIG_MANUAL,
scope=Scope.settings,
help="The type of date configuration. Possible values are 'manual', 'subsection', and 'course_end'."
)

@property
def course_id(self):
return str(self.xmodule_runtime.course_id) # pylint: disable=no-member
Expand Down Expand Up @@ -1131,6 +1137,13 @@ def is_closed(self, step=None, course_staff=None):
if course_staff:
return False, None, DISTANT_PAST, DISTANT_FUTURE

if self.date_config_type == DATE_CONFIG_COURSE_END:
course = self.course
if course.start and course.end:
open_range = (course.start, course.end)
elif self.date_config_type == DATE_CONFIG_SUBSECTION and self.due:
open_range = (self.start, self.due)

if self.is_beta_tester:
beta_start = self._adjust_start_date_for_beta_testers(open_range[0])
open_range = (beta_start, open_range[1])
Expand Down
55 changes: 54 additions & 1 deletion openassessment/xblock/test/test_openassessment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from freezegun import freeze_time
from lxml import etree
from openassessment.workflow.errors import AssessmentWorkflowError
from openassessment.xblock import openassessmentblock
from openassessment.xblock import defaults, openassessmentblock
from openassessment.xblock.resolve_dates import DateValidationError, DISTANT_FUTURE, DISTANT_PAST

from .base import XBlockHandlerTestCase, scenario
Expand Down Expand Up @@ -1006,6 +1006,59 @@ def test_course_staff_dates(self, xblock):
course_staff=True
)

@scenario('data/basic_scenario.xml')
def test_date_config_type_course_end(self, xblock):
"""
Test that the date config type field set to course end date
"""
xblock.date_config_type = defaults.DATE_CONFIG_COURSE_END

mock_course = Mock()
mock_course.start = dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc)
mock_course.end = dt.datetime(2016, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc)
xblock.course = mock_course

# The problem should always be not be close if now is before course start date
self.assert_is_closed(
xblock,
dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc),
"abitrary", False, None,
mock_course.start, mock_course.end
)

# The problem should be closed if now is after course end date
self.assert_is_closed(
xblock,
dt.datetime(2016, 4, 1, 1, 1, 1, 2).replace(tzinfo=pytz.utc),
"abitrary", True, 'due',
mock_course.start, mock_course.end
)

@scenario('data/basic_scenario.xml')
def test_date_config_type_subsection(self, xblock):
"""
Test that the date config type field set to section
"""
xblock.date_config_type = defaults.DATE_CONFIG_SUBSECTION
xblock.start = dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc)
xblock.due = dt.datetime(2016, 4, 1, 1, 1, 1, 1).replace(tzinfo=pytz.utc)

# The problem should always be not be close if now is before section start date
self.assert_is_closed(
xblock,
dt.datetime(2016, 3, 31, 23, 59, 59).replace(tzinfo=pytz.utc),
"abitrary", False, None,
xblock.start, xblock.due
)

# The problem should be closed if now is after section due date
self.assert_is_closed(
xblock,
dt.datetime(2016, 4, 1, 1, 1, 1, 2).replace(tzinfo=pytz.utc),
"abitrary", True, 'due',
xblock.start, xblock.due
)

def assert_is_closed(
self, xblock, now, step, expected_is_closed, expected_reason,
expected_start, expected_due, released=None, course_staff=False,
Expand Down

0 comments on commit 0c3f7b3

Please sign in to comment.