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


Python tests.ResourceFactory类代码示例

本文整理汇总了Python中pontoon.base.tests.ResourceFactory的典型用法代码示例。如果您正苦于以下问题:Python ResourceFactory类的具体用法?Python ResourceFactory怎么用?Python ResourceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: setUp

 def setUp(self):
     self.locale = LocaleFactory.create(cldr_plurals="0,1")
     self.project = ProjectFactory.create(locales=[self.locale])
     self.main_resource = ResourceFactory.create(project=self.project, path="main.lang")
     self.other_resource = ResourceFactory.create(project=self.project, path="other.lang")
     self.main_entity = EntityFactory.create(
         resource=self.main_resource,
         string="Source String",
         string_plural="Plural Source String",
         key="Source String",
     )
     self.other_entity = EntityFactory.create(
         resource=self.other_resource,
         string="Other Source String",
         key="Key" + KEY_SEPARATOR + "Other Source String",
     )
     self.main_translation = TranslationFactory.create(
         entity=self.main_entity, locale=self.locale, plural_form=0, string="Translated String"
     )
     self.main_translation_plural = TranslationFactory.create(
         entity=self.main_entity, locale=self.locale, plural_form=1, string="Translated Plural String"
     )
     self.other_translation = TranslationFactory.create(
         entity=self.other_entity, locale=self.locale, string="Other Translated String"
     )
     self.subpage = SubpageFactory.create(project=self.project, name="Subpage", resources=[self.main_resource])
开发者ID:dsaumyajit007,项目名称:pontoon,代码行数:26,代码来源:test_models.py

示例2: setUp

    def setUp(self):
        timezone_patch = patch.object(sync_projects, 'timezone')
        self.mock_timezone = timezone_patch.start()
        self.addCleanup(timezone_patch.stop)
        self.mock_timezone.now.return_value = aware_datetime(1970, 1, 1)

        self.translated_locale = LocaleFactory.create(code='translated-locale')
        self.inactive_locale = LocaleFactory.create(code='inactive-locale')
        self.repository = RepositoryFactory()

        self.db_project = ProjectFactory.create(
            name='db-project',
            locales=[self.translated_locale],
            repositories=[self.repository]
        )
        self.main_db_resource = ResourceFactory.create(
            project=self.db_project,
            path='main.lang',
            format='lang'
        )
        self.other_db_resource = ResourceFactory.create(
            project=self.db_project,
            path='other.lang',
            format='lang'
        )
        self.missing_db_resource = ResourceFactory.create(
            project=self.db_project,
            path='missing.lang',
            format='lang'
        )

        # Load paths from the fake locale directory.
        checkout_path_patch = patch.object(
            Project,
            'checkout_path',
            new_callable=PropertyMock,
            return_value=FAKE_CHECKOUT_PATH
        )
        checkout_path_patch.start()
        self.addCleanup(checkout_path_patch.stop)

        self.vcs_project = VCSProject(self.db_project)
        self.main_vcs_resource = self.vcs_project.resources[self.main_db_resource.path]
        self.other_vcs_resource = self.vcs_project.resources[self.other_db_resource.path]
        self.missing_vcs_resource = self.vcs_project.resources[self.missing_db_resource.path]
        self.main_vcs_entity = self.main_vcs_resource.entities['Source String']
        self.main_vcs_translation = self.main_vcs_entity.translations['translated-locale']

        # Mock VCSResource.save() for each resource to avoid altering
        # the filesystem.
        resource_save_patch = patch.object(VCSResource, 'save')
        resource_save_patch.start()
        self.addCleanup(resource_save_patch.stop)

        self.changeset = sync_projects.ChangeSet(
            self.db_project,
            self.vcs_project,
            aware_datetime(1970, 1, 1)
        )
开发者ID:riseofthetigers,项目名称:pontoon,代码行数:59,代码来源:test_sync_projects.py

示例3: setUp

    def setUp(self):
        """
        We don't call project synchronization during the tests, so we have to
        create dummy resource project to avoid recurse redirect at /.
        """
        ResourceFactory.create(project=Project.objects.get(pk=1))

        self.factory = RequestFactory()
开发者ID:MikkCZ,项目名称:pontoon,代码行数:8,代码来源:test_views.py

示例4: test_invalid_locale_valid_project

    def test_invalid_locale_valid_project(self):
        """
        If the project is valid but the locale isn't, redirect home.
        """
        project = ProjectFactory.create(slug='valid-project')
        ResourceFactory.create(project=project)

        response = self.client.get('/invalid-locale/valid-project/path/')
        assert_equal(response.status_code, 404)
开发者ID:MikkCZ,项目名称:pontoon,代码行数:9,代码来源:test_views.py

示例5: test_invalid_locale_valid_project

    def test_invalid_locale_valid_project(self):
        """
        If the project is valid but the locale isn't, redirect home.
        """
        project = ProjectFactory.create(slug='valid-project')
        ResourceFactory.create(project=project)

        response = self.client.get('/invalid-locale/valid-project/')
        assert_redirects(response, reverse('pontoon.home'))
        assert_equal(self.client.session['translate_error'], {'none': None})
开发者ID:Jobava,项目名称:mirror-pontoon,代码行数:10,代码来源:test_views.py

示例6: test_project_view

    def test_project_view(self):
        """
        Checks if project page is returned properly.
        """
        project = ProjectFactory.create()
        ResourceFactory.create(project=project)

        with patch('pontoon.base.views.render', wraps=render) as mock_render:
            self.client.get('/projects/{}/'.format(project.slug))
            assert_equal(mock_render.call_args[0][2]['project'], project)
开发者ID:sudheesh001,项目名称:pontoon,代码行数:10,代码来源:test_views.py

示例7: test_locale_view

    def test_locale_view(self):
        """
        Checks if locale page is returned properly.
        """
        locale = LocaleFactory.create()

        # Locale requires valid project with resources
        ResourceFactory.create(project__locales=[locale])

        with patch('pontoon.base.views.render', wraps=render) as mock_render:
            self.client.get('/{}/'.format(locale.code))
            assert_equal(mock_render.call_args[0][2]['locale'], locale)
开发者ID:sudheesh001,项目名称:pontoon,代码行数:12,代码来源:test_views.py

示例8: test_not_authed_public_project

    def test_not_authed_public_project(self):
        """
        If the user is not authenticated and we're translating project
        ID 1, return a 200.
        """
        # Clear out existing project with ID=1 if necessary.
        Project.objects.filter(id=1).delete()
        locale = LocaleFactory.create(code='fakelocale')
        project = ProjectFactory.create(id=1, slug='valid-project', locales=[locale])
        ResourceFactory.create(project=project)

        response = self.client.get('/fakelocale/valid-project/')
        assert_equal(response.status_code, 200)
开发者ID:Jobava,项目名称:mirror-pontoon,代码行数:13,代码来源:test_views.py

示例9: test_not_authed_nonpublic_project

    def test_not_authed_nonpublic_project(self):
        """
        If the user is not authenticated and we're not translating
        project ID 1, redirect home.
        """
        # Clear out existing project with ID=1 if necessary.
        Project.objects.filter(id=2).delete()
        locale = LocaleFactory.create(code='fakelocale')
        project = ProjectFactory.create(id=2, slug='valid-project', locales=[locale])
        ResourceFactory.create(project=project)

        response = self.client.get('/fakelocale/valid-project/')
        assert_redirects(response, reverse('pontoon.home'))
        assert_equal(self.client.session['translate_error'], {'redirect': '/fakelocale/valid-project/'})
开发者ID:Jobava,项目名称:mirror-pontoon,代码行数:14,代码来源:test_views.py

示例10: setUp

 def setUp(self):
     self.locale = LocaleFactory.create(
         cldr_plurals="0,1"
     )
     self.project = ProjectFactory.create(
         locales=[self.locale]
     )
     self.main_resource = ResourceFactory.create(
         project=self.project,
         path='main.lang'
     )
     self.other_resource = ResourceFactory.create(
         project=self.project,
         path='other.lang'
     )
     self.main_entity = EntityFactory.create(
         resource=self.main_resource,
         string='Source String',
         string_plural='Plural Source String',
         key='Source String'
     )
     self.other_entity = EntityFactory.create(
         resource=self.other_resource,
         string='Other Source String',
         key='Key' + KEY_SEPARATOR + 'Other Source String'
     )
     self.main_translation = TranslationFactory.create(
         entity=self.main_entity,
         locale=self.locale,
         plural_form=0,
         string='Translated String'
     )
     self.main_translation_plural = TranslationFactory.create(
         entity=self.main_entity,
         locale=self.locale,
         plural_form=1,
         string='Translated Plural String'
     )
     self.other_translation = TranslationFactory.create(
         entity=self.other_entity,
         locale=self.locale,
         string='Other Translated String'
     )
     self.subpage = SubpageFactory.create(
         project=self.project,
         name='Subpage',
         resources=[self.main_resource]
     )
开发者ID:waseem18,项目名称:pontoon,代码行数:48,代码来源:test_models.py

示例11: test_locales_parts_stats_pages_tied_to_resources

    def test_locales_parts_stats_pages_tied_to_resources(self):
        """
        Return subpage name and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(
            project=self.project,
            path='/other/path.po'
        )
        EntityFactory.create(resource=resource_other)
        StatsFactory.create(resource=resource_other, locale=self.locale)
        StatsFactory.create(resource=resource_other, locale=self.locale_other)
        SubpageFactory.create(
            project=self.project,
            name='Subpage',
            resources=[self.resource]
        )
        SubpageFactory.create(
            project=self.project,
            name='Other Subpage',
            resources=[resource_other]
        )

        project_details = self._fetch_locales_parts_stats()
        details = project_details.get(self.locale.code)
        details_other = project_details.get(self.locale_other.code)

        assert_equal(details[0]['resource__path'], 'Other Subpage')
        assert_equal(details[0]['translated_count'], 0)
        assert_equal(details[1]['resource__path'], 'Subpage')
        assert_equal(details[1]['translated_count'], 0)
        assert_equal(details_other[0]['resource__path'], 'Other Subpage')
        assert_equal(details_other[0]['translated_count'], 0)
开发者ID:rajul,项目名称:pontoon,代码行数:32,代码来源:test_models.py

示例12: test_parts_stats_pages_tied_to_resources

    def test_parts_stats_pages_tied_to_resources(self):
        """
        Return subpage name and stats for locales resources are available for.
        """
        resource_other = ResourceFactory.create(
            project=self.project,
            path='/other/path.po'
        )
        EntityFactory.create(resource=resource_other)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale)
        TranslatedResourceFactory.create(resource=resource_other, locale=self.locale_other)
        SubpageFactory.create(
            project=self.project,
            name='Subpage',
            resources=[self.resource]
        )
        SubpageFactory.create(
            project=self.project,
            name='Other Subpage',
            resources=[resource_other]
        )

        details = self.locale.parts_stats(self.project)
        details_other = self.locale_other.parts_stats(self.project)

        assert_equal(details[0]['title'], 'Other Subpage')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], 'Subpage')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(details_other[0]['title'], 'Other Subpage')
        assert_equal(details_other[0]['translated_strings'], 0)
开发者ID:transforlab,项目名称:pontoon,代码行数:31,代码来源:test_models.py

示例13: test_save_latest_translation_update

    def test_save_latest_translation_update(self):
        """
        When a translation is saved, update the latest_translation
        attribute on the related project, locale, stats, and
        project_locale objects.
        """
        locale = LocaleFactory.create(latest_translation=None)
        project = ProjectFactory.create(locales=[locale], latest_translation=None)
        resource = ResourceFactory.create(project=project)
        stats = StatsFactory.create(locale=locale, resource=resource, latest_translation=None)
        project_locale = ProjectLocale.objects.get(locale=locale, project=project)

        assert_is_none(locale.latest_translation)
        assert_is_none(project.latest_translation)
        assert_is_none(stats.latest_translation)
        assert_is_none(project_locale.latest_translation)

        translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 1, 1)
        )
        self.assert_latest_translation(locale, translation)
        self.assert_latest_translation(project, translation)
        self.assert_latest_translation(stats, translation)
        self.assert_latest_translation(project_locale, translation)

        # Ensure translation is replaced for newer translations
        newer_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 2, 1)
        )
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(stats, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure translation isn't replaced for older translations.
        TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            date=aware_datetime(1970, 1, 5)
        )
        self.assert_latest_translation(locale, newer_translation)
        self.assert_latest_translation(project, newer_translation)
        self.assert_latest_translation(stats, newer_translation)
        self.assert_latest_translation(project_locale, newer_translation)

        # Ensure approved_date is taken into consideration as well.
        newer_approved_translation = TranslationFactory.create(
            locale=locale,
            entity__resource=resource,
            approved_date=aware_datetime(1970, 3, 1)
        )
        self.assert_latest_translation(locale, newer_approved_translation)
        self.assert_latest_translation(project, newer_approved_translation)
        self.assert_latest_translation(stats, newer_approved_translation)
        self.assert_latest_translation(project_locale, newer_approved_translation)
开发者ID:rajul,项目名称:pontoon,代码行数:59,代码来源:test_models.py

示例14: test_no_subpage_no_stats_in_current_locale

    def test_no_subpage_no_stats_in_current_locale(self):
        """
        If there are stats for a resource available in other locales but
        not in the current one, and no subpages, do not set ctx['part'].
        """
        locale, locale_no_stats = LocaleFactory.create_batch(2)
        project = ProjectFactory.create(locales=[locale, locale_no_stats])

        resource = ResourceFactory.create(project=project, path='foo.lang', entity_count=1)
        ResourceFactory.create(project=project, entity_count=1)
        StatsFactory.create(resource=resource, locale=locale)

        self.client_login()
        url = '/{}/'.format('/'.join([locale_no_stats.code, project.slug, resource.path]))
        with patch('pontoon.base.views.render', wraps=render) as mock_render:
            self.client.get(url)
            assert_true('part' not in mock_render.call_args[0][2])
开发者ID:rajul,项目名称:pontoon,代码行数:17,代码来源:test_views.py

示例15: test_no_subpage_one_stats_in_current_locale

    def test_no_subpage_one_stats_in_current_locale(self):
        """
        If there is just one stats for a resource available in the current
        locale, and no subpages, do not set ctx['part'].
        """
        locale = LocaleFactory.create()
        project = ProjectFactory.create(locales=[locale])

        # Need two resources to trigger setting the part value.
        resource = ResourceFactory.create(project=project, path='foo.lang', entity_count=1)
        ResourceFactory.create(project=project, entity_count=1)
        StatsFactory.create(resource=resource, locale=locale)

        self.client_login()
        url = '/{locale.code}/{project.slug}/'.format(locale=locale, project=project)
        with patch('pontoon.base.views.render', wraps=render) as mock_render:
            self.client.get(url)
            assert_true('part' not in mock_render.call_args[0][2])
开发者ID:riseofthetigers,项目名称:pontoon,代码行数:18,代码来源:test_views.py


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