def _make_content_loader_factory(application,
                                 frameworks,
                                 initial_instance=None):
    # for testing purposes we allow an initial_instance to be provided
    primary_cl = initial_instance if initial_instance is not None else ContentLoader(
        'app/content')
    for framework_data in frameworks:
        if not framework_data['slug'] in application.config.get(
                'DM_FRAMEWORK_CONTENT_MAP', {}):
            if framework_data['framework'] == 'g-cloud':
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'services_search_filters')
                # we need to be able to display old services, even on expired frameworks
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'display_service')
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'download_results')
                try_load_metadata(primary_cl, application, framework_data,
                                  ['following_framework'])
            elif framework_data[
                    'framework'] == 'digital-outcomes-and-specialists':
                primary_cl.load_manifest(framework_data['slug'], 'briefs',
                                         'display_brief')
                try_load_manifest(primary_cl, application, framework_data,
                                  'briefs', 'briefs_search_filters')

    # seal primary_cl in a closure by returning a function which will only ever return an independent copy of it.
    # this is of course only guaranteed when the initial_instance argument wasn't used.
    return lambda: deepcopy(primary_cl)
Esempio n. 2
0
    def test_content_loader_asked_to_load_manifest(self):
        try_load_manifest(self.content_loader_mock, self.application_mock,
                          TestTryLoadManifest.FRAMEWORK_DATA,
                          TestTryLoadManifest.QUESTION_SET,
                          TestTryLoadManifest.MANIFEST)

        assert self.content_loader_mock.load_manifest.call_args_list == [
            mock.call(TestTryLoadManifest.FRAMEWORK_DATA['slug'],
                      TestTryLoadManifest.QUESTION_SET,
                      TestTryLoadManifest.MANIFEST)
        ]
        assert self.application_mock.logger.info.called is False
Esempio n. 3
0
    def test_info_log_generated_on_content_not_found(self):
        self.content_loader_mock.load_manifest.side_effect = ContentNotFoundError(
        )

        try_load_manifest(self.content_loader_mock, self.application_mock,
                          TestTryLoadManifest.FRAMEWORK_DATA,
                          TestTryLoadManifest.QUESTION_SET,
                          TestTryLoadManifest.MANIFEST)

        assert self.content_loader_mock.load_manifest.call_args_list == [
            mock.call(TestTryLoadManifest.FRAMEWORK_DATA['slug'],
                      TestTryLoadManifest.QUESTION_SET,
                      TestTryLoadManifest.MANIFEST)
        ]

        assert self.application_mock.logger.info.call_args_list == [
            mock.call('Could not load {}.{} manifest for {}'.format(
                TestTryLoadManifest.QUESTION_SET, TestTryLoadManifest.MANIFEST,
                TestTryLoadManifest.FRAMEWORK_DATA['slug']))
        ]