本文整理汇总了Python中student.models.CourseEnrollment类的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment类的具体用法?Python CourseEnrollment怎么用?Python CourseEnrollment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseEnrollment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enroll
def test_enroll(self, course_modes, next_url, enrollment_mode):
# Create the course modes (if any) required for this test case
for mode_slug in course_modes:
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=mode_slug,
mode_display_name=mode_slug,
)
# Reverse the expected next URL, if one is provided
# (otherwise, use an empty string, which the JavaScript client
# interprets as a redirect to the dashboard)
full_url = (
reverse(next_url, kwargs={'course_id': unicode(self.course.id)})
if next_url else next_url
)
# Enroll in the course and verify the URL we get sent to
resp = self._change_enrollment('enroll')
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content, full_url)
# If we're not expecting to be enrolled, verify that this is the case
if enrollment_mode is None:
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
# Otherwise, verify that we're enrolled with the expected course mode
else:
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course.id))
course_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
self.assertTrue(is_active)
self.assertEqual(course_mode, enrollment_mode)
示例2: test_linked_in_add_to_profile_btn_not_appearing_without_config
def test_linked_in_add_to_profile_btn_not_appearing_without_config(self):
# Without linked-in config don't show Add Certificate to LinkedIn button
self.client.login(username="jack", password="test")
CourseModeFactory.create(
course_id=self.course.id,
mode_slug='verified',
mode_display_name='verified',
expiration_datetime=datetime.now(pytz.UTC) - timedelta(days=1)
)
CourseEnrollment.enroll(self.user, self.course.id, mode='honor')
self.course.start = datetime.now(pytz.UTC) - timedelta(days=2)
self.course.end = datetime.now(pytz.UTC) - timedelta(days=1)
self.course.display_name = u"Omega"
self.course = self.update_course(self.course, self.user.id)
download_url = 'www.edx.org'
GeneratedCertificateFactory.create(
user=self.user,
course_id=self.course.id,
status=CertificateStatuses.downloadable,
mode='honor',
grade='67',
download_url=download_url
)
response = self.client.get(reverse('dashboard'))
self.assertEquals(response.status_code, 200)
self.assertNotIn('Add Certificate to LinkedIn', response.content)
response_url = 'http://www.linkedin.com/profile/add?_ed='
self.assertNotContains(response, escape(response_url))
示例3: test_transfer_students
def test_transfer_students(self):
student = UserFactory()
student.set_password(self.PASSWORD) # pylint: disable=E1101
student.save() # pylint: disable=E1101
# Original Course
original_course_location = locator.CourseLocator('Org0', 'Course0', 'Run0')
course = self._create_course(original_course_location)
# Enroll the student in 'verified'
CourseEnrollment.enroll(student, course.id, mode="verified")
# New Course 1
course_location_one = locator.CourseLocator('Org1', 'Course1', 'Run1')
new_course_one = self._create_course(course_location_one)
# New Course 2
course_location_two = locator.CourseLocator('Org2', 'Course2', 'Run2')
new_course_two = self._create_course(course_location_two)
original_key = unicode(course.id)
new_key_one = unicode(new_course_one.id)
new_key_two = unicode(new_course_two.id)
# Run the actual management command
transfer_students.Command().handle(
source_course=original_key, dest_course_list=new_key_one + "," + new_key_two
)
# Confirm the enrollment mode is verified on the new courses, and enrollment is enabled as appropriate.
self.assertEquals(('verified', False), CourseEnrollment.enrollment_mode_for_user(student, course.id))
self.assertEquals(('verified', True), CourseEnrollment.enrollment_mode_for_user(student, new_course_one.id))
self.assertEquals(('verified', True), CourseEnrollment.enrollment_mode_for_user(student, new_course_two.id))
示例4: test_unenrolled_from_some_courses
def test_unenrolled_from_some_courses(self):
# Enroll in several courses in the org
self._create_courses_and_enrollments(
(self.TEST_ORG, True),
(self.TEST_ORG, True),
(self.TEST_ORG, True),
("org_alias", True)
)
# Set a preference for the aliased course
self._set_opt_in_pref(self.user, "org_alias", False)
# Unenroll from the aliased course
CourseEnrollment.unenroll(self.user, self.courses[3].id, skip_refund=True)
# Expect that the preference still applies,
# and all the enrollments should appear in the list
output = self._run_command(self.TEST_ORG, other_names=["org_alias"])
self._assert_output(
output,
(self.user, self.courses[0].id, False),
(self.user, self.courses[1].id, False),
(self.user, self.courses[2].id, False),
(self.user, self.courses[3].id, False)
)
示例5: setUp
def setUp(self):
super(CertificateExceptionViewInstructorApiTest, self).setUp()
self.global_staff = GlobalStaffFactory()
self.instructor = InstructorFactory(course_key=self.course.id)
self.user = UserFactory()
self.user2 = UserFactory()
CourseEnrollment.enroll(self.user, self.course.id)
CourseEnrollment.enroll(self.user2, self.course.id)
self.url = reverse('certificate_exception_view', kwargs={'course_id': unicode(self.course.id)})
certificate_white_list_item = CertificateWhitelistFactory.create(
user=self.user2,
course_id=self.course.id,
)
self.certificate_exception = dict(
created="",
notes="Test Notes for Test Certificate Exception",
user_email='',
user_id='',
user_name=unicode(self.user.username)
)
self.certificate_exception_in_db = dict(
id=certificate_white_list_item.id,
user_name=certificate_white_list_item.user.username,
notes=certificate_white_list_item.notes,
user_email=certificate_white_list_item.user.email,
user_id=certificate_white_list_item.user.id,
)
# Enable certificate generation
cache.clear()
CertificateGenerationConfiguration.objects.create(enabled=True)
self.client.login(username=self.global_staff.username, password='test')
示例6: test_unenrollment_email_off
def test_unenrollment_email_off(self):
"""
Do un-enrollment email off test
"""
course = self.course
# Run the Un-enroll students command
url = reverse('instructor_dashboard_legacy', kwargs={'course_id': course.id.to_deprecated_string()})
response = self.client.post(
url,
{
'action': 'Unenroll multiple students',
'multiple_students': '[email protected] [email protected]'
}
)
# Check the page output
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>[email protected]</td>')
self.assertContains(response, '<td>un-enrolled</td>')
# Check the enrollment table
user = User.objects.get(email='[email protected]')
self.assertFalse(CourseEnrollment.is_enrolled(user, course.id))
user = User.objects.get(email='[email protected]')
self.assertFalse(CourseEnrollment.is_enrolled(user, course.id))
# Check the outbox
self.assertEqual(len(mail.outbox), 0)
示例7: setUp
def setUp(self):
super(GradeTestBase, self).setUp()
self.request = get_request_for_user(UserFactory())
self.client.login(username=self.request.user.username, password="test")
self.subsection_grade_factory = SubsectionGradeFactory(self.request.user)
self.course_structure = get_course_blocks(self.request.user, self.course.location)
CourseEnrollment.enroll(self.request.user, self.course.id)
示例8: test_score_recalculation_on_enrollment_update
def test_score_recalculation_on_enrollment_update(self):
"""
Test that an update in enrollment cause score recalculation.
Note:
Score recalculation task must be called with a delay of SCORE_RECALCULATION_DELAY_ON_ENROLLMENT_UPDATE
"""
course_modes = ['verified', 'audit']
for mode_slug in course_modes:
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=mode_slug,
mode_display_name=mode_slug,
)
CourseEnrollment.enroll(self.user, self.course.id, mode="audit")
local_task_args = dict(
user_id=self.user.id,
course_key=str(self.course.id)
)
with patch(
'lms.djangoapps.grades.tasks.recalculate_course_and_subsection_grades_for_user.apply_async',
return_value=None
) as mock_task_apply:
CourseEnrollment.enroll(self.user, self.course.id, mode="verified")
mock_task_apply.assert_called_once_with(
countdown=SCORE_RECALCULATION_DELAY_ON_ENROLLMENT_UPDATE,
kwargs=local_task_args
)
示例9: setUp
def setUp(self):
super(TeamAPITestCase, self).setUp()
self.topics_count = 4
self.users = {
"student_unenrolled": UserFactory.create(password=self.test_password),
"student_enrolled": UserFactory.create(password=self.test_password),
"student_enrolled_not_on_team": UserFactory.create(password=self.test_password),
# This student is enrolled in both test courses and is a member of a team in each course, but is not on the
# same team as student_enrolled.
"student_enrolled_both_courses_other_team": UserFactory.create(password=self.test_password),
"staff": AdminFactory.create(password=self.test_password),
"course_staff": StaffFactory.create(course_key=self.test_course_1.id, password=self.test_password),
}
# 'solar team' is intentionally lower case to test case insensitivity in name ordering
self.test_team_1 = CourseTeamFactory.create(
name=u"sólar team", course_id=self.test_course_1.id, topic_id="topic_0"
)
self.test_team_2 = CourseTeamFactory.create(name="Wind Team", course_id=self.test_course_1.id)
self.test_team_3 = CourseTeamFactory.create(name="Nuclear Team", course_id=self.test_course_1.id)
self.test_team_4 = CourseTeamFactory.create(name="Coal Team", course_id=self.test_course_1.id, is_active=False)
self.test_team_5 = CourseTeamFactory.create(name="Another Team", course_id=self.test_course_2.id)
for user, course in [
("student_enrolled", self.test_course_1),
("student_enrolled_not_on_team", self.test_course_1),
("student_enrolled_both_courses_other_team", self.test_course_1),
("student_enrolled_both_courses_other_team", self.test_course_2),
]:
CourseEnrollment.enroll(self.users[user], course.id, check_access=True)
self.test_team_1.add_user(self.users["student_enrolled"])
self.test_team_3.add_user(self.users["student_enrolled_both_courses_other_team"])
self.test_team_5.add_user(self.users["student_enrolled_both_courses_other_team"])
示例10: test_course_goal_updates
def test_course_goal_updates(self):
"""
Ensure that the following five use cases work as expected.
1) Unenrolled users are not shown the update goal selection field.
2) Enrolled users are not shown the update goal selection field if they have not yet set a course goal.
3) Enrolled users are shown the update goal selection field if they have set a course goal.
4) Enrolled users in the verified track are shown the update goal selection field.
"""
# Create a course with a verified track.
verifiable_course = CourseFactory.create()
add_course_mode(verifiable_course, upgrade_deadline_expired=False)
# Verify that unenrolled users are not shown the update goal selection field.
user = self.create_user_for_course(verifiable_course, CourseUserType.UNENROLLED)
response = self.client.get(course_home_url(verifiable_course))
self.assertNotContains(response, TEST_COURSE_GOAL_UPDATE_FIELD)
# Verify that enrolled users that have not set a course goal are shown a hidden update goal selection field.
enrollment = CourseEnrollment.enroll(user, verifiable_course.id)
response = self.client.get(course_home_url(verifiable_course))
self.assertContains(response, TEST_COURSE_GOAL_UPDATE_FIELD_HIDDEN)
# Verify that enrolled users that have set a course goal are shown a visible update goal selection field.
add_course_goal(user, verifiable_course.id, COURSE_GOAL_DISMISS_OPTION)
response = self.client.get(course_home_url(verifiable_course))
self.assertContains(response, TEST_COURSE_GOAL_UPDATE_FIELD)
self.assertNotContains(response, TEST_COURSE_GOAL_UPDATE_FIELD_HIDDEN)
# Verify that enrolled and verified users are shown the update goal selection
CourseEnrollment.update_enrollment(enrollment, is_active=True, mode=CourseMode.VERIFIED)
response = self.client.get(course_home_url(verifiable_course))
self.assertContains(response, TEST_COURSE_GOAL_UPDATE_FIELD)
self.assertNotContains(response, TEST_COURSE_GOAL_UPDATE_FIELD_HIDDEN)
示例11: test_refund_cert_callback_before_expiration_email
def test_refund_cert_callback_before_expiration_email(self):
""" Test that refund emails are being sent correctly. """
course = CourseFactory.create()
course_key = course.id
many_days = datetime.timedelta(days=60)
course_mode = CourseMode(course_id=course_key,
mode_slug="verified",
mode_display_name="verified cert",
min_price=self.cost,
expiration_datetime=datetime.datetime.now(pytz.utc) + many_days)
course_mode.save()
CourseEnrollment.enroll(self.user, course_key, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, course_key, self.cost, 'verified')
cart.purchase()
mail.outbox = []
with patch('shoppingcart.models.log.error') as mock_error_logger:
CourseEnrollment.unenroll(self.user, course_key)
self.assertFalse(mock_error_logger.called)
self.assertEquals(len(mail.outbox), 1)
self.assertEquals('[Refund] User-Requested Refund', mail.outbox[0].subject)
self.assertEquals(settings.PAYMENT_SUPPORT_EMAIL, mail.outbox[0].from_email)
self.assertIn('has requested a refund on Order', mail.outbox[0].body)
示例12: test_refund_cert_callback_before_expiration
def test_refund_cert_callback_before_expiration(self):
# If the expiration date has not yet passed on a verified mode, the user can be refunded
many_days = datetime.timedelta(days=60)
course = CourseFactory.create()
self.course_key = course.id
course_mode = CourseMode(course_id=self.course_key,
mode_slug="verified",
mode_display_name="verified cert",
min_price=self.cost,
expiration_datetime=(datetime.datetime.now(pytz.utc) + many_days))
course_mode.save()
# need to prevent analytics errors from appearing in stderr
with patch('sys.stderr', sys.stdout.write):
CourseEnrollment.enroll(self.user, self.course_key, 'verified')
cart = Order.get_cart_for_user(user=self.user)
CertificateItem.add_to_order(cart, self.course_key, self.cost, 'verified')
cart.purchase()
CourseEnrollment.unenroll(self.user, self.course_key)
target_certs = CertificateItem.objects.filter(course_id=self.course_key, user_id=self.user, status='refunded', mode='verified')
self.assertTrue(target_certs[0])
self.assertTrue(target_certs[0].refund_requested_time)
self.assertEquals(target_certs[0].order.status, 'refunded')
self._assert_refund_tracked()
示例13: test_student_progress_with_valid_and_invalid_id
def test_student_progress_with_valid_and_invalid_id(self, default_store):
"""
Check that invalid 'student_id' raises Http404 for both old mongo and
split mongo courses.
"""
# Create new course with respect to 'default_store'
self.course = CourseFactory.create(default_store=default_store)
# Invalid Student Ids (Integer and Non-int)
invalid_student_ids = [
991021,
'azU3N_8$',
]
for invalid_id in invalid_student_ids:
self.assertRaises(
Http404, views.progress,
self.request,
course_id=unicode(self.course.id),
student_id=invalid_id
)
# Enroll student into course
CourseEnrollment.enroll(self.user, self.course.id, mode='honor')
resp = views.progress(self.request, course_id=self.course.id.to_deprecated_string(), student_id=self.user.id)
# Assert that valid 'student_id' returns 200 status
self.assertEqual(resp.status_code, 200)
示例14: test_check_for_existing_entitlement_and_enroll
def test_check_for_existing_entitlement_and_enroll(self, mock_get_course_uuid):
course = CourseFactory()
CourseModeFactory(
course_id=course.id,
mode_slug=CourseMode.VERIFIED,
# This must be in the future to ensure it is returned by downstream code.
expiration_datetime=now() + timedelta(days=1)
)
entitlement = CourseEntitlementFactory.create(
mode=CourseMode.VERIFIED,
user=self.user,
)
mock_get_course_uuid.return_value = entitlement.course_uuid
assert not CourseEnrollment.is_enrolled(user=self.user, course_key=course.id)
CourseEntitlement.check_for_existing_entitlement_and_enroll(
user=self.user,
course_run_key=course.id,
)
assert CourseEnrollment.is_enrolled(user=self.user, course_key=course.id)
entitlement.refresh_from_db()
assert entitlement.enrollment_course_run
示例15: handle
def handle(self, *args, **options):
csv_path = options['csv_path']
with open(csv_path) as csvfile:
reader = unicodecsv.DictReader(csvfile)
for row in reader:
username = row['username']
email = row['email']
course_key = row['course_id']
try:
user = User.objects.get(Q(username=username) | Q(email=email))
except ObjectDoesNotExist:
user = None
msg = 'User with username {} or email {} does not exist'.format(username, email)
logger.warning(msg)
try:
course_id = CourseKey.from_string(course_key)
except InvalidKeyError:
course_id = None
msg = 'Invalid course id {course_id}, skipping un-enrollement for {username}, {email}'.format(**row)
logger.warning(msg)
if user and course_id:
enrollment = CourseEnrollment.get_enrollment(user, course_id)
if not enrollment:
msg = 'Enrollment for the user {} in course {} does not exist!'.format(username, course_key)
logger.info(msg)
else:
try:
CourseEnrollment.unenroll(user, course_id, skip_refund=True)
except Exception as err:
msg = 'Error un-enrolling User {} from course {}: '.format(username, course_key, err)
logger.error(msg, exc_info=True)