本文整理汇总了Python中student.tests.factories.CourseEnrollmentFactory.delete方法的典型用法代码示例。如果您正苦于以下问题:Python CourseEnrollmentFactory.delete方法的具体用法?Python CourseEnrollmentFactory.delete怎么用?Python CourseEnrollmentFactory.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类student.tests.factories.CourseEnrollmentFactory
的用法示例。
在下文中一共展示了CourseEnrollmentFactory.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UsersEndpointTestCase
# 需要导入模块: from student.tests.factories import CourseEnrollmentFactory [as 别名]
# 或者: from student.tests.factories.CourseEnrollmentFactory import delete [as 别名]
class UsersEndpointTestCase(ModuleStoreTestCase, MockRequestSetupMixin):
def set_post_counts(self, mock_request, threads_count=1, comments_count=1):
"""
sets up a mock response from the comments service for getting post counts for our other_user
"""
self._set_mock_request_data(mock_request, {
"threads_count": threads_count,
"comments_count": comments_count,
})
def setUp(self):
self.course = CourseFactory.create()
seed_permissions_roles(self.course.id)
self.student = UserFactory.create()
self.enrollment = CourseEnrollmentFactory(user=self.student, course_id=self.course.id)
self.other_user = UserFactory.create(username="other")
CourseEnrollmentFactory(user=self.other_user, course_id=self.course.id)
def make_request(self, method='get', course_id=None, **kwargs):
course_id = course_id or self.course.id
request = getattr(RequestFactory(), method)("dummy_url", kwargs)
request.user = self.student
request.view_name = "users"
return views.users(request, course_id=course_id.to_deprecated_string())
@patch('lms.lib.comment_client.utils.requests.request')
def test_finds_exact_match(self, mock_request):
self.set_post_counts(mock_request)
response = self.make_request(username="other")
self.assertEqual(response.status_code, 200)
self.assertEqual(
json.loads(response.content)["users"],
[{"id": self.other_user.id, "username": self.other_user.username}]
)
@patch('lms.lib.comment_client.utils.requests.request')
def test_finds_no_match(self, mock_request):
self.set_post_counts(mock_request)
response = self.make_request(username="othor")
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content)["users"], [])
def test_requires_GET(self):
response = self.make_request(method='post', username="other")
self.assertEqual(response.status_code, 405)
def test_requires_username_param(self):
response = self.make_request()
self.assertEqual(response.status_code, 400)
content = json.loads(response.content)
self.assertIn("errors", content)
self.assertNotIn("users", content)
def test_course_does_not_exist(self):
course_id = SlashSeparatedCourseKey.from_deprecated_string("does/not/exist")
response = self.make_request(course_id=course_id, username="other")
self.assertEqual(response.status_code, 404)
content = json.loads(response.content)
self.assertIn("errors", content)
self.assertNotIn("users", content)
def test_requires_requestor_enrolled_in_course(self):
# unenroll self.student from the course.
self.enrollment.delete()
response = self.make_request(username="other")
self.assertEqual(response.status_code, 404)
content = json.loads(response.content)
self.assertIn("errors", content)
self.assertNotIn("users", content)
@patch('lms.lib.comment_client.utils.requests.request')
def test_requires_matched_user_has_forum_content(self, mock_request):
self.set_post_counts(mock_request, 0, 0)
response = self.make_request(username="other")
self.assertEqual(response.status_code, 200)
self.assertEqual(json.loads(response.content)["users"], [])
示例2: VerifiedUpgradeToolTest
# 需要导入模块: from student.tests.factories import CourseEnrollmentFactory [as 别名]
# 或者: from student.tests.factories.CourseEnrollmentFactory import delete [as 别名]
class VerifiedUpgradeToolTest(SharedModuleStoreTestCase):
@classmethod
def setUpClass(cls):
super(VerifiedUpgradeToolTest, cls).setUpClass()
cls.now = datetime.datetime.now(pytz.UTC)
cls.course = CourseFactory.create(
org='edX',
number='test',
display_name='Test Course',
self_paced=True,
start=cls.now - datetime.timedelta(days=30),
)
cls.course_overview = CourseOverview.get_from_id(cls.course.id)
@override_waffle_flag(CREATE_SCHEDULE_WAFFLE_FLAG, True)
def setUp(self):
super(VerifiedUpgradeToolTest, self).setUp()
self.course_verified_mode = CourseModeFactory(
course_id=self.course.id,
mode_slug=CourseMode.VERIFIED,
expiration_datetime=self.now + datetime.timedelta(days=30),
)
patcher = patch('openedx.core.djangoapps.schedules.signals.get_current_site')
mock_get_current_site = patcher.start()
self.addCleanup(patcher.stop)
mock_get_current_site.return_value = SiteFactory.create()
DynamicUpgradeDeadlineConfiguration.objects.create(enabled=True)
self.enrollment = CourseEnrollmentFactory(
course_id=self.course.id,
mode=CourseMode.AUDIT,
course=self.course_overview,
)
self.request = RequestFactory().request()
self.request.user = self.enrollment.user
crum.set_current_request(self.request)
def test_tool_visible(self):
self.assertTrue(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_no_enrollment_exists(self):
self.enrollment.delete()
request = RequestFactory().request()
request.user = UserFactory()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_using_deadline_from_course_mode(self):
DynamicUpgradeDeadlineConfiguration.objects.create(enabled=False)
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_enrollment_is_inactive(self):
self.enrollment.is_active = False
self.enrollment.save()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_already_verified(self):
self.enrollment.mode = CourseMode.VERIFIED
self.enrollment.save()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_no_verified_track(self):
self.course_verified_mode.delete()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_course_deadline_has_passed(self):
self.course_verified_mode.expiration_datetime = self.now - datetime.timedelta(days=1)
self.course_verified_mode.save()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))
def test_not_visible_when_course_mode_has_no_deadline(self):
self.course_verified_mode.expiration_datetime = None
self.course_verified_mode.save()
self.assertFalse(VerifiedUpgradeTool().is_enabled(self.request, self.course.id))