本文整理汇总了Python中lms.djangoapps.verify_student.models.VerificationDeadline类的典型用法代码示例。如果您正苦于以下问题:Python VerificationDeadline类的具体用法?Python VerificationDeadline怎么用?Python VerificationDeadline使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VerificationDeadline类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_caching
def test_caching(self):
deadlines = {
CourseKey.from_string("edX/DemoX/Fall"): datetime.now(pytz.UTC),
CourseKey.from_string("edX/DemoX/Spring"): datetime.now(pytz.UTC) + timedelta(days=1)
}
course_keys = deadlines.keys()
# Initially, no deadlines are set
with self.assertNumQueries(1):
all_deadlines = VerificationDeadline.deadlines_for_courses(course_keys)
self.assertEqual(all_deadlines, {})
# Create the deadlines
for course_key, deadline in deadlines.iteritems():
VerificationDeadline.objects.create(
course_key=course_key,
deadline=deadline,
)
# Warm the cache
with self.assertNumQueries(1):
VerificationDeadline.deadlines_for_courses(course_keys)
# Load the deadlines from the cache
with self.assertNumQueries(0):
all_deadlines = VerificationDeadline.deadlines_for_courses(course_keys)
self.assertEqual(all_deadlines, deadlines)
# Delete the deadlines
VerificationDeadline.objects.all().delete()
# Verify that the deadlines are updated correctly
with self.assertNumQueries(1):
all_deadlines = VerificationDeadline.deadlines_for_courses(course_keys)
self.assertEqual(all_deadlines, {})
示例2: test_update_verification_deadline_left_alone
def test_update_verification_deadline_left_alone(self):
"""
When the course's verification deadline is set and an update request doesn't
include it, we should take no action on it.
"""
verification_deadline = datetime(year=1915, month=5, day=7, tzinfo=pytz.utc)
response, __ = self._get_update_response_and_expected_data(None, verification_deadline)
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)
verified_mode = CourseMode(
mode_slug=u'verified',
min_price=200,
currency=u'USD',
sku=u'ABC123',
bulk_sku=u'BULK-ABC123',
expiration_datetime=None
)
updated_data = self._serialize_course(self.course, [verified_mode], None)
# don't include the verification_deadline key in the PUT request
updated_data.pop('verification_deadline', None)
response = self.client.put(self.path, json.dumps(updated_data), content_type=JSON_CONTENT_TYPE)
self.assertEqual(response.status_code, 200)
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)
示例3: test_deadline
def test_deadline(self):
""" Verify deadline is set to course end date by signal when changed. """
deadline = datetime.now(tz=UTC) - timedelta(days=7)
VerificationDeadline.set_deadline(self.course.id, deadline)
_listen_for_course_publish('store', self.course.id)
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), self.course.end)
示例4: test_deadline_explicit
def test_deadline_explicit(self):
""" Verify deadline is unchanged by signal when explicitly set. """
deadline = datetime.now(tz=UTC) - timedelta(days=7)
VerificationDeadline.set_deadline(self.course.id, deadline, is_explicit=True)
_listen_for_course_publish('store', self.course.id)
actual_deadline = VerificationDeadline.deadline_for_course(self.course.id)
self.assertNotEqual(actual_deadline, self.course.end)
self.assertEqual(actual_deadline, deadline)
示例5: _setup_mode_and_enrollment
def _setup_mode_and_enrollment(self, deadline, enrollment_mode):
"""Create a course mode and enrollment.
Arguments:
deadline (datetime): The deadline for submitting your verification.
enrollment_mode (str): The mode of the enrollment.
"""
CourseModeFactory.create(course_id=self.course.id, mode_slug="verified", expiration_datetime=deadline)
CourseEnrollmentFactory(course_id=self.course.id, user=self.user, mode=enrollment_mode)
VerificationDeadline.set_deadline(self.course.id, deadline)
示例6: test_disable_verification_deadline
def test_disable_verification_deadline(self):
# Configure a verification deadline for the course
VerificationDeadline.set_deadline(self.course.id, self.VERIFICATION_DEADLINE)
# Create the course mode Django admin form
form = self._admin_form("verified", upgrade_deadline=self.UPGRADE_DEADLINE)
# Use the form to disable the verification deadline
self._set_form_verification_deadline(form, None)
form.save()
# Check that the deadline was disabled
self.assertIs(VerificationDeadline.deadline_for_course(self.course.id), None)
示例7: save
def save(self, *args, **kwargs): # pylint: disable=unused-argument
""" Save the CourseMode objects to the database. """
# Update the verification deadline for the course (not the individual modes)
VerificationDeadline.set_deadline(self.id, self.verification_deadline)
for mode in self.modes:
mode.course_id = self.id
mode.mode_display_name = self.get_mode_display_name(mode)
mode.save()
deleted_mode_ids = [mode.id for mode in self._deleted_modes]
CourseMode.objects.filter(id__in=deleted_mode_ids).delete()
self._deleted_modes = []
示例8: _configure
def _configure(self, mode, upgrade_deadline=None, verification_deadline=None):
"""Configure course modes and deadlines. """
course_mode = CourseMode.objects.create(
mode_slug=mode,
mode_display_name=mode,
)
if upgrade_deadline is not None:
course_mode.upgrade_deadline = upgrade_deadline
course_mode.save()
VerificationDeadline.set_deadline(self.course.id, verification_deadline)
return CourseModeForm(instance=course_mode)
示例9: save
def save(self, *args, **kwargs): # pylint: disable=unused-argument
""" Save the CourseMode objects to the database. """
if self.verification_deadline is not UNDEFINED:
# Override the verification deadline for the course (not the individual modes)
# This will delete verification deadlines for the course if self.verification_deadline is null
VerificationDeadline.set_deadline(self.id, self.verification_deadline, is_explicit=True)
for mode in self.modes:
mode.course_id = self.id
mode.mode_display_name = self.get_mode_display_name(mode)
mode.save()
deleted_mode_ids = [mode.id for mode in self._deleted_modes]
CourseMode.objects.filter(id__in=deleted_mode_ids).delete()
self._deleted_modes = []
示例10: test_set_verification_deadline
def test_set_verification_deadline(self, course_mode):
# Configure a verification deadline for the course
VerificationDeadline.set_deadline(self.course.id, self.VERIFICATION_DEADLINE)
# Create the course mode Django admin form
form = self._admin_form(course_mode)
# Update the verification deadline form data
# We need to set the date and time fields separately, since they're
# displayed as separate widgets in the form.
new_deadline = (self.VERIFICATION_DEADLINE + timedelta(days=1)).replace(microsecond=0)
self._set_form_verification_deadline(form, new_deadline)
form.save()
# Check that the deadline was updated
updated_deadline = VerificationDeadline.deadline_for_course(self.course.id)
self.assertEqual(updated_deadline, new_deadline)
示例11: test_update_remove_verification_deadline
def test_update_remove_verification_deadline(self):
"""
Verify that verification deadlines can be removed through the API.
"""
verification_deadline = datetime(year=1915, month=5, day=7, tzinfo=pytz.utc)
response, __ = self._get_update_response_and_expected_data(None, verification_deadline)
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)
verified_mode = CourseMode(
mode_slug=u"verified", min_price=200, currency=u"USD", sku=u"ABC123", expiration_datetime=None
)
updated_data = self._serialize_course(self.course, [verified_mode], None)
updated_data["verification_deadline"] = None
response = self.client.put(self.path, json.dumps(updated_data), content_type=JSON_CONTENT_TYPE)
self.assertEqual(response.status_code, 200)
self.assertIsNone(VerificationDeadline.deadline_for_course(self.course.id))
示例12: test_update
def test_update(self):
""" Verify the view supports updating a course. """
# Sanity check: Ensure no verification deadline is set
self.assertIsNone(VerificationDeadline.deadline_for_course(self.course.id))
# Generate the expected data
verification_deadline = datetime(year=2020, month=12, day=31, tzinfo=pytz.utc)
expiration_datetime = datetime.now(pytz.utc)
response, expected = self._get_update_response_and_expected_data(expiration_datetime, verification_deadline)
# Sanity check: The API should return HTTP status 200 for updates
self.assertEqual(response.status_code, 200)
# Verify the course and modes are returned as JSON
actual = json.loads(response.content)
self.assertEqual(actual, expected)
# Verify the verification deadline is updated
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)
示例13: test_load_verification_deadline
def test_load_verification_deadline(self, mode, expect_deadline):
# Configure a verification deadline for the course
VerificationDeadline.set_deadline(self.course.id, self.VERIFICATION_DEADLINE)
# Configure a course mode with both an upgrade and verification deadline
# and load the form to edit it.
deadline = self.UPGRADE_DEADLINE if mode == "verified" else None
form = self._admin_form(mode, upgrade_deadline=deadline)
# Check that the verification deadline is loaded,
# but ONLY for verified modes.
loaded_deadline = form.initial.get("verification_deadline")
if expect_deadline:
self.assertEqual(
loaded_deadline.replace(tzinfo=None),
self.VERIFICATION_DEADLINE.replace(tzinfo=None)
)
else:
self.assertIs(loaded_deadline, None)
示例14: test_update_verification_deadline_without_expiring_modes
def test_update_verification_deadline_without_expiring_modes(self):
""" Verify verification deadline can be set if no course modes expire.
This accounts for the verified professional mode, which requires verification but should never expire.
"""
verification_deadline = datetime(year=1915, month=5, day=7, tzinfo=pytz.utc)
response, __ = self._get_update_response_and_expected_data(None, verification_deadline)
self.assertEqual(response.status_code, 200)
self.assertEqual(VerificationDeadline.deadline_for_course(self.course.id), verification_deadline)
示例15: _serialize_course
def _serialize_course(cls, course, modes=None, verification_deadline=None):
""" Serializes a course to a Python dict. """
modes = modes or []
verification_deadline = verification_deadline or VerificationDeadline.deadline_for_course(course.id)
return {
u'id': unicode(course.id),
u'name': unicode(course.display_name),
u'verification_deadline': cls._serialize_datetime(verification_deadline),
u'modes': [cls._serialize_course_mode(mode) for mode in modes]
}