本文整理汇总了Python中student.tests.factories.CourseModeFactory类的典型用法代码示例。如果您正苦于以下问题:Python CourseModeFactory类的具体用法?Python CourseModeFactory怎么用?Python CourseModeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CourseModeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enroll
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)
示例2: test_deactivate_enrollment
def test_deactivate_enrollment(self):
"""With the right API key, deactivate (i.e., unenroll from) an existing enrollment."""
# Create an honor and verified mode for a course. This allows an update.
for mode in [CourseMode.HONOR, CourseMode.VERIFIED]:
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=mode,
mode_display_name=mode,
)
# Create a 'verified' enrollment
self.assert_enrollment_status(as_server=True, mode=CourseMode.VERIFIED)
# Check that the enrollment is 'verified' and active.
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, CourseMode.VERIFIED)
# Verify that a non-Boolean enrollment status is treated as invalid.
self.assert_enrollment_status(
as_server=True,
mode=None,
is_active='foo',
expected_status=status.HTTP_400_BAD_REQUEST
)
# Verify that the enrollment has been deactivated, and that the mode is unchanged.
self.assert_enrollment_activation(False)
# Verify that enrollment deactivation is idempotent.
self.assert_enrollment_activation(False)
示例3: test_auto_enroll_step
def test_auto_enroll_step(self, course_modes, enrollment_mode, email_opt_in, email_opt_in_result):
# Create the course modes for the test case
for mode_slug in course_modes:
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=mode_slug,
mode_display_name=mode_slug.capitalize()
)
# Simulate the pipeline step, passing in a course ID
# to indicate that the user was trying to enroll
# when they started the auth process.
strategy = self._fake_strategy()
strategy.session_set('enroll_course_id', unicode(self.course.id))
strategy.session_set('email_opt_in', email_opt_in)
result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=assignment-from-no-return,redundant-keyword-arg
self.assertEqual(result, {})
# Check that the user was or was not enrolled
# (this will vary based on the course mode)
if enrollment_mode is not None:
actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
self.assertTrue(is_active)
self.assertEqual(actual_mode, enrollment_mode)
else:
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
# Check that the Email Opt In option was set
tag = UserOrgTag.objects.get(user=self.user)
self.assertIsNotNone(tag)
self.assertEquals(tag.value, email_opt_in_result)
示例4: test_user_does_not_match_param
def test_user_does_not_match_param(self):
"""
The view should return status 404 if the enrollment username does not match the username of the user
making the request, unless the request is made by a superuser or with a server API key.
"""
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=CourseMode.HONOR,
mode_display_name=CourseMode.HONOR,
)
url = reverse('courseenrollment',
kwargs={'username': self.other_user.username, "course_id": unicode(self.course.id)})
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
# Verify that the server still has access to this endpoint.
self.client.logout()
response = self.client.get(url, **{'HTTP_X_EDX_API_KEY': self.API_KEY})
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Verify superusers have access to this endpoint
superuser = UserFactory.create(password=self.PASSWORD, is_superuser=True)
self.client.login(username=superuser.username, password=self.PASSWORD)
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
示例5: test_get_course_details
def test_get_course_details(self):
CourseModeFactory.create(course_id=self.course.id, mode_slug="honor", mode_display_name="Honor")
resp = self.client.get(reverse("courseenrollmentdetails", kwargs={"course_id": unicode(self.course.id)}))
self.assertEqual(resp.status_code, status.HTTP_200_OK)
data = json.loads(resp.content)
self.assertEqual(unicode(self.course.id), data["course_id"])
示例6: test_auto_enroll_step
def test_auto_enroll_step(self, course_modes, enrollment_mode):
# Create the course modes for the test case
for mode_slug in course_modes:
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=mode_slug,
mode_display_name=mode_slug.capitalize()
)
# Simulate the pipeline step, passing in a course ID
# to indicate that the user was trying to enroll
# when they started the auth process.
strategy = self._fake_strategy()
strategy.session_set('enroll_course_id', unicode(self.course.id))
result = pipeline.change_enrollment(strategy, 1, user=self.user) # pylint: disable=E1111,E1124
self.assertEqual(result, {})
# Check that the user was or was not enrolled
# (this will vary based on the course mode)
if enrollment_mode is not None:
actual_mode, is_active = CourseEnrollment.enrollment_mode_for_user(self.user, self.course.id)
self.assertTrue(is_active)
self.assertEqual(actual_mode, enrollment_mode)
else:
self.assertFalse(CourseEnrollment.is_enrolled(self.user, self.course.id))
示例7: 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)
示例8: 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))
示例9: test_third_party_auth_course_id_shopping_cart
def test_third_party_auth_course_id_shopping_cart(self):
# Create a course with a white-label course mode
course = CourseFactory.create()
CourseModeFactory.create(course_id=course.id, mode_slug="honor", mode_display_name="Honor", min_price=100)
# Verify that the entry URL for third party auth
# contains the course ID and redirects to the shopping cart
shoppingcart_url = reverse("shoppingcart.views.show_cart")
expected_providers = [
{
"name": "Facebook",
"iconClass": "fa-facebook",
"loginUrl": self._third_party_login_url(
"facebook", "login", course_id=unicode(course.id), redirect_url=shoppingcart_url
),
"registerUrl": self._third_party_login_url(
"facebook", "register", course_id=unicode(course.id), redirect_url=shoppingcart_url
),
},
{
"name": "Google",
"iconClass": "fa-google-plus",
"loginUrl": self._third_party_login_url(
"google-oauth2", "login", course_id=unicode(course.id), redirect_url=shoppingcart_url
),
"registerUrl": self._third_party_login_url(
"google-oauth2", "register", course_id=unicode(course.id), redirect_url=shoppingcart_url
),
},
]
# Verify that the login page contains the correct provider URLs
response = self.client.get(reverse("account_login"), {"course_id": unicode(course.id)})
self._assert_third_party_auth_data(response, None, expected_providers)
示例10: test_enrollment_includes_expired_verified
def test_enrollment_includes_expired_verified(self):
"""With the right API key, request that expired course verifications are still returned. """
# Create a honor mode for a course.
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=CourseMode.HONOR,
mode_display_name=CourseMode.HONOR,
)
# Create a verified mode for a course.
CourseModeFactory.create(
course_id=self.course.id,
mode_slug=CourseMode.VERIFIED,
mode_display_name=CourseMode.VERIFIED,
expiration_datetime='1970-01-01 05:00:00'
)
# Passes the include_expired parameter to the API call
v_response = self.client.get(
reverse('courseenrollmentdetails', kwargs={"course_id": unicode(self.course.id)}), {'include_expired': True}
)
v_data = json.loads(v_response.content)
# Ensure that both course modes are returned
self.assertEqual(len(v_data['course_modes']), 2)
# Omits the include_expired parameter from the API call
h_response = self.client.get(reverse('courseenrollmentdetails', kwargs={"course_id": unicode(self.course.id)}))
h_data = json.loads(h_response.content)
# Ensure that only one course mode is returned and that it is honor
self.assertEqual(len(h_data['course_modes']), 1)
self.assertEqual(h_data['course_modes'][0]['slug'], CourseMode.HONOR)
示例11: test_third_party_auth_course_id_verified
def test_third_party_auth_course_id_verified(self, modes):
# Create a course with the specified course modes
course = CourseFactory.create()
for slug in modes:
CourseModeFactory.create(course_id=course.id, mode_slug=slug, mode_display_name=slug)
# Verify that the entry URL for third party auth
# contains the course ID and redirects to the track selection page.
course_modes_choose_url = reverse("course_modes_choose", kwargs={"course_id": unicode(course.id)})
expected_providers = [
{
"name": "Facebook",
"iconClass": "fa-facebook",
"loginUrl": self._third_party_login_url(
"facebook", "login", course_id=unicode(course.id), redirect_url=course_modes_choose_url
),
"registerUrl": self._third_party_login_url(
"facebook", "register", course_id=unicode(course.id), redirect_url=course_modes_choose_url
),
},
{
"name": "Google",
"iconClass": "fa-google-plus",
"loginUrl": self._third_party_login_url(
"google-oauth2", "login", course_id=unicode(course.id), redirect_url=course_modes_choose_url
),
"registerUrl": self._third_party_login_url(
"google-oauth2", "register", course_id=unicode(course.id), redirect_url=course_modes_choose_url
),
},
]
# Verify that the login page contains the correct provider URLs
response = self.client.get(reverse("account_login"), {"course_id": unicode(course.id)})
self._assert_third_party_auth_data(response, None, expected_providers)
示例12: setUp
def setUp(self):
super(ChangeEnrollmentTests, self).setUp()
self.course = CourseFactory.create()
self.audit_mode = CourseModeFactory.create(
course_id=self.course.id,
mode_slug='audit',
mode_display_name='Audit',
)
self.honor_mode = CourseModeFactory.create(
course_id=self.course.id,
mode_slug='honor',
mode_display_name='Honor',
)
self.user_info = [
('amy', '[email protected]', 'password'),
('rory', '[email protected]', 'password'),
('river', '[email protected]', 'password')
]
self.enrollments = []
self.users = []
for username, email, password in self.user_info:
user = UserFactory.create(username=username, email=email, password=password)
self.users.append(user)
self.enrollments.append(CourseEnrollment.enroll(user, self.course.id, mode='audit'))
示例13: setUp
def setUp(self):
super(DashboardTestsWithSiteOverrides, self).setUp()
self.org = "fakeX"
self.course = CourseFactory.create(org=self.org)
self.user = UserFactory.create(username="jack", email="[email protected]", password="test")
CourseModeFactory.create(mode_slug="no-id-professional", course_id=self.course.id)
CourseEnrollment.enroll(self.user, self.course.location.course_key, mode="no-id-professional")
cache.clear()
示例14: setUp
def setUp(self):
super(AnonymousLookupTable, self).setUp()
self.course = CourseFactory.create()
self.user = UserFactory()
CourseModeFactory.create(course_id=self.course.id, mode_slug="honor", mode_display_name="Honor Code")
patcher = patch("student.models.tracker")
patcher.start()
self.addCleanup(patcher.stop)
示例15: test_user_does_not_match_param_for_list
def test_user_does_not_match_param_for_list(self):
CourseModeFactory.create(
course_id=self.course.id,
mode_slug='honor',
mode_display_name='Honor',
)
resp = self.client.get(reverse('courseenrollments'), {"user": "not_the_user"})
self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)