本文整理汇总了Python中student.models.ManualEnrollmentAudit.create_manual_enrollment_audit方法的典型用法代码示例。如果您正苦于以下问题:Python ManualEnrollmentAudit.create_manual_enrollment_audit方法的具体用法?Python ManualEnrollmentAudit.create_manual_enrollment_audit怎么用?Python ManualEnrollmentAudit.create_manual_enrollment_audit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.ManualEnrollmentAudit
的用法示例。
在下文中一共展示了ManualEnrollmentAudit.create_manual_enrollment_audit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_manual_enrollment_history
# 需要导入模块: from student.models import ManualEnrollmentAudit [as 别名]
# 或者: from student.models.ManualEnrollmentAudit import create_manual_enrollment_audit [as 别名]
def test_get_manual_enrollment_history(self):
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.user,
self.student.email,
ENROLLED_TO_ENROLLED,
'Financial Assistance',
CourseEnrollment.objects.get(course_id=self.course.id, user=self.student) # pylint: disable=no-member
)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertDictContainsSubset({
'enrolled_by': self.user.email,
'reason': 'Financial Assistance',
}, json.loads(response.content)[0]['manual_enrollment'])
示例2: test_retirement
# 需要导入模块: from student.models import ManualEnrollmentAudit [as 别名]
# 或者: from student.models.ManualEnrollmentAudit import create_manual_enrollment_audit [as 别名]
def test_retirement(self):
"""
Tests that calling the retirement method for a specific enrollment retires
the enrolled_email and reason columns of each row associated with that
enrollment.
"""
enrollment = CourseEnrollment.enroll(self.user, self.course.id)
other_enrollment = CourseEnrollment.enroll(self.user, self.other_course.id)
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.instructor, self.user.email, ALLOWEDTOENROLL_TO_ENROLLED,
'manually enrolling unenrolled user', enrollment
)
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.instructor, self.user.email, ALLOWEDTOENROLL_TO_ENROLLED,
'manually enrolling unenrolled user again', enrollment
)
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.instructor, self.user.email, ALLOWEDTOENROLL_TO_ENROLLED,
'manually enrolling unenrolled user', other_enrollment
)
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.instructor, self.user.email, ALLOWEDTOENROLL_TO_ENROLLED,
'manually enrolling unenrolled user again', other_enrollment
)
self.assertTrue(ManualEnrollmentAudit.objects.filter(enrollment=enrollment).exists())
# retire the ManualEnrollmentAudit objects associated with the above enrollments
enrollments = CourseEnrollment.objects.filter(user=self.user)
ManualEnrollmentAudit.retire_manual_enrollments(enrollments=enrollments, retired_email="xxx")
self.assertTrue(ManualEnrollmentAudit.objects.filter(enrollment=enrollment).exists())
self.assertFalse(ManualEnrollmentAudit.objects.filter(enrollment=enrollment).exclude(
enrolled_email="xxx"
))
self.assertFalse(ManualEnrollmentAudit.objects.filter(enrollment=enrollment).exclude(
reason=""
))
示例3: test_student_manually_enrolled_in_detailed_enrollment_source
# 需要导入模块: from student.models import ManualEnrollmentAudit [as 别名]
# 或者: from student.models.ManualEnrollmentAudit import create_manual_enrollment_audit [as 别名]
def test_student_manually_enrolled_in_detailed_enrollment_source(self):
"""
test to check the manually enrolled user enrollment report status
and enrollment source.
"""
student = UserFactory()
enrollment = CourseEnrollment.enroll(student, self.course.id)
ManualEnrollmentAudit.create_manual_enrollment_audit(
self.instructor, student.email, ALLOWEDTOENROLL_TO_ENROLLED,
'manually enrolling unenrolled user', enrollment
)
task_input = {'features': []}
with patch('instructor_task.tasks_helper._get_current_task'):
result = upload_enrollment_report(None, None, self.course.id, task_input, 'generating_enrollment_report')
enrollment_source = u'manually enrolled by user_id {user_id}, enrollment state transition: {transition}'.format(
user_id=self.instructor.id, transition=ALLOWEDTOENROLL_TO_ENROLLED) # pylint: disable=no-member
self.assertDictContainsSubset({'attempted': 1, 'succeeded': 1, 'failed': 0}, result)
self._verify_cell_data_in_csv(student.username, 'Enrollment Source', enrollment_source)
self._verify_cell_data_in_csv(student.username, 'Payment Status', 'TBD')
示例4: post
# 需要导入模块: from student.models import ManualEnrollmentAudit [as 别名]
# 或者: from student.models.ManualEnrollmentAudit import create_manual_enrollment_audit [as 别名]
def post(self, request, username_or_email):
"""Allows support staff to alter a user's enrollment."""
try:
user = User.objects.get(Q(username=username_or_email) | Q(email=username_or_email))
course_id = request.data['course_id']
course_key = CourseKey.from_string(course_id)
old_mode = request.data['old_mode']
new_mode = request.data['new_mode']
reason = request.data['reason']
enrollment = CourseEnrollment.objects.get(user=user, course_id=course_key)
if enrollment.mode != old_mode:
return HttpResponseBadRequest(u'User {username} is not enrolled with mode {old_mode}.'.format(
username=user.username,
old_mode=old_mode
))
if new_mode == CourseMode.CREDIT_MODE:
return HttpResponseBadRequest(u'Enrollment cannot be changed to credit mode.')
except KeyError as err:
return HttpResponseBadRequest(u'The field {} is required.'.format(text_type(err)))
except InvalidKeyError:
return HttpResponseBadRequest(u'Could not parse course key.')
except (CourseEnrollment.DoesNotExist, User.DoesNotExist):
return HttpResponseBadRequest(
u'Could not find enrollment for user {username} in course {course}.'.format(
username=username_or_email,
course=unicode(course_key)
)
)
try:
# Wrapped in a transaction so that we can be sure the
# ManualEnrollmentAudit record is always created correctly.
with transaction.atomic():
update_enrollment(user.username, course_id, mode=new_mode, include_expired=True)
manual_enrollment = ManualEnrollmentAudit.create_manual_enrollment_audit(
request.user,
enrollment.user.email,
ENROLLED_TO_ENROLLED,
reason=reason,
enrollment=enrollment
)
return JsonResponse(ManualEnrollmentSerializer(instance=manual_enrollment).data)
except CourseModeNotFoundError as err:
return HttpResponseBadRequest(text_type(err))