Beispiel #1
0
 def create_db_entities_translations(self):
     """
     Create entities and translations in the database for strings
     from the fake checkout.
     """
     self.main_db_entity = EntityFactory.create(
         resource=self.main_db_resource,
         string='Source String',
         key='Source String',
         obsolete=False
     )
     self.other_db_entity = EntityFactory.create(
         resource=self.other_db_resource,
         string='Other Source String',
         key='Other Source String',
         obsolete=False
     )
     self.main_db_translation = TranslationFactory.create(
         entity=self.main_db_entity,
         plural_form=None,
         locale=self.translated_locale,
         string='Translated String',
         date=aware_datetime(1970, 1, 1),
         approved=True,
         extra={'tags': []}
     )
Beispiel #2
0
    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)
Beispiel #3
0
    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)
Beispiel #4
0
 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])
Beispiel #5
0
 def setUp(self):
     self.locale, self.locale_other = LocaleFactory.create_batch(2)
     self.project = ProjectFactory.create(
         locales=[self.locale, self.locale_other])
     self.resource = ResourceFactory.create(project=self.project,
                                            path='/main/path.po')
     EntityFactory.create(resource=self.resource)
     StatsFactory.create(resource=self.resource, locale=self.locale)
Beispiel #6
0
    def test_for_project_locale_order(self):
        """
        Return entities in correct order.
        """
        entity_second = EntityFactory.create(order=1, resource=self.main_resource, string="Second String")
        entity_first = EntityFactory.create(order=0, resource=self.main_resource, string="First String")
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[2]["original"], "First String")
        assert_equal(entities[3]["original"], "Second String")
Beispiel #7
0
 def setUp(self):
     self.locale, self.locale_other = LocaleFactory.create_batch(2)
     self.project = ProjectFactory.create(
         locales=[self.locale, self.locale_other]
     )
     self.resource = ResourceFactory.create(
         project=self.project,
         path='/main/path.po'
     )
     EntityFactory.create(resource=self.resource)
     StatsFactory.create(resource=self.resource, locale=self.locale)
Beispiel #8
0
 def test_for_project_locale_filter(self):
     """
     Evaluate entities filtering by locale, project, obsolete.
     """
     other_locale = LocaleFactory.create()
     other_project = ProjectFactory.create(locales=[self.locale, other_locale])
     # Obsolete_entity
     EntityFactory.create(obsolete=True, resource=self.main_resource, string="Obsolete String")
     entities = Entity.for_project_locale(self.project, other_locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(other_project, self.locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(self.project, self.locale)
     assert_equal(len(entities), 2)
Beispiel #9
0
 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]
     )
Beispiel #10
0
    def test_for_project_locale_order(self):
        """
        Return entities in correct order.
        """
        # First entity
        EntityFactory.create(order=1,
                             resource=self.main_resource,
                             string='Second String')
        # Second entity
        EntityFactory.create(order=0,
                             resource=self.main_resource,
                             string='First String')
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[2]['original'], 'First String')
        assert_equal(entities[3]['original'], 'Second String')
Beispiel #11
0
 def test_for_project_locale_filter(self):
     """
     Evaluate entities filtering by locale, project, obsolete.
     """
     other_locale = LocaleFactory.create()
     other_project = ProjectFactory.create(
         locales=[self.locale, other_locale])
     # Obsolete_entity
     EntityFactory.create(obsolete=True,
                          resource=self.main_resource,
                          string='Obsolete String')
     entities = Entity.for_project_locale(self.project, other_locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(other_project, self.locale)
     assert_equal(len(entities), 0)
     entities = Entity.for_project_locale(self.project, self.locale)
     assert_equal(len(entities), 2)
Beispiel #12
0
    def test_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths 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)

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

        assert_equal(details[0]["resource__path"], "/main/path.po")
        assert_equal(details[0]["translated_count"], 0)
        assert_equal(details[1]["resource__path"], "/other/path.po")
        assert_equal(details[1]["translated_count"], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]["resource__path"], "/other/path.po")
        assert_equal(details_other[0]["translated_count"], 0)
Beispiel #13
0
    def test_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths 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)

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

        assert_equal(details[0]['resource__path'], '/main/path.po')
        assert_equal(details[0]['translated_count'], 0)
        assert_equal(details[1]['resource__path'], '/other/path.po')
        assert_equal(details[1]['translated_count'], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]['resource__path'], '/other/path.po')
        assert_equal(details_other[0]['translated_count'], 0)
Beispiel #14
0
    def test_for_project_locale_order(self):
        """
        Return entities in correct order.
        """
        # First entity
        EntityFactory.create(
            order=1,
            resource=self.main_resource,
            string='Second String'
        )
        # Second entity
        EntityFactory.create(
            order=0,
            resource=self.main_resource,
            string='First String'
        )
        entities = Entity.for_project_locale(self.project, self.locale)

        assert_equal(entities[2]['original'], 'First String')
        assert_equal(entities[3]['original'], 'Second String')
Beispiel #15
0
    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)
        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])

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

        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)
Beispiel #16
0
    def test_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths 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)

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

        assert_equal(details[0]['title'], '/main/path.po')
        assert_equal(details[0]['translated_strings'], 0)
        assert_equal(details[1]['title'], '/other/path.po')
        assert_equal(details[1]['translated_strings'], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]['title'], '/other/path.po')
        assert_equal(details_other[0]['translated_strings'], 0)
Beispiel #17
0
    def test_locales_parts_stats_no_page_multiple_resources(self):
        """
        Return resource paths 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)

        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'], '/main/path.po')
        assert_equal(details[0]['translated_count'], 0)
        assert_equal(details[1]['resource__path'], '/other/path.po')
        assert_equal(details[1]['translated_count'], 0)
        assert_equal(len(details_other), 1)
        assert_equal(details_other[0]['resource__path'], '/other/path.po')
        assert_equal(details_other[0]['translated_count'], 0)
Beispiel #18
0
    def setUp(self):
        super(TranslationUpdateTestCase, self).setUp()

        locale = LocaleFactory.create()
        project = ProjectFactory.create()
        ProjectLocale.objects.create(
            project=project,
            locale=locale,
        )
        resource = ResourceFactory.create(project=project)
        entity = EntityFactory.create(resource=resource)

        self.translation = TranslationFactory.create(entity=entity, locale=locale)
        self.translation.locale.translators_group.user_set.add(self.user)
Beispiel #19
0
    def setUp(self):
        timezone_patch = patch('pontoon.sync.core.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'
        )
        self.main_db_entity = EntityFactory.create(
            resource=self.main_db_resource,
            string='Source String',
            key='Source String',
            obsolete=False
        )
        self.other_db_entity = EntityFactory.create(
            resource=self.other_db_resource,
            string='Other Source String',
            key='Other Source String',
            obsolete=False
        )
        self.main_db_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            plural_form=None,
            locale=self.translated_locale,
            string='Translated String',
            date=aware_datetime(1970, 1, 1),
            approved=True,
            extra={'tags': []}
        )

        # 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 = ChangeSet(
            self.db_project,
            self.vcs_project,
            aware_datetime(1970, 1, 1)
        )
Beispiel #20
0
    def setUp(self):
        self.now = aware_datetime(1970, 1, 1)

        timezone_patch = patch("pontoon.sync.tasks.timezone")
        self.mock_timezone = timezone_patch.start()
        self.addCleanup(timezone_patch.stop)
        self.mock_timezone.now.return_value = self.now

        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")
        self.main_db_entity = EntityFactory.create(
            resource=self.main_db_resource,
            string="Source String",
            key="Source String",
            obsolete=False,
        )
        self.other_db_entity = EntityFactory.create(
            resource=self.other_db_resource,
            string="Other Source String",
            key="Other Source String",
            obsolete=False,
        )
        self.main_db_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            plural_form=None,
            locale=self.translated_locale,
            string="Translated String",
            date=aware_datetime(1970, 1, 1),
            approved=True,
            extra={"tags": []},
        )

        # 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)

        vcs_changed_files = {
            self.main_db_resource.path: [self.translated_locale],
            self.other_db_resource.path: [self.translated_locale],
            self.missing_db_resource.path: [self.translated_locale],
        }

        changed_files_patch = patch.object(
            VCSProject,
            "changed_files",
            new_callable=PropertyMock,
            return_value=vcs_changed_files,
        )
        changed_files_patch.start()
        self.addCleanup(changed_files_patch.stop)

        source_repository = patch.object(
            Project,
            "source_repository",
            new_callable=PropertyMock,
            return_value=self.db_project.repositories.all()[0],
        )
        source_repository.start()
        self.addCleanup(source_repository.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 = ChangeSet(
            self.db_project,
            self.vcs_project,
            aware_datetime(1970, 1, 1),
            self.translated_locale,
        )
Beispiel #21
0
 def setUp(self):
     self.project = EntityFactory.create().resource.project
     self.locale = LocaleFactory.create()
Beispiel #22
0
 def setUp(self):
     self.project = EntityFactory.create().resource.project
     self.locale = LocaleFactory.create()
Beispiel #23
0
    def setUp(self):
        self.now = aware_datetime(1970, 1, 1)

        timezone_patch = patch('pontoon.sync.tasks.timezone')
        self.mock_timezone = timezone_patch.start()
        self.addCleanup(timezone_patch.stop)
        self.mock_timezone.now.return_value = self.now

        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')
        self.main_db_entity = EntityFactory.create(
            resource=self.main_db_resource,
            string='Source String',
            key='Source String',
            obsolete=False)
        self.other_db_entity = EntityFactory.create(
            resource=self.other_db_resource,
            string='Other Source String',
            key='Other Source String',
            obsolete=False)
        self.main_db_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            plural_form=None,
            locale=self.translated_locale,
            string='Translated String',
            date=aware_datetime(1970, 1, 1),
            approved=True,
            extra={'tags': []})

        # 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 = ChangeSet(self.db_project, self.vcs_project,
                                   aware_datetime(1970, 1, 1))