本文整理汇总了Python中student.models.CourseEnrollment.is_enrolled方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollment.is_enrolled方法的具体用法?Python CourseEnrollment.is_enrolled怎么用?Python CourseEnrollment.is_enrolled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.models.CourseEnrollment
的用法示例。
在下文中一共展示了CourseEnrollment.is_enrolled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unenrollment_email_off
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
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", kwargs={"course_id": course.id})
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)
示例2: test_unenrollment_email_off
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
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)
示例3: test_enroll
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
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)
示例4: test_enrollment_by_email
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_enrollment_by_email(self):
user = User.objects.create(username="jack", email="[email protected]")
course_id = SlashSeparatedCourseKey("edX", "Test101", "2013")
CourseEnrollment.enroll_by_email("[email protected]", course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
self.assert_enrollment_event_was_emitted(user, course_id)
# This won't throw an exception, even though the user is not found
self.assertIsNone(CourseEnrollment.enroll_by_email("[email protected]", course_id))
self.assert_no_events_were_emitted()
self.assertRaises(
User.DoesNotExist, CourseEnrollment.enroll_by_email, "[email protected]", course_id, ignore_errors=False
)
self.assert_no_events_were_emitted()
# Now unenroll them by email
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assert_unenrollment_event_was_emitted(user, course_id)
# Harmless second unenroll
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assert_no_events_were_emitted()
# Unenroll on non-existent user shouldn't throw an error
CourseEnrollment.unenroll_by_email("[email protected]", course_id)
self.assert_no_events_were_emitted()
示例5: test_check_for_existing_entitlement_and_enroll
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
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
示例6: test_user_can_unenroll
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_user_can_unenroll(self, mock_get_course_runs):
course_entitlement = CourseEntitlementFactory.create(user=self.user, mode=CourseMode.VERIFIED)
mock_get_course_runs.return_value = self.return_values
url = reverse(
self.ENTITLEMENTS_ENROLLMENT_NAMESPACE,
args=[str(course_entitlement.uuid)]
)
assert course_entitlement.enrollment_course_run is None
data = {
'course_run_id': str(self.course.id)
}
response = self.client.post(
url,
data=json.dumps(data),
content_type='application/json',
)
course_entitlement.refresh_from_db()
assert response.status_code == 201
assert CourseEnrollment.is_enrolled(self.user, self.course.id)
response = self.client.delete(
url,
content_type='application/json',
)
assert response.status_code == 204
course_entitlement.refresh_from_db()
assert not CourseEnrollment.is_enrolled(self.user, self.course.id)
assert course_entitlement.enrollment_course_run is None
示例7: test_enroll
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_enroll(self, course_modes, next_url, enrollment_mode, auto_reg):
# 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", auto_reg=auto_reg)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content, full_url)
# TODO (ECOM-16): If auto-registration is enabled, check that we're
# storing the auto-reg flag in the user's session
if auto_reg:
self.assertIn("auto_register", self.client.session)
self.assertTrue(self.client.session["auto_register"])
# 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)
示例8: test_shib_login_enrollment
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_shib_login_enrollment(self):
"""
A functionality test that a student with an existing shib login
can auto-enroll in a class with GET or POST params. Also tests the direction functionality of
the 'next' GET/POST param
"""
student = UserFactory.create()
extauth = ExternalAuthMap(
external_id="[email protected]",
external_email="",
external_domain="shib:https://idp.stanford.edu/",
external_credentials="",
internal_password="password",
user=student,
)
student.set_password("password")
student.save()
extauth.save()
course = CourseFactory.create(
org="Stanford",
number="123",
display_name="Shib Only",
enrollment_domain="shib:https://idp.stanford.edu/",
user_id=self.test_user_id,
)
# use django test client for sessions and url processing
# no enrollment before trying
self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
self.client.logout()
request_kwargs = {
"path": "/shib-login/",
"data": {
"enrollment_action": "enroll",
"course_id": course.id.to_deprecated_string(),
"next": "/testredirect",
},
"follow": False,
"REMOTE_USER": "[email protected]",
"Shib-Identity-Provider": "https://idp.stanford.edu/",
}
response = self.client.get(**request_kwargs)
# successful login is a redirect to "/"
self.assertEqual(response.status_code, 302)
self.assertEqual(response["location"], "http://testserver/testredirect")
# now there is enrollment
self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
# Clean up and try again with POST (doesn't happen with real production shib, doing this for test coverage)
self.client.logout()
CourseEnrollment.unenroll(student, course.id)
self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
response = self.client.post(**request_kwargs)
# successful login is a redirect to "/"
self.assertEqual(response.status_code, 302)
self.assertEqual(response["location"], "http://testserver/testredirect")
# now there is enrollment
self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
示例9: test_enrollment
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_enrollment(self):
user = User.objects.create_user("joe", "[email protected]", "password")
course_id = "edX/Test101/2013"
course_id_partial = "edX/Test101"
# Test basic enrollment
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assertFalse(CourseEnrollment.is_enrolled_by_partial(user, course_id_partial))
CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
self.assertTrue(CourseEnrollment.is_enrolled_by_partial(user, course_id_partial))
# Enrolling them again should be harmless
CourseEnrollment.enroll(user, course_id)
self.assertTrue(CourseEnrollment.is_enrolled(user, course_id))
self.assertTrue(CourseEnrollment.is_enrolled_by_partial(user, course_id_partial))
# Now unenroll the user
CourseEnrollment.unenroll(user, course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assertFalse(CourseEnrollment.is_enrolled_by_partial(user, course_id_partial))
# Unenrolling them again should also be harmless
CourseEnrollment.unenroll(user, course_id)
self.assertFalse(CourseEnrollment.is_enrolled(user, course_id))
self.assertFalse(CourseEnrollment.is_enrolled_by_partial(user, course_id_partial))
# The enrollment record should still exist, just be inactive
enrollment_record = CourseEnrollment.objects.get(user=user, course_id=course_id)
self.assertFalse(enrollment_record.is_active)
示例10: test_enrollment_limit_by_domain
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_enrollment_limit_by_domain(self):
"""
Tests that the enrollmentDomain setting is properly limiting enrollment to those who have
the proper external auth
"""
# create 2 course, one with limited enrollment one without
shib_course = CourseFactory.create(org='Stanford', number='123', display_name='Shib Only')
shib_course.enrollment_domain = 'shib:https://idp.stanford.edu/'
self.store.update_item(shib_course, '**replace_user**')
open_enroll_course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course')
open_enroll_course.enrollment_domain = ''
self.store.update_item(open_enroll_course, '**replace_user**')
# create 3 kinds of students, external_auth matching shib_course, external_auth not matching, no external auth
shib_student = UserFactory.create()
shib_student.save()
extauth = ExternalAuthMap(external_id='[email protected]',
external_email='',
external_domain='shib:https://idp.stanford.edu/',
external_credentials="",
user=shib_student)
extauth.save()
other_ext_student = UserFactory.create()
other_ext_student.username = "teststudent2"
other_ext_student.email = "[email protected]"
other_ext_student.save()
extauth = ExternalAuthMap(external_id='[email protected]',
external_email='',
external_domain='shib:https://other.edu/',
external_credentials="",
user=other_ext_student)
extauth.save()
int_student = UserFactory.create()
int_student.username = "teststudent3"
int_student.email = "[email protected]"
int_student.save()
# Tests the two case for courses, limited and not
for course in [shib_course, open_enroll_course]:
for student in [shib_student, other_ext_student, int_student]:
request = self.request_factory.post('/change_enrollment')
request.POST.update({'enrollment_action': 'enroll',
'course_id': course.id.to_deprecated_string()})
request.user = student
response = change_enrollment(request)
# If course is not limited or student has correct shib extauth then enrollment should be allowed
if course is open_enroll_course or student is shib_student:
self.assertEqual(response.status_code, 200)
self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
# Clean up
CourseEnrollment.unenroll(student, course.id)
else:
self.assertEqual(response.status_code, 400)
self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
示例11: test_purchase
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_purchase(self):
# This test is for testing the subclassing functionality of OrderItem, but in
# order to do this, we end up testing the specific functionality of
# CertificateItem, which is not quite good unit test form. Sorry.
cart = Order.get_cart_for_user(user=self.user)
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_id))
CertificateItem.add_to_order(cart, self.course_id, self.cost, 'verified')
# course enrollment object should be created but still inactive
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course_id))
cart.purchase()
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_id))
示例12: test_unregister_students
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_unregister_students(self):
users = UserFactory.create_batch(size=20)
self.enroll_students(self.course, *users)
for user in users:
self.assertTrue(CourseEnrollment.is_enrolled(user, self.course.id))
input_file = self.create_input_file(*[user.email for user in users])
self.unregister_student(input_file)
for user in users:
self.assertFalse(CourseEnrollment.is_enrolled(user, self.course.id))
示例13: test_enrollment_new_student_autoenroll_on_email_off
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_enrollment_new_student_autoenroll_on_email_off(self):
"""
Do auto-enroll on, email off test
"""
course = self.course
# Run the Enroll students command
url = reverse("instructor_dashboard_legacy", kwargs={"course_id": course.id.to_deprecated_string()})
response = self.client.post(
url,
{
"action": "Enroll multiple students",
"multiple_students": "[email protected], [email protected]",
"auto_enroll": "on",
},
)
# Check the page output
self.assertContains(response, "<td>[email protected]</td>")
self.assertContains(response, "<td>[email protected]</td>")
self.assertContains(
response, "<td>user does not exist, enrollment allowed, pending with auto enrollment on</td>"
)
# Check the outbox
self.assertEqual(len(mail.outbox), 0)
# Check the enrollmentallowed db entries
cea = CourseEnrollmentAllowed.objects.filter(email="[email protected]", course_id=course.id)
self.assertEqual(1, cea[0].auto_enroll)
cea = CourseEnrollmentAllowed.objects.filter(email="[email protected]", course_id=course.id)
self.assertEqual(1, cea[0].auto_enroll)
# Check there is no enrollment db entry other than for the other students
ce = CourseEnrollment.objects.filter(course_id=course.id, is_active=1)
self.assertEqual(4, len(ce))
# Create and activate student accounts with same email
self.student1 = "[email protected]"
self.password = "bar"
self.create_account("s1_1", self.student1, self.password)
self.activate_user(self.student1)
self.student2 = "[email protected]"
self.create_account("s1_2", self.student2, self.password)
self.activate_user(self.student2)
# Check students are enrolled
user = User.objects.get(email="[email protected]")
self.assertTrue(CourseEnrollment.is_enrolled(user, course.id))
user = User.objects.get(email="[email protected]")
self.assertTrue(CourseEnrollment.is_enrolled(user, course.id))
示例14: login_with_enrollment
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def login_with_enrollment(self):
course = CourseFactory.create()
user = UserFactory.create()
self.assertFalse(CourseEnrollment.is_enrolled(user, course.id))
post_params = {
'email': user.email,
'password': 'test',
'enrollment_action': 'enroll',
'course_id': unicode(course.id)
}
self.client.post(reverse('login'), post_params)
self.assertTrue(CourseEnrollment.is_enrolled(user, course.id))
示例15: test_shib_login_enrollment
# 需要导入模块: from student.models import CourseEnrollment [as 别名]
# 或者: from student.models.CourseEnrollment import is_enrolled [as 别名]
def test_shib_login_enrollment(self):
"""
A functionality test that a student with an existing shib login
can auto-enroll in a class with GET or POST params. Also tests the direction functionality of
the 'next' GET/POST param
"""
student = UserFactory.create()
extauth = ExternalAuthMap(external_id='[email protected]',
external_email='',
external_domain='shib:https://idp.stanford.edu/',
external_credentials="",
internal_password="password",
user=student)
student.set_password("password")
student.save()
extauth.save()
course = CourseFactory.create(
org='Stanford',
number='123',
display_name='Shib Only',
enrollment_domain='shib:https://idp.stanford.edu/',
user_id=self.test_user_id,
)
# use django test client for sessions and url processing
# no enrollment before trying
self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
self.client.logout()
request_kwargs = {'path': '/shib-login/',
'data': {'enrollment_action': 'enroll', 'course_id': course.id.to_deprecated_string(), 'next': '/testredirect'},
'follow': False,
'REMOTE_USER': '[email protected]',
'Shib-Identity-Provider': 'https://idp.stanford.edu/'}
response = self.client.get(**request_kwargs)
# successful login is a redirect to "/"
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], 'http://testserver/testredirect')
# now there is enrollment
self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))
# Clean up and try again with POST (doesn't happen with real production shib, doing this for test coverage)
self.client.logout()
CourseEnrollment.unenroll(student, course.id)
self.assertFalse(CourseEnrollment.is_enrolled(student, course.id))
response = self.client.post(**request_kwargs)
# successful login is a redirect to "/"
self.assertEqual(response.status_code, 302)
self.assertEqual(response['location'], 'http://testserver/testredirect')
# now there is enrollment
self.assertTrue(CourseEnrollment.is_enrolled(student, course.id))