本文整理汇总了Python中openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python CourseOverviewFactory.create方法的具体用法?Python CourseOverviewFactory.create怎么用?Python CourseOverviewFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory
的用法示例。
在下文中一共展示了CourseOverviewFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_config_overrides
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_config_overrides(self, global_setting, site_setting, org_setting, course_setting, reverse_order):
"""
Test that the stacked configuration overrides happen in the correct order and priority.
This is tested by exhaustively setting each combination of contexts, and validating that only
the lowest level context that is set to not-None is applied.
"""
# Add a bunch of configuration outside the contexts that are being tested, to make sure
# there are no leaks of configuration across contexts
non_test_course_enabled = CourseOverviewFactory.create(org='non-test-org-enabled')
non_test_course_disabled = CourseOverviewFactory.create(org='non-test-org-disabled')
non_test_site_cfg_enabled = SiteConfigurationFactory.create(
values={'course_org_filter': non_test_course_enabled.org}
)
non_test_site_cfg_disabled = SiteConfigurationFactory.create(
values={'course_org_filter': non_test_course_disabled.org}
)
CourseDurationLimitConfig.objects.create(course=non_test_course_enabled, enabled=True)
CourseDurationLimitConfig.objects.create(course=non_test_course_disabled, enabled=False)
CourseDurationLimitConfig.objects.create(org=non_test_course_enabled.org, enabled=True)
CourseDurationLimitConfig.objects.create(org=non_test_course_disabled.org, enabled=False)
CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_enabled.site, enabled=True)
CourseDurationLimitConfig.objects.create(site=non_test_site_cfg_disabled.site, enabled=False)
# Set up test objects
test_course = CourseOverviewFactory.create(org='test-org')
test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': test_course.org})
if reverse_order:
CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)
CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
CourseDurationLimitConfig.objects.create(enabled=global_setting)
else:
CourseDurationLimitConfig.objects.create(enabled=global_setting)
CourseDurationLimitConfig.objects.create(course=test_course, enabled=course_setting)
CourseDurationLimitConfig.objects.create(org=test_course.org, enabled=org_setting)
CourseDurationLimitConfig.objects.create(site=test_site_cfg.site, enabled=site_setting)
expected_global_setting = self._resolve_settings([global_setting])
expected_site_setting = self._resolve_settings([global_setting, site_setting])
expected_org_setting = self._resolve_settings([global_setting, site_setting, org_setting])
expected_course_setting = self._resolve_settings([global_setting, site_setting, org_setting, course_setting])
self.assertEqual(expected_global_setting, CourseDurationLimitConfig.current().enabled)
self.assertEqual(expected_site_setting, CourseDurationLimitConfig.current(site=test_site_cfg.site).enabled)
self.assertEqual(expected_org_setting, CourseDurationLimitConfig.current(org=test_course.org).enabled)
self.assertEqual(expected_course_setting, CourseDurationLimitConfig.current(course_key=test_course.id).enabled)
示例2: test_unpublished_sessions_for_entitlement_when_enrolled
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_unpublished_sessions_for_entitlement_when_enrolled(self, mock_get_edx_api_data):
"""
Test unpublished course runs are part of visible session entitlements when the user
is enrolled.
"""
catalog_course_run = CourseRunFactory.create(status=COURSE_UNPUBLISHED)
catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(
mode_slug=CourseMode.VERIFIED,
min_price=100,
course_id=course_overview.id,
expiration_datetime=now() - timedelta(days=1)
)
course_enrollment = CourseEnrollmentFactory(
user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED
)
entitlement = CourseEntitlementFactory(
user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED
)
session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, [catalog_course_run])
示例3: setUpClass
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUpClass(cls):
super(TaskTestCase, cls).setUpClass()
cls.discussion_id = 'dummy_discussion_id'
cls.course = CourseOverviewFactory.create(language='fr')
# Patch the comment client user save method so it does not try
# to create a new cc user when creating a django user
with mock.patch('student.models.cc.User.save'):
cls.thread_author = UserFactory(
username='thread_author',
password='password',
email='email'
)
cls.comment_author = UserFactory(
username='comment_author',
password='password',
email='email'
)
CourseEnrollmentFactory(
user=cls.thread_author,
course_id=cls.course.id
)
CourseEnrollmentFactory(
user=cls.comment_author,
course_id=cls.course.id
)
config = ForumsConfig.current()
config.enabled = True
config.save()
cls.create_thread_and_comments()
示例4: test_caching_org
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_caching_org(self):
course = CourseOverviewFactory.create(org='test-org')
site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': course.org})
org_config = ContentTypeGatingConfig(org=course.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
org_config.save()
# Check that the org value is not retrieved from cache after save
with self.assertNumQueries(2):
self.assertTrue(ContentTypeGatingConfig.current(org=course.org).enabled)
# Check that the org value can be retrieved from cache after read
with self.assertNumQueries(0):
self.assertTrue(ContentTypeGatingConfig.current(org=course.org).enabled)
org_config.enabled = False
org_config.save()
# Check that the org value in cache was deleted on save
with self.assertNumQueries(2):
self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)
global_config = ContentTypeGatingConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
global_config.save()
# Check that the org value is not updated in cache by changing the global value
with self.assertNumQueries(0):
self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)
site_config = ContentTypeGatingConfig(site=site_cfg.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
site_config.save()
# Check that the org value is not updated in cache by changing the site value
with self.assertNumQueries(0):
self.assertFalse(ContentTypeGatingConfig.current(org=course.org).enabled)
示例5: setUp
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUp(self):
super(TestModels, self).setUp()
self.course = CourseOverviewFactory.create(
start=now()
)
self.enrollment = CourseEnrollmentFactory.create(course_id=self.course.id)
self.user = UserFactory()
self.client.login(username=self.user.username, password=TEST_PASSWORD)
示例6: test_all_current_course_configs
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_all_current_course_configs(self):
# Set up test objects
for global_setting in (True, False, None):
CourseDurationLimitConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1))
for site_setting in (True, False, None):
test_site_cfg = SiteConfigurationFactory.create(values={'course_org_filter': []})
CourseDurationLimitConfig.objects.create(
site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)
)
for org_setting in (True, False, None):
test_org = "{}-{}".format(test_site_cfg.id, org_setting)
test_site_cfg.values['course_org_filter'].append(test_org)
test_site_cfg.save()
CourseDurationLimitConfig.objects.create(
org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)
)
for course_setting in (True, False, None):
test_course = CourseOverviewFactory.create(
org=test_org,
id=CourseLocator(test_org, 'test_course', 'run-{}'.format(course_setting))
)
CourseDurationLimitConfig.objects.create(
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)
)
with self.assertNumQueries(4):
all_configs = CourseDurationLimitConfig.all_current_course_configs()
# Deliberatly using the last all_configs that was checked after the 3rd pass through the global_settings loop
# We should be creating 3^4 courses (3 global values * 3 site values * 3 org values * 3 course values)
# Plus 1 for the edX/toy/2012_Fall course
self.assertEqual(len(all_configs), 3**4 + 1)
# Point-test some of the final configurations
self.assertEqual(
all_configs[CourseLocator('7-True', 'test_course', 'run-None')],
{
'enabled': (True, Provenance.org),
'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
}
)
self.assertEqual(
all_configs[CourseLocator('7-True', 'test_course', 'run-False')],
{
'enabled': (False, Provenance.run),
'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
}
)
self.assertEqual(
all_configs[CourseLocator('7-None', 'test_course', 'run-None')],
{
'enabled': (True, Provenance.site),
'enabled_as_of': (datetime(2018, 1, 1, 5, tzinfo=pytz.UTC), Provenance.run),
}
)
示例7: test_unfulfilled_entitlement
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_unfulfilled_entitlement(self, mock_course_overview, mock_pseudo_session,
mock_course_runs, mock_get_programs):
"""
When a learner has an unfulfilled entitlement, their course dashboard should have:
- a hidden 'View Course' button
- the text 'In order to view the course you must select a session:'
- an unhidden course-entitlement-selection-container
- a related programs message
"""
program = ProgramFactory()
CourseEntitlementFactory.create(user=self.user, course_uuid=program['courses'][0]['uuid'])
mock_get_programs.return_value = [program]
course_key = CourseKey.from_string('course-v1:FAKE+FA1-MA1.X+3T2017')
mock_course_overview.return_value = CourseOverviewFactory.create(start=self.TOMORROW, id=course_key)
mock_course_runs.return_value = [
{
'key': six.text_type(course_key),
'enrollment_end': str(self.TOMORROW),
'pacing_type': 'instructor_paced',
'type': 'verified',
'status': 'published'
}
]
mock_pseudo_session.return_value = {
'key': six.text_type(course_key),
'type': 'verified'
}
response = self.client.get(self.path)
self.assertIn('class="course-target-link enter-course hidden"', response.content)
self.assertIn('You must select a session to access the course.', response.content)
self.assertIn('<div class="course-entitlement-selection-container ">', response.content)
self.assertIn('Related Programs:', response.content)
# If an entitlement has already been redeemed by the user for a course run, do not let the run be selectable
enrollment = CourseEnrollmentFactory(
user=self.user, course_id=six.text_type(mock_course_overview.return_value.id), mode=CourseMode.VERIFIED
)
CourseEntitlementFactory.create(
user=self.user, course_uuid=program['courses'][0]['uuid'], enrollment_course_run=enrollment
)
mock_course_runs.return_value = [
{
'key': 'course-v1:edX+toy+2012_Fall',
'enrollment_end': str(self.TOMORROW),
'pacing_type': 'instructor_paced',
'type': 'verified',
'status': 'published'
}
]
response = self.client.get(self.path)
# There should be two entitlements on the course page, one prompting for a mandatory session, but no
# select option for the courses as there is only the single course run which has already been redeemed
self.assertEqual(response.content.count('<li class="course-item">'), 2)
self.assertIn('You must select a session to access the course.', response.content)
self.assertNotIn('To access the course, select a session.', response.content)
示例8: setUp
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUp(self):
self.student = UserFactory.create(username='test-student')
self.course = CourseOverviewFactory.create(
self_paced=True # Any option to allow the certificate to be viewable for the course
)
self.certificate = GeneratedCertificateFactory(
user=self.student,
mode='verified',
course_id=self.course.id,
status='downloadable'
)
示例9: setUpClass
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUpClass(cls):
super(ListViewTestMixin, cls).setUpClass()
cls.program_uuid = '00000000-1111-2222-3333-444444444444'
cls.curriculum_uuid = 'aaaaaaaa-1111-2222-3333-444444444444'
cls.other_curriculum_uuid = 'bbbbbbbb-1111-2222-3333-444444444444'
cls.course_id = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
_ = CourseOverviewFactory.create(id=cls.course_id)
cls.password = 'password'
cls.student = UserFactory.create(username='student', password=cls.password)
cls.global_staff = GlobalStaffFactory.create(username='global-staff', password=cls.password)
示例10: setUpClass
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUpClass(cls):
super(CertificatesListRestApiTest, cls).setUpClass()
cls.course = CourseFactory.create(
org='edx',
number='verified',
display_name='Verified Course',
self_paced=True,
)
cls.course_overview = CourseOverviewFactory.create(
id=cls.course.id,
display_org_with_default='edx',
display_name='Verified Course',
cert_html_view_enabled=True,
self_paced=True,
)
示例11: setUpClass
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUpClass(cls):
cls.course_key = CourseKey.from_string('course-v1:edX+DemoX+Demo_Course')
cls.course = CourseOverviewFactory.create(id=cls.course_key)
cls.audit_mode = CourseModeFactory.create(
course_id=cls.course_key,
mode_slug='audit',
mode_display_name='Audit',
min_price=0,
)
cls.verified_mode = CourseModeFactory.create(
course_id=cls.course_key,
mode_slug='verified',
mode_display_name='Verified',
min_price=25,
)
# use these to make sure we don't fetch data for other courses
cls.other_course_key = CourseKey.from_string('course-v1:edX+DemoX+Other_Course')
cls.other_course = CourseOverviewFactory.create(id=cls.other_course_key)
cls.other_mode = CourseModeFactory.create(
course_id=cls.other_course_key,
mode_slug='other-audit',
mode_display_name='Other Audit',
min_price=0,
)
示例12: setUp
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUp(self):
super(CertificatesApiTestCase, self).setUp()
self.course = CourseOverviewFactory.create(
start=datetime(2017, 1, 1, tzinfo=pytz.UTC),
end=datetime(2017, 1, 31, tzinfo=pytz.UTC),
certificate_available_date=None
)
self.user = UserFactory.create()
self.enrollment = CourseEnrollmentFactory(
user=self.user,
course_id=self.course.id,
is_active=True,
mode='audit',
)
self.certificate = MockGeneratedCertificate(
user=self.user,
course_id=self.course.id
)
示例13: test_get_visible_sessions_for_entitlement
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def test_get_visible_sessions_for_entitlement(self, mock_get_edx_api_data):
"""
Test retrieval of visible session entitlements.
"""
catalog_course_run = CourseRunFactory.create()
catalog_course = CourseFactory(course_runs=[catalog_course_run])
mock_get_edx_api_data.return_value = catalog_course
course_key = CourseKey.from_string(catalog_course_run.get('key'))
course_overview = CourseOverviewFactory.create(id=course_key, start=self.tomorrow)
CourseModeFactory.create(mode_slug=CourseMode.VERIFIED, min_price=100, course_id=course_overview.id)
course_enrollment = CourseEnrollmentFactory(
user=self.user, course_id=unicode(course_overview.id), mode=CourseMode.VERIFIED
)
entitlement = CourseEntitlementFactory(
user=self.user, enrollment_course_run=course_enrollment, mode=CourseMode.VERIFIED
)
session_entitlements = get_visible_sessions_for_entitlement(entitlement)
self.assertEqual(session_entitlements, [catalog_course_run])
示例14: _create_test_course_with_default_grading_policy
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def _create_test_course_with_default_grading_policy(cls, display_name, run):
"""
Utility method to create a course with a default grading policy
"""
course = CourseFactory.create(display_name=display_name, run=run)
_ = CourseOverviewFactory.create(id=course.id)
chapter = ItemFactory.create(
category='chapter',
parent_location=course.location,
display_name="Chapter 1",
)
# create a problem for each type and minimum count needed by the grading policy
# A section is not considered if the student answers less than "min_count" problems
for grading_type, min_count in (("Homework", 12), ("Lab", 12), ("Midterm Exam", 1), ("Final Exam", 1)):
for num in xrange(min_count):
section = ItemFactory.create(
category='sequential',
parent_location=chapter.location,
due=datetime(2017, 12, 18, 11, 30, 00),
display_name=u'Sequential {} {}'.format(grading_type, num),
format=grading_type,
graded=True,
)
vertical = ItemFactory.create(
category='vertical',
parent_location=section.location,
display_name=u'Vertical {} {}'.format(grading_type, num),
)
ItemFactory.create(
category='problem',
parent_location=vertical.location,
display_name=u'Problem {} {}'.format(grading_type, num),
)
return course
示例15: setUp
# 需要导入模块: from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory [as 别名]
# 或者: from openedx.core.djangoapps.content.course_overviews.tests.factories.CourseOverviewFactory import create [as 别名]
def setUp(self):
self.course_overview = CourseOverviewFactory.create()
self.user = UserFactory.create()
super(TestCourseDurationLimitConfig, self).setUp()