예제 #1
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)
예제 #2
0
    def test_handle_entities(self):
        """Call handle_entity on all matching Entity and VCSEntity pairs."""
        vcs_entities = {
            'match': VCSEntityFactory(),
            'no_db_match': VCSEntityFactory()
        }
        db_entities = {
            'match': EntityFactory(),
            'no_vcs_match': EntityFactory()
        }

        with patch('pontoon.sync.core.get_vcs_entities', return_value=vcs_entities), \
             patch('pontoon.sync.core.get_db_entities', return_value=db_entities), \
             patch('pontoon.sync.core.handle_entity') as mock_handle_entity:
            sync_project(self.db_project)

        mock_handle_entity.assert_has_calls([
            call(ANY, self.db_project, 'match', db_entities['match'],
                 vcs_entities['match']),
            call(ANY, self.db_project, 'no_vcs_match',
                 db_entities['no_vcs_match'], None),
            call(ANY, self.db_project, 'no_db_match', None,
                 vcs_entities['no_db_match']),
        ],
                                            any_order=True)
예제 #3
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)
예제 #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])
예제 #5
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)
예제 #6
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': []}
     )
예제 #7
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': []}
     )
예제 #8
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)
예제 #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])
예제 #10
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)
예제 #11
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")
예제 #12
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)
예제 #13
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)
예제 #14
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]
     )
예제 #15
0
    def test_manage_project_strings_list(self):
        project = ProjectFactory.create(data_source='database',
                                        repositories=[])
        resource = ResourceFactory.create(project=project)
        nb_entities = 2
        entities = EntityFactory.create_batch(nb_entities, resource=resource)

        url = reverse('pontoon.admin.project.strings', args=(project.slug, ))

        response = self.client.get(url)
        assert_code(response, 200)
        for i in range(nb_entities):
            assert_contains(response, 'string %s' % i)

        # Test editing strings and comments.
        form_data = {
            'form-TOTAL_FORMS': nb_entities,
            'form-INITIAL_FORMS': nb_entities,
            'form-MIN_NUM_FORMS': 0,
            'form-MAX_NUM_FORMS': 1000,
            'form-0-id': entities[0].id,
            'form-0-string': 'changed 0',
            'form-0-comment': 'Wubba lubba dub dub',
            'form-1-id': entities[1].id,
            'form-1-string': 'string 1',
            'form-1-obsolete': 'on',  # Remove this one.
        }

        response = self.client.post(url, form_data)
        assert_code(response, 200)
        assert_contains(response, 'changed 0')
        assert_contains(response, 'Wubba lubba dub dub')
        assert_not_contains(response, 'string 0')
        assert_not_contains(response, 'string 1')  # It's been removed.
예제 #16
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')
예제 #17
0
 def setUp(self):
     self.resource = ResourceFactory.create()
     self.locale = LocaleFactory.create()
     ProjectLocale.objects.create(project=self.resource.project, locale=self.locale)
     TranslatedResource.objects.create(resource=self.resource, locale=self.locale)
     self.entities = EntityFactory.create_batch(3, resource=self.resource)
     self.entities_pks = [e.pk for e in self.entities]
예제 #18
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)
예제 #19
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)
예제 #20
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)
예제 #21
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')
예제 #22
0
    def test_handle_project_handle_entities(self):
        """Call handle_entity on all matching Entity and VCSEntity pairs."""
        vcs_entities = {
            'match': VCSEntityFactory(),
            'no_db_match': VCSEntityFactory()
        }
        self.command.get_vcs_entities = Mock(return_value=vcs_entities)
        db_entities = {
            'match': EntityFactory(),
            'no_vcs_match': EntityFactory()
        }
        self.command.get_db_entities = Mock(return_value=db_entities)
        self.command.handle_entity = Mock()

        self.command.handle_project(self.db_project)
        self.command.handle_entity.assert_has_calls([
            call(ANY, self.db_project, 'match', db_entities['match'], vcs_entities['match']),
            call(ANY, self.db_project, 'no_vcs_match', db_entities['no_vcs_match'], None),
            call(ANY, self.db_project, 'no_db_match', None, vcs_entities['no_db_match']),
        ], any_order=True)
예제 #23
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)
예제 #24
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)
예제 #25
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)
예제 #26
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)
예제 #27
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,
        )
예제 #28
0
파일: __init__.py 프로젝트: rajul/pontoon
    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)
        )
예제 #29
0
 def setUp(self):
     # Create a list of instances in order to filter them.
     EntityFactory.create_batch(10)
예제 #30
0
 def setUp(self):
     self.project = EntityFactory.create().resource.project
     self.locale = LocaleFactory.create()
예제 #31
0
 def setUp(self):
     self.project = EntityFactory.create().resource.project
     self.locale = LocaleFactory.create()
예제 #32
0
 def setUp(self):
     # Create a list of instances in order to filter them.
     EntityFactory.create_batch(10)
예제 #33
0
 def setUp(self):
     # Create a list of instances in order to filter them.
     EntityFactory.create_batch(10, string='qwertyuiop')
예제 #34
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))
예제 #35
0
def collation_entities():
    # Create a list of instances in order to filter them.
    EntityFactory.create_batch(10, string="qwertyuiop")