当前位置: 首页>>代码示例>>Python>>正文


Python ProgramFactory.create_batch方法代码示例

本文整理汇总了Python中openedx.core.djangoapps.catalog.tests.factories.ProgramFactory.create_batch方法的典型用法代码示例。如果您正苦于以下问题:Python ProgramFactory.create_batch方法的具体用法?Python ProgramFactory.create_batch怎么用?Python ProgramFactory.create_batch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openedx.core.djangoapps.catalog.tests.factories.ProgramFactory的用法示例。


在下文中一共展示了ProgramFactory.create_batch方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_completed_programs

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def test_completed_programs(self, mock_completed_course_runs, mock_get_programs):
        """Verify that completed programs are correctly identified."""
        data = ProgramFactory.create_batch(3)
        mock_get_programs.return_value = data

        program_uuids = []
        course_run_keys = []
        for program in data:
            program_uuids.append(program['uuid'])

            for course in program['courses']:
                for course_run in course['course_runs']:
                    course_run_keys.append(course_run['key'])

        # Verify that no programs are complete.
        meter = ProgramProgressMeter(self.site, self.user)
        self.assertEqual(meter.completed_programs, [])

        # Complete all programs.
        self._create_enrollments(*course_run_keys)
        mock_completed_course_runs.return_value = [
            {'course_run_id': course_run_key, 'type': MODES.verified}
            for course_run_key in course_run_keys
        ]

        # Verify that all programs are complete.
        meter = ProgramProgressMeter(self.site, self.user)
        self.assertEqual(meter.completed_programs, program_uuids)
开发者ID:dehamzah,项目名称:edx-platform,代码行数:30,代码来源:test_utils.py

示例2: test_get_many_with_missing

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def test_get_many_with_missing(self, mock_cache, mock_warning, mock_info):
        programs = ProgramFactory.create_batch(3)

        all_programs = {
            PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs
        }

        partial_programs = {
            PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs[:2]
        }

        def fake_get_many(keys):
            if len(keys) == 1:
                return {PROGRAM_CACHE_KEY_TPL.format(uuid=programs[-1]['uuid']): programs[-1]}
            else:
                return partial_programs

        mock_cache.get.return_value = [program['uuid'] for program in programs]
        mock_cache.get_many.side_effect = fake_get_many

        actual_programs = get_programs(self.site)

        # All 3 cached programs should be returned. An info message should be
        # logged about the one that was initially missing, but the code should
        # be able to stitch together all the details.
        self.assertEqual(
            set(program['uuid'] for program in actual_programs),
            set(program['uuid'] for program in all_programs.values())
        )
        self.assertFalse(mock_warning.called)
        mock_info.assert_called_with('Failed to get details for 1 programs. Retrying.')

        for program in actual_programs:
            key = PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid'])
            self.assertEqual(program, all_programs[key])
开发者ID:dehamzah,项目名称:edx-platform,代码行数:37,代码来源:test_utils.py

示例3: setUp

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def setUp(self):
        super(ProgramPageBase, self).setUp()

        self.set_programs_api_configuration(is_enabled=True)

        self.programs = ProgramFactory.create_batch(3)
        self.username = None
开发者ID:mreyk,项目名称:edx-platform,代码行数:9,代码来源:test_programs.py

示例4: setUp

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def setUp(self):
        super(TestCachePrograms, self).setUp()

        httpretty.httpretty.reset()

        self.catalog_integration = self.create_catalog_integration()
        self.site_domain = 'testsite.com'
        self.set_up_site(
            self.site_domain,
            {
                'COURSE_CATALOG_API_URL': self.catalog_integration.get_internal_api_url().rstrip('/')
            }
        )

        self.list_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/programs/'
        self.detail_tpl = self.list_url.rstrip('/') + '/{uuid}/'
        self.pathway_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/pathways/'

        self.programs = ProgramFactory.create_batch(3)
        self.pathways = PathwayFactory.create_batch(3)

        for pathway in self.pathways:
            self.programs += pathway['programs']

        self.uuids = [program['uuid'] for program in self.programs]

        # add some of the previously created programs to some pathways
        self.pathways[0]['programs'].extend([self.programs[0], self.programs[1]])
        self.pathways[1]['programs'].append(self.programs[0])
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:31,代码来源:test_cache_programs.py

示例5: test_get_programs_by_types

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def test_get_programs_by_types(self, mock_get_edx_api_data):
        programs = ProgramFactory.create_batch(2)
        mock_get_edx_api_data.return_value = programs

        data = get_programs(types=self.types)

        self.assert_contract(mock_get_edx_api_data.call_args, types=self.types)
        self.assertEqual(data, programs)
开发者ID:shevious,项目名称:edx-platform,代码行数:10,代码来源:test_utils.py

示例6: setUp

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def setUp(self):
        super(ProgramPageBase, self).setUp()

        self.set_programs_api_configuration(is_enabled=True)

        self.programs = ProgramFactory.create_batch(3)
        self.pathways = PathwayFactory.create_batch(3)
        for pathway in self.pathways:
            self.programs += pathway['programs']

        # add some of the previously created programs to some pathways
        self.pathways[0]['programs'].extend([self.programs[0], self.programs[1]])
        self.pathways[1]['programs'].append(self.programs[0])

        self.username = None
开发者ID:jolyonb,项目名称:edx-platform,代码行数:17,代码来源:test_programs.py

示例7: setUp

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def setUp(self):
        super(TestCachePrograms, self).setUp()

        self.catalog_integration = self.create_catalog_integration()
        self.site_domain = 'testsite.com'
        self.set_up_site(
            self.site_domain,
            {
                'COURSE_CATALOG_API_URL': self.catalog_integration.get_internal_api_url().rstrip('/')
            }
        )

        self.list_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/programs/'
        self.detail_tpl = self.list_url.rstrip('/') + '/{uuid}/'

        self.programs = ProgramFactory.create_batch(3)
        self.uuids = [program['uuid'] for program in self.programs]
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:19,代码来源:test_cache_programs.py

示例8: test_get_programs_with_type

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def test_get_programs_with_type(self, mock_get_program_types, mock_get_programs):
        """Verify get_programs_with_type returns the expected list of programs."""
        programs_with_program_type = []
        programs = ProgramFactory.create_batch(2)
        program_types = []

        for program in programs:
            program_type = ProgramTypeFactory(name=program['type'])
            program_types.append(program_type)

            program_with_type = copy.deepcopy(program)
            program_with_type['type'] = program_type
            programs_with_program_type.append(program_with_type)

        mock_get_programs.return_value = programs
        mock_get_program_types.return_value = program_types

        actual = get_programs_with_type(self.site)
        self.assertEqual(actual, programs_with_program_type)
开发者ID:dehamzah,项目名称:edx-platform,代码行数:21,代码来源:test_utils.py

示例9: test_get_many

# 需要导入模块: from openedx.core.djangoapps.catalog.tests.factories import ProgramFactory [as 别名]
# 或者: from openedx.core.djangoapps.catalog.tests.factories.ProgramFactory import create_batch [as 别名]
    def test_get_many(self, mock_warning, mock_info):
        programs = ProgramFactory.create_batch(3)

        # Cache details for 2 of 3 programs.
        partial_programs = {
            PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs[:2]
        }
        cache.set_many(partial_programs, None)

        # When called before UUIDs are cached, the function should return an
        # empty list and log a warning.
        self.assertEqual(get_programs(self.site), [])
        mock_warning.assert_called_once_with('Failed to get program UUIDs from the cache.')
        mock_warning.reset_mock()

        # Cache UUIDs for all 3 programs.
        cache.set(
            SITE_PROGRAM_UUIDS_CACHE_KEY_TPL.format(domain=self.site.domain),
            [program['uuid'] for program in programs],
            None
        )

        actual_programs = get_programs(self.site)

        # The 2 cached programs should be returned while info and warning
        # messages should be logged for the missing one.
        self.assertEqual(
            set(program['uuid'] for program in actual_programs),
            set(program['uuid'] for program in partial_programs.values())
        )
        mock_info.assert_called_with('Failed to get details for 1 programs. Retrying.')
        mock_warning.assert_called_with(
            'Failed to get details for program {uuid} from the cache.'.format(uuid=programs[2]['uuid'])
        )
        mock_warning.reset_mock()

        # We can't use a set comparison here because these values are dictionaries
        # and aren't hashable. We've already verified that all programs came out
        # of the cache above, so all we need to do here is verify the accuracy of
        # the data itself.
        for program in actual_programs:
            key = PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid'])
            self.assertEqual(program, partial_programs[key])

        # Cache details for all 3 programs.
        all_programs = {
            PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']): program for program in programs
        }
        cache.set_many(all_programs, None)

        actual_programs = get_programs(self.site)

        # All 3 programs should be returned.
        self.assertEqual(
            set(program['uuid'] for program in actual_programs),
            set(program['uuid'] for program in all_programs.values())
        )
        self.assertFalse(mock_warning.called)

        for program in actual_programs:
            key = PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid'])
            self.assertEqual(program, all_programs[key])
开发者ID:dehamzah,项目名称:edx-platform,代码行数:64,代码来源:test_utils.py


注:本文中的openedx.core.djangoapps.catalog.tests.factories.ProgramFactory.create_batch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。