Пример #1
0
    def test_update_db_unapprove_fuzzy(self):
        """
        If an existing translation is fuzzy and doesn't match anything in VCS,
        unapprove and unfuzzy that translation without rejecting it.
        """
        self.main_db_translation.fuzzy = True
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = "New Translated String"

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None,
            rejected=False,
            fuzzy=False,
        )

        assert ActionLog.objects.filter(
            action_type="translation:unapproved",
            translation=self.main_db_translation.pk,
        ).exists()
Пример #2
0
    def test_update_db_existing_translation(self):
        """
        Update an existing translation in the DB with changes from VCS.
        """
        # Set up DB and VCS to differ and require an update.
        self.main_db_translation.fuzzy = True
        self.main_db_translation.extra = {}
        self.main_db_translation.save()

        self.main_vcs_entity.key = "Source String"
        self.main_vcs_entity.comments = ["first comment", "second"]
        self.main_vcs_entity.order = 7
        self.main_vcs_entity.string_plural = "plural string"
        self.main_vcs_entity.source = ["foo.py:87"]
        self.main_vcs_translation.fuzzy = False
        # The test translation is from a langfile so we can use tags
        # for testing extra.
        self.main_vcs_translation.tags = set(["ok"])

        self.update_main_db_entity()
        self.main_db_entity.refresh_from_db()
        assert_attributes_equal(
            self.main_db_entity,
            key="Source String",
            comment="first comment\nsecond",
            order=7,
            string_plural="plural string",
            source=["foo.py:87"],
        )

        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(self.main_db_translation,
                                fuzzy=False,
                                extra={"tags": ["ok"]})
Пример #3
0
 def test_parse_hash_with_rule(self):
     source = '''
     <sample_hash[@cldr.global($n)] {
         *one: "First string",
         other: "Second string"
     }
     first_attr: "First string attribute"
     >
     '''
     _, resource = self.parse_string(source)
     assert_equal(len(resource.translations), 2)
     assert_attributes_equal(resource.translations[0],
         key=self.key('sample_hash'),
         source_string='First string',
         source_string_plural='Second string',
         strings={
             0: 'First string',
             1: 'Second string',
         },
         order=0)
     assert_attributes_equal(resource.translations[1],
         key=self.key('sample_hash.first_attr'),
         strings={None: 'First string attribute'},
         order=1
     )
Пример #4
0
    def run_parse_multiple_comments(
        self,
        input_string,
        translation_index,
        comments=None,
    ):
        path, resource = self.parse_string(input_string)

        if comments is None:
            comments = ["First comment", "Second comment"]

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=comments,
            source=[],
            key=self.key("Multiple Comments"),
            strings={None: "Translated Multiple Comments"},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string="Multiple Comments",
                source_string_plural="",
            )
Пример #5
0
    def run_parse_multiple_comments(
        self,
        input_string,
        translation_index,
        comments=None,
    ):
        path, resource = self.parse_string(input_string)

        if comments is None:
            comments = ['First comment', 'Second comment']

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=comments,
            source=[],
            key=self.key('Multiple Comments'),
            strings={None: 'Translated Multiple Comments'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Multiple Comments',
                source_string_plural=''
            )
Пример #6
0
 def test_parse_hash_attributes(self):
     source = '''
     <sample_hash {
         *one: "First string",
         other: "Second string"
     }
     first_attr: "First string attribute"
     >
     '''
     _, resource = self.parse_string(source)
     assert_equal(len(resource.translations), 2)
     assert_attributes_equal(resource.translations[0],
                             key=self.key('sample_hash'),
                             source_string='First string',
                             source_string_plural='Second string',
                             strings={
                                 0: 'First string',
                                 1: 'Second string',
                             },
                             order=0)
     assert_attributes_equal(resource.translations[1],
                             key=self.key('sample_hash.first_attr'),
                             source_string='First string attribute',
                             strings={None: 'First string attribute'},
                             order=1)
Пример #7
0
    def test_update_db_existing_translation(self):
        """
        Update an existing translation in the DB with changes from VCS.
        """
        # Set up DB and VCS to differ and require an update.
        self.main_db_translation.fuzzy = True
        self.main_db_translation.extra = {}
        self.main_db_translation.save()

        self.main_vcs_entity.key = 'Source String'
        self.main_vcs_entity.comments = ['first comment', 'second']
        self.main_vcs_entity.order = 7
        self.main_vcs_entity.string_plural = 'plural string'
        self.main_vcs_entity.source = ['foo.py:87']
        self.main_vcs_translation.fuzzy = False
        # The test translation is from a langfile so we can use tags
        # for testing extra.
        self.main_vcs_translation.tags = set(['ok'])

        self.update_main_db_entity()
        self.main_db_entity.refresh_from_db()
        assert_attributes_equal(
            self.main_db_entity,
            key='Source String',
            comment='first comment\nsecond',
            order=7,
            string_plural='plural string',
            source=['foo.py:87'],
        )

        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(self.main_db_translation,
                                fuzzy=False,
                                extra={'tags': ['ok']})
Пример #8
0
    def test_create_db(self):
        """Create new entity in the database."""
        self.main_db_entity.delete()

        self.main_vcs_entity.key = 'Source String'
        self.main_vcs_entity.comments = ['first comment', 'second']
        self.main_vcs_entity.order = 7
        self.main_vcs_translation.fuzzy = False
        self.main_vcs_entity.string_plural = 'plural string'
        self.main_vcs_entity.source = ['foo.py:87']

        self.changeset.create_db_entity(self.main_vcs_entity)
        self.changeset.execute()
        new_entity = Entity.objects.get(
            resource__path=self.main_vcs_resource.path,
            string=self.main_vcs_entity.string)
        assert_attributes_equal(
            new_entity,
            resource=self.main_db_resource,
            string='Source String',
            key='Source String',
            comment='first comment\nsecond',
            order=7,
            string_plural='plural string',
            source=['foo.py:87'],
        )

        new_translation = new_entity.translation_set.all()[0]
        assert_attributes_equal(new_translation,
                                locale=self.translated_locale,
                                string='Translated String',
                                plural_form=None,
                                approved=True,
                                approved_date=aware_datetime(1970, 1, 1),
                                fuzzy=False)
Пример #9
0
    def test_update_db_unapprove_existing(self):
        """
        Any existing translations that don't match anything in VCS get
        unapproved, unless they were created after self.now.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        created_after_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None
        )

        created_after_translation.refresh_from_db()
        assert_attributes_equal(
            created_after_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )
Пример #10
0
    def test_update_db_unapprove_existing(self):
        """
        Any existing translations that don't match anything in VCS get
        unapproved, unless they were created after self.now.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        created_after_translation = TranslationFactory.create(
            entity=self.main_db_entity,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_user=None,
            approved_date=None
        )

        created_after_translation.refresh_from_db()
        assert_attributes_equal(
            created_after_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 3)
        )
Пример #11
0
 def test_parse_multiline_comment(self):
     path, resource = self.parse_string(BASE_L20N_FILE)
     assert_attributes_equal(
         resource.translations[3],
         comments=["Multiline\nComment"],
         key=self.key('Multiline Comment'),
         strings={None: 'Multiline Comment'},
         order=3,
     )
Пример #12
0
 def test_parse_multiline_comment(self):
     path, resource = self.parse_string(BASE_L20N_FILE)
     assert_attributes_equal(
         resource.translations[3],
         comments=["Multiline\nComment"],
         key=self.key('Multiline Comment'),
         strings={None: 'Multiline Comment'},
         order=3,
     )
Пример #13
0
    def test_update_db_unfuzzy_existing(self):
        """
        Any existing fuzzy translations get unfuzzied.
        """
        self.main_db_translation.fuzzy = True
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(self.main_db_translation, fuzzy=False)
Пример #14
0
 def test_parse_no_comments_no_sources(self):
     path, resource = self.parse_string(BASE_JSON_FILE)
     assert_attributes_equal(
         resource.translations[0],
         comments=[],
         source=[],
         key=self.key('["No Comments or Sources"]'),
         strings={None: "Translated No Comments or Sources"},
         source_string_plural="",
         fuzzy=False,
         order=0,
     )
Пример #15
0
 def test_parse_nested(self):
     path, resource = self.parse_string(BASE_JSON_FILE)
     assert_attributes_equal(
         resource.translations[1],
         comments=[],
         source=[],
         # Nested keys are internally using "\200" as a separator
         key=self.key('["Nested", "key"]'),
         strings={None: "value"},
         fuzzy=False,
         order=1,
     )
Пример #16
0
    def test_parse_basic(self):
        input_string = BASE_FTL_FILE
        translation_index = 0
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=['Sample comment'],
            key=self.key('Source String'),
            strings={None: 'SourceString = Translated String\n'},
            fuzzy=False,
            order=translation_index,
        )
Пример #17
0
 def test_parse_multiple_comments(self):
     input_string = BASE_JSON_FILE
     translation_index = 1
     path, resource = self.parse_string(input_string)
     assert_attributes_equal(
         resource.translations[translation_index],
         comments=['Second comment'],
         source=[],
         key=self.key('Multiple Comments'),
         strings={None: 'Translated Multiple Comments'},
         fuzzy=False,
         order=translation_index,
     )
Пример #18
0
    def test_parse_basic(self):
        input_string = BASE_FTL_FILE
        translation_index = 0
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=['Sample comment'],
            key=self.key('Source String'),
            strings={None: 'SourceString = Translated String\n'},
            fuzzy=False,
            order=translation_index,
        )
Пример #19
0
    def test_parse_multiple_comments(self):
        input_string = BASE_FTL_FILE
        translation_index = 1
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=['First comment\nSecond comment'],
            source=[],
            key=self.key('Multiple Comments'),
            strings={None: 'MultipleComments = Translated Multiple Comments\n'},
            fuzzy=False,
            order=translation_index,
        )
Пример #20
0
    def test_parse_no_comments_no_sources(self):
        input_string = BASE_FTL_FILE
        translation_index = 2
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('No Comments Or Sources'),
            strings={None: 'NoCommentsOrSources = Translated No Comments or Sources\n'},
            fuzzy=False,
            order=translation_index,
        )
Пример #21
0
    def test_load_utf8_bom(self):
        """
        Ensure that the langfile parser can load UTF-8 files with an encoded
        BOM at the beginning of the file.

        See https://docs.python.org/2/library/codecs.html for details (search
        for the string "utf-8-sig").
        """
        current_dir = os.path.dirname(__file__)
        resource = lang.parse(os.path.join(current_dir, 'bom.lang'))
        assert_equal(len(resource.translations), 1)
        assert_attributes_equal(resource.translations[0],
                                source_string='Source String',
                                strings={None: 'Translated String'})
Пример #22
0
    def test_parse_multiple_comments(self):
        input_string = BASE_FTL_FILE
        translation_index = 1
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=["First comment\nSecond comment"],
            source=[],
            key=self.key("Multiple Comments"),
            strings={None: "MultipleComments = Translated Multiple Comments\n"},
            fuzzy=False,
            order=translation_index,
        )
Пример #23
0
    def test_update_db_approve_translation(self):
        """
        Approve any un-approved translations that have counterparts in
        VCS.
        """
        self.main_db_translation.approved = False
        self.main_db_translation.approved_date = None
        self.main_db_translation.save()

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(self.main_db_translation,
                                approved=True,
                                approved_date=aware_datetime(1970, 1, 1))
Пример #24
0
    def test_update_db_unfuzzy_existing(self):
        """
        Any existing fuzzy translations get unfuzzied.
        """
        self.main_db_translation.fuzzy = True
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            fuzzy=False
        )
Пример #25
0
    def test_parse_no_comments_no_sources(self):
        input_string = BASE_FTL_FILE
        translation_index = 2
        path, resource = self.parse_string(input_string)

        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key("No Comments Or Sources"),
            strings={None: "NoCommentsOrSources = Translated No Comments or Sources\n"},
            fuzzy=False,
            order=translation_index,
        )
Пример #26
0
    def test_update_db_dont_approve_fuzzy(self):
        """
        Do not approve un-approved translations that have non-fuzzy
        counterparts in VCS.
        """
        self.main_db_translation.approved = False
        self.main_db_translation.approved_date = None
        self.main_db_translation.save()
        self.main_vcs_translation.fuzzy = True

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(self.main_db_translation,
                                approved=False,
                                approved_date=None)
Пример #27
0
 def test_key_and_context_format(self):
     input_string = dedent(
         """
         {
             "Source": {
               "String": "Source String"
             }
         }
     """
     )
     path, resource = self.parse_string(input_string)
     assert_attributes_equal(
         resource.translations[0],
         key='["Source", "String"]',
         context="Source.String",
     )
Пример #28
0
    def run_parse_multiple_sources(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[('file.py', '2'), ('file.py', '3')],
            key=self.key('Multiple Sources'),
            strings={None: 'Translated Multiple Sources'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(resource.translations[translation_index],
                                    source_string='Multiple Sources',
                                    source_string_plural='')
Пример #29
0
    def run_parse_missing_translation(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Missing Translation'),
            strings={},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(resource.translations[translation_index],
                                    source_string='Missing Translation',
                                    source_string_plural='')
Пример #30
0
    def test_update_db_approve_translation(self):
        """
        Approve any un-approved translations that have counterparts in
        VCS.
        """
        self.main_db_translation.approved = False
        self.main_db_translation.approved_date = None
        self.main_db_translation.save()

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=True,
            approved_date=aware_datetime(1970, 1, 1)
        )
Пример #31
0
    def test_load_utf8_bom(self):
        """
        Ensure that the langfile parser can load UTF-8 files with an encoded
        BOM at the beginning of the file.

        See https://docs.python.org/2/library/codecs.html for details (search
        for the string "utf-8-sig").
        """
        current_dir = os.path.dirname(__file__)
        resource = lang.parse(os.path.join(current_dir, 'bom.lang'))
        assert_equal(len(resource.translations), 1)
        assert_attributes_equal(
            resource.translations[0],
            source_string='Source String',
            strings={None: 'Translated String'}
        )
Пример #32
0
    def run_parse_fuzzy(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Fuzzy'),
            strings={None: 'Translated Fuzzy'},
            fuzzy=True,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(resource.translations[translation_index],
                                    source_string='Fuzzy',
                                    source_string_plural='')
 def test_parse_placeholder(self):
     input_string = BASE_JSON_FILE
     translation_index = 3
     path, resource = self.parse_string(input_string)
     assert_attributes_equal(
         resource.translations[translation_index],
         comments=['Peer greeting'],
         source={"your_name": {
             "content": "$1",
             "example": "Cira"
         }},
         key=self.key('placeholder'),
         strings={None: 'Hello $YOUR_NAME$'},
         fuzzy=False,
         order=translation_index,
     )
Пример #34
0
    def test_moz_langpack_contributors(self):
        """
        If a .inc file has a commented-out entity named
        MOZ_LANGPACK_CONTRIBUTORS, the parser should un-comment it and
        process it as an entity.
        """
        input_string = dedent("""
            #define String Some String

            # #define MOZ_LANGPACK_CONTRIBUTORS Contributor list
        """)

        path, resource = self.parse_string(input_string)
        assert_equal(len(resource.translations), 2)
        assert_attributes_equal(resource.translations[1],
                                key='MOZ_LANGPACK_CONTRIBUTORS',
                                strings={None: 'Contributor list'})
Пример #35
0
 def test_parse_hash_entities(self):
     source = '''
     /*Hash comment*/
     <multiple_hash_items {
         *one: "One item",
         other: "Other items",
     }>
     '''
     path, resource = self.parse_string(source)
     assert_attributes_equal(resource.translations[0],
                             key=self.key('multiple_hash_items'),
                             strings={
                                 0: "One item",
                                 1: "Other items",
                             },
                             comments=['Hash comment'],
                             order=0)
Пример #36
0
    def test_update_db_reject_approved(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=True,
        )
Пример #37
0
    def run_parse_no_comments_no_sources(self, input_string,
                                         translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('No Comments or Sources'),
            strings={None: 'Translated No Comments or Sources'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(resource.translations[translation_index],
                                    source_string='No Comments or Sources',
                                    source_string_plural='')
Пример #38
0
    def test_update_db_dont_approve_fuzzy(self):
        """
        Do not approve un-approved translations that have non-fuzzy
        counterparts in VCS.
        """
        self.main_db_translation.approved = False
        self.main_db_translation.approved_date = None
        self.main_db_translation.save()
        self.main_vcs_translation.fuzzy = True

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            approved=False,
            approved_date=None
        )
Пример #39
0
    def test_update_db_reject_approved(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = 'New Translated String'

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=True,
        )
Пример #40
0
    def test_update_db_new_translation(self):
        """
        If a matching translation does not exist in the database, create a new
        one.
        """
        self.main_db_translation.delete()
        self.update_main_db_entity()

        translation = self.main_db_entity.translation_set.all()[0]
        assert_attributes_equal(translation,
                                locale=self.translated_locale,
                                string='Translated String',
                                plural_form=None,
                                approved=True,
                                approved_date=aware_datetime(1970, 1, 1),
                                fuzzy=False,
                                extra={'tags': []})
Пример #41
0
    def run_parse_fuzzy(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Fuzzy'),
            strings={None: 'Translated Fuzzy'},
            fuzzy=True,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Fuzzy',
                source_string_plural=''
            )
Пример #42
0
    def run_parse_no_comments_no_sources(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('No Comments or Sources'),
            strings={None: 'Translated No Comments or Sources'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='No Comments or Sources',
                source_string_plural=''
            )
Пример #43
0
    def run_parse_missing_traslation(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Missing Translation'),
            strings={},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Missing Translation',
                source_string_plural=''
            )
Пример #44
0
 def test_parse_placeholder(self):
     input_string = BASE_JSON_FILE
     translation_index = 3
     path, resource = self.parse_string(input_string)
     assert_attributes_equal(
         resource.translations[translation_index],
         comments=['Peer greeting'],
         source={
             "your_name": {
                 "content": "$1",
                 "example": "Cira"
             }
         },
         key=self.key('placeholder'),
         strings={None: 'Hello $YOUR_NAME$'},
         fuzzy=False,
         order=translation_index,
     )
Пример #45
0
 def test_parse_hash_entities(self):
     source = '''
     /*Hash comment*/
     <multiple_hash_items {
         *one: "One item",
         other: "Other items",
     }>
     '''
     path, resource = self.parse_string(source)
     assert_attributes_equal(resource.translations[0],
         key=self.key('multiple_hash_items'),
         strings={
             0: "One item",
             1: "Other items",
         },
         comments=['Hash comment'],
         order=0
     )
Пример #46
0
    def run_parse_empty_translation(self, input_string, translation_index):
        """Test that empty translations are parsed properly."""
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Empty Translation'),
            strings={None: u''},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Empty Translation',
            )
Пример #47
0
    def run_parse_multiple_sources(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[("file.py", "2"), ("file.py", "3")],
            key=self.key("Multiple Sources"),
            strings={None: "Translated Multiple Sources"},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string="Multiple Sources",
                source_string_plural="",
            )
Пример #48
0
    def run_parse_multiple_sources(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[('file.py', '2'), ('file.py', '3')],
            key=self.key('Multiple Sources'),
            strings={None: 'Translated Multiple Sources'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Multiple Sources',
                source_string_plural=''
            )
Пример #49
0
    def test_update_db_new_translation(self):
        """
        If a matching translation does not exist in the database, create a new
        one.
        """
        self.main_db_translation.delete()
        self.update_main_db_entity()

        translation = self.main_db_entity.translation_set.all()[0]
        assert_attributes_equal(
            translation,
            locale=self.translated_locale,
            string='Translated String',
            plural_form=None,
            approved=True,
            approved_date=aware_datetime(1970, 1, 1),
            fuzzy=False,
            extra={'tags': []}
        )
Пример #50
0
    def test_moz_langpack_contributors(self):
        """
        If a .inc file has a commented-out entity named
        MOZ_LANGPACK_CONTRIBUTORS, the parser should un-comment it and
        process it as an entity.
        """
        input_string = dedent("""
            #define String Some String

            # #define MOZ_LANGPACK_CONTRIBUTORS Contributor list
        """)

        path, resource = self.parse_string(input_string)
        assert_equal(len(resource.translations), 2)
        assert_attributes_equal(
            resource.translations[1],
            key='MOZ_LANGPACK_CONTRIBUTORS',
            strings={None: 'Contributor list'}
        )
Пример #51
0
    def test_update_db_reject_approved_skip_fuzzy(self):
        """
        When a translation is submitted through VCS, reject any existing approved translations.
        Unless the same translation is submitted and only made fuzzy.
        """
        self.main_db_translation.approved = True
        self.main_db_translation.approved_date = aware_datetime(1970, 1, 1)
        self.main_db_translation.approved_user = UserFactory.create()
        self.main_db_translation.rejected = False
        self.main_db_translation.save()
        self.main_vcs_translation.strings[None] = self.main_db_translation.string
        self.main_vcs_translation.fuzzy = True

        self.update_main_db_entity()
        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            rejected=False,
        )
Пример #52
0
    def run_parse_plural_translation_missing(self, input_string, translation_index):
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=[],
            source=[],
            key=self.key('Plural %(count)s string with missing translations'),
            strings={
                1: 'Translated Plural %(count)s strings with missing translations'
            },
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Plural %(count)s string with missing translations',
                source_string_plural='Plural %(count)s strings with missing translations',
            )
Пример #53
0
    def test_period_filters(self):
        """
        Total counts should be filtered by given date.
        Test creates 2 contributors with different activity periods and checks if they are filtered properly.
        """

        first_contributor = self.create_contributor_with_translation_counts(approved=12, unapproved=1, needs_work=2,
            date=aware_datetime(2015, 3, 2))

        # Second contributor
        self.create_contributor_with_translation_counts(approved=2, unapproved=11, needs_work=2,
            date=aware_datetime(2015, 6, 1))

        TranslationFactory.create_batch(5, approved=True, user=first_contributor, date=aware_datetime(2015, 7, 2))

        top_contributors = User.translators.with_translation_counts(aware_datetime(2015, 6, 10))

        assert_equal(top_contributors.count(), 1)
        assert_attributes_equal(top_contributors[0], translations_count=5,
            translations_approved_count=5, translations_unapproved_count=0,
            translations_needs_work_count=0)

        top_contributors = User.translators.with_translation_counts(aware_datetime(2015, 5, 10))

        assert_equal(top_contributors.count(), 2)
        assert_attributes_equal(top_contributors[0], translations_count=15,
            translations_approved_count=2, translations_unapproved_count=11,
            translations_needs_work_count=2)
        assert_attributes_equal(top_contributors[1], translations_count=5,
            translations_approved_count=5, translations_unapproved_count=0,
            translations_needs_work_count=0)

        top_contributors = User.translators.with_translation_counts(aware_datetime(2015, 1, 10))

        assert_equal(top_contributors.count(), 2)
        assert_attributes_equal(top_contributors[0], translations_count=20,
            translations_approved_count=17, translations_unapproved_count=1,
            translations_needs_work_count=2)
        assert_attributes_equal(top_contributors[1], translations_count=15,
            translations_approved_count=2, translations_unapproved_count=11,
            translations_needs_work_count=2)
Пример #54
0
    def run_parse_basic(self, input_string, translation_index):
        """Basic translation with a comment and source."""
        path, resource = self.parse_string(input_string)
        assert_attributes_equal(
            resource.translations[translation_index],
            comments=['Sample comment'],
            key=self.key('Source String'),
            strings={None: 'Translated String'},
            fuzzy=False,
            order=translation_index,
        )

        if self.supports_source:
            assert_equal(resource.translations[translation_index].source, [('file.py', '1')])

        if self.supports_source_string:
            assert_attributes_equal(
                resource.translations[translation_index],
                source_string='Source String',
                source_string_plural=''
            )
Пример #55
0
    def test_query_args_filtering(self):
        """
        Tests if query args are honored properly and contributors are filtered.
        """
        locale_first, locale_second = LocaleFactory.create_batch(2)

        first_contributor = self.create_contributor_with_translation_counts(
            approved=12, unapproved=1, needs_work=2, locale=locale_first)
        second_contributor = self.create_contributor_with_translation_counts(
            approved=11, unapproved=1, needs_work=2, locale=locale_second)
        third_contributor = self.create_contributor_with_translation_counts(
            approved=10, unapproved=12, needs_work=2, locale=locale_first)

        # Testing filtering for the first locale
        top_contributors = User.translators.with_translation_counts(aware_datetime(2015, 1, 1), Q(translation__locale=locale_first))
        assert_equal(top_contributors.count(), 2)
        assert_equal(top_contributors[0], third_contributor)
        assert_attributes_equal(top_contributors[0], translations_count=24,
            translations_approved_count=10, translations_unapproved_count=12,
            translations_needs_work_count=2)

        assert_equal(top_contributors[1], first_contributor)
        assert_attributes_equal(top_contributors[1], translations_count=15,
            translations_approved_count=12, translations_unapproved_count=1,
            translations_needs_work_count=2)

        # Testing filtering for the second locale
        top_contributors = User.translators.with_translation_counts(aware_datetime(2015, 1, 1), Q(translation__locale=locale_second))

        assert_equal(top_contributors.count(), 1)
        assert_equal(top_contributors[0], second_contributor)
        assert_attributes_equal(top_contributors[0], translations_count=14,
            translations_approved_count=11, translations_unapproved_count=1,
            translations_needs_work_count=2)
Пример #56
0
    def test_translation_counts(self):
        """
        Checks if translation counts are calculated properly.
        Tests creates 3 contributors with different numbers translations and checks if their counts match.
        """

        first_contributor = self.create_contributor_with_translation_counts(approved=7, unapproved=3, needs_work=2)
        second_contributor = self.create_contributor_with_translation_counts(approved=5, unapproved=9, needs_work=2)
        third_contributor = self.create_contributor_with_translation_counts(approved=1, unapproved=2, needs_work=5)

        top_contributors = User.translators.with_translation_counts()
        assert_equal(top_contributors.count(), 3)

        assert_equal(top_contributors[0], second_contributor)
        assert_equal(top_contributors[1], first_contributor)
        assert_equal(top_contributors[2], third_contributor)

        assert_attributes_equal(top_contributors[0], translations_count=16,
            translations_approved_count=5, translations_unapproved_count=9,
            translations_needs_work_count=2)
        assert_attributes_equal(top_contributors[1], translations_count=12,
            translations_approved_count=7, translations_unapproved_count=3,
            translations_needs_work_count=2)
        assert_attributes_equal(top_contributors[2], translations_count=8,
            translations_approved_count=1, translations_unapproved_count=2,
            translations_needs_work_count=5)
Пример #57
0
    def test_parse_string_attributes(self):
        source = '''
        <multiple_attributes "Multiple attributes"
        first: "First attribute"
        second: "Second attribute">
        '''
        path, resource = self.parse_string(source)

        assert_attributes_equal(resource.translations[0],
            key=self.key('multiple_attributes'),
            strings={None: 'Multiple attributes'},
            order=0,
        )

        assert_attributes_equal(resource.translations[1],
            key=self.key('multiple_attributes.first'),
            strings={None: 'First attribute'},
            order=1,
        )

        assert_attributes_equal(resource.translations[2],
            key=self.key('multiple_attributes.second'),
            strings={None: 'Second attribute'},
            order=2,
        )
Пример #58
0
    def test_create_db(self):
        """Create new entity in the database."""
        self.main_db_entity.delete()

        self.main_vcs_entity.key = 'string-key'
        self.main_vcs_entity.comments = ['first comment', 'second']
        self.main_vcs_entity.order = 7
        self.main_vcs_translation.fuzzy = False
        self.main_vcs_entity.string_plural = 'plural string'
        self.main_vcs_entity.source = ['foo.py:87']

        self.changeset.create_db_entity(self.main_vcs_entity)
        self.changeset.execute()
        new_entity = Entity.objects.get(
            resource__path=self.main_vcs_resource.path,
            string=self.main_vcs_entity.string
        )
        assert_attributes_equal(
            new_entity,
            resource=self.main_db_resource,
            string='Source String',
            key='string-key',
            comment='first comment\nsecond',
            order=7,
            string_plural='plural string',
            source=['foo.py:87'],
        )

        new_translation = new_entity.translation_set.all()[0]
        assert_attributes_equal(
            new_translation,
            locale=self.translated_locale,
            string='Translated String',
            plural_form=None,
            approved=True,
            approved_date=aware_datetime(1970, 1, 1),
            fuzzy=False
        )
Пример #59
0
    def test_update_db_existing_translation(self):
        """
        Update an existing translation in the DB with changes from VCS.
        """
        self.create_db_entities_translations()

        # Set up DB and VCS to differ and require an update.
        self.main_db_translation.fuzzy = True
        self.main_db_translation.extra = {}
        self.main_db_translation.save()

        self.main_vcs_entity.key = 'string-key'
        self.main_vcs_entity.comments = ['first comment', 'second']
        self.main_vcs_entity.order = 7
        self.main_vcs_entity.string_plural = 'plural string'
        self.main_vcs_entity.source = ['foo.py:87']
        self.main_vcs_translation.fuzzy = False
        # The test translation is from a langfile so we can use tags
        # for testing extra.
        self.main_vcs_translation.tags = set(['ok'])

        self.update_main_db_entity()
        self.main_db_entity.refresh_from_db()
        assert_attributes_equal(
            self.main_db_entity,
            key='string-key',
            comment='first comment\nsecond',
            order=7,
            string_plural='plural string',
            source=['foo.py:87'],
        )

        self.main_db_translation.refresh_from_db()
        assert_attributes_equal(
            self.main_db_translation,
            fuzzy=False,
            extra={'tags': ['ok']}
        )