本文整理汇总了Python中openedx.core.djangoapps.site_configuration.tests.factories.SiteConfigurationFactory.save方法的典型用法代码示例。如果您正苦于以下问题:Python SiteConfigurationFactory.save方法的具体用法?Python SiteConfigurationFactory.save怎么用?Python SiteConfigurationFactory.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openedx.core.djangoapps.site_configuration.tests.factories.SiteConfigurationFactory
的用法示例。
在下文中一共展示了SiteConfigurationFactory.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBinnedSchedulesBaseResolver
# 需要导入模块: from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.tests.factories.SiteConfigurationFactory import save [as 别名]
class TestBinnedSchedulesBaseResolver(CacheIsolationTestCase):
def setUp(self):
super(TestBinnedSchedulesBaseResolver, self).setUp()
self.site = SiteFactory.create()
self.site_config = SiteConfigurationFactory(site=self.site)
self.schedule_config = ScheduleConfigFactory.create(site=self.site)
self.resolver = BinnedSchedulesBaseResolver(
async_send_task=Mock(name='async_send_task'),
site=self.site,
target_datetime=datetime.datetime.now(),
day_offset=3,
bin_num=2,
)
@ddt.data(
'course1'
)
def test_get_course_org_filter_equal(self, course_org_filter):
self.site_config.values['course_org_filter'] = course_org_filter
self.site_config.save()
mock_query = Mock()
result = self.resolver.filter_by_org(mock_query)
self.assertEqual(result, mock_query.filter.return_value)
mock_query.filter.assert_called_once_with(enrollment__course__org=course_org_filter)
@ddt.unpack
@ddt.data(
(['course1', 'course2'], ['course1', 'course2'])
)
def test_get_course_org_filter_include__in(self, course_org_filter, expected_org_list):
self.site_config.values['course_org_filter'] = course_org_filter
self.site_config.save()
mock_query = Mock()
result = self.resolver.filter_by_org(mock_query)
self.assertEqual(result, mock_query.filter.return_value)
mock_query.filter.assert_called_once_with(enrollment__course__org__in=expected_org_list)
@ddt.unpack
@ddt.data(
(None, set([])),
('course1', set([u'course1'])),
(['course1', 'course2'], set([u'course1', u'course2']))
)
def test_get_course_org_filter_exclude__in(self, course_org_filter, expected_org_list):
SiteConfigurationFactory.create(
values={'course_org_filter': course_org_filter},
)
mock_query = Mock()
result = self.resolver.filter_by_org(mock_query)
mock_query.exclude.assert_called_once_with(enrollment__course__org__in=expected_org_list)
self.assertEqual(result, mock_query.exclude.return_value)
示例2: AwardProgramCertificatesTestCase
# 需要导入模块: from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory [as 别名]
# 或者: from openedx.core.djangoapps.site_configuration.tests.factories.SiteConfigurationFactory import save [as 别名]
class AwardProgramCertificatesTestCase(CatalogIntegrationMixin, CredentialsApiConfigMixin, TestCase):
"""
Tests for the 'award_program_certificates' celery task.
"""
def setUp(self):
super(AwardProgramCertificatesTestCase, self).setUp()
self.create_credentials_config()
self.student = UserFactory.create(username='test-student')
self.site = SiteFactory()
self.site_configuration = SiteConfigurationFactory(site=self.site)
self.catalog_integration = self.create_catalog_integration()
ClientFactory.create(name='credentials')
UserFactory.create(username=settings.CREDENTIALS_SERVICE_USERNAME)
def test_completion_check(
self,
mock_get_completed_programs,
mock_get_certified_programs, # pylint: disable=unused-argument
mock_award_program_certificate, # pylint: disable=unused-argument
):
"""
Checks that the Programs API is used correctly to determine completed
programs.
"""
tasks.award_program_certificates.delay(self.student.username).get()
mock_get_completed_programs.assert_called(self.site, self.student)
@ddt.data(
([1], [2, 3]),
([], [1, 2, 3]),
([1, 2, 3], []),
)
@ddt.unpack
def test_awarding_certs(
self,
already_awarded_program_uuids,
expected_awarded_program_uuids,
mock_get_completed_programs,
mock_get_certified_programs,
mock_award_program_certificate,
):
"""
Checks that the Credentials API is used to award certificates for
the proper programs.
"""
mock_get_completed_programs.return_value = {1: 1, 2: 2, 3: 3}
mock_get_certified_programs.return_value = already_awarded_program_uuids
tasks.award_program_certificates.delay(self.student.username).get()
actual_program_uuids = [call[0][2] for call in mock_award_program_certificate.call_args_list]
self.assertEqual(actual_program_uuids, expected_awarded_program_uuids)
actual_visible_dates = [call[0][3] for call in mock_award_program_certificate.call_args_list]
self.assertEqual(actual_visible_dates, expected_awarded_program_uuids) # program uuids are same as mock dates
@mock.patch('openedx.core.djangoapps.site_configuration.helpers.get_current_site_configuration')
def test_awarding_certs_with_skip_program_certificate(
self,
mocked_get_current_site_configuration,
mock_get_completed_programs,
mock_get_certified_programs,
mock_award_program_certificate,
):
"""
Checks that the Credentials API is used to award certificates for
the proper programs and those program will be skipped which are provided
by 'programs_without_certificates' list in site configuration.
"""
# all completed programs
mock_get_completed_programs.return_value = {1: 1, 2: 2, 3: 3, 4: 4}
# already awarded programs
mock_get_certified_programs.return_value = [1]
# programs to be skipped
self.site_configuration.values = {
"programs_without_certificates": [2]
}
self.site_configuration.save()
mocked_get_current_site_configuration.return_value = self.site_configuration
# programs which are expected to be awarded.
# (completed_programs - (already_awarded+programs + to_be_skipped_programs)
expected_awarded_program_uuids = [3, 4]
tasks.award_program_certificates.delay(self.student.username).get()
actual_program_uuids = [call[0][2] for call in mock_award_program_certificate.call_args_list]
self.assertEqual(actual_program_uuids, expected_awarded_program_uuids)
actual_visible_dates = [call[0][3] for call in mock_award_program_certificate.call_args_list]
self.assertEqual(actual_visible_dates, expected_awarded_program_uuids) # program uuids are same as mock dates
@ddt.data(
('credentials', 'enable_learner_issuance'),
)
@ddt.unpack
def test_retry_if_config_disabled(
self,
disabled_config_type,
#.........这里部分代码省略.........