Ejemplo n.º 1
0
    def _test_properties_save2db(self):
        """Test creating source strings from a PROPERTIES file works"""
        handler = MozillaPropertiesHandler(
            os.path.join(os.path.dirname(__file__), 'complex.properties')
        )

        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)

        r = self.resource
        l = self.resource.source_language

        handler.bind_resource(r)

        handler.save2db(is_source=True)

        # Check that all 25 entities are created in the db
        self.assertEqual( SourceEntity.objects.filter(resource=r).count(), 25)

        # Check that all source translations are there
        self.assertEqual(
            len(Translation.objects.filter(source_entity__resource=r, language=l)), 25
        )

        # Import and save the finish translation
        handler.bind_file(os.path.join(os.path.dirname(__file__),'complex_hi_IN.properties'))
        l = Language.objects.get(code='hi_IN')
        handler.set_language(l)
        handler.parse_file()

        entities = 0
        translations = 0
        for s in handler.stringset:
            entities += 1
            if s.translation.strip() != '':
                translations += 1

        self.assertEqual(entities, 23)
        self.assertEqual(translations, 23)

        handler.save2db()
        # Check if all Source strings are untouched
        self.assertEqual(SourceEntity.objects.filter(resource=r).count(), 25)
        # Check that all translations are there
        self.assertEqual(len(Translation.objects.filter(source_entity__resource=r,
            language=l)), 23)
        self._mark_translation_as_reviewed(self.resource,
                ['Key00', 'Key02'], l, 2)

        return handler
Ejemplo n.º 2
0
    def test_properties_compile(self):
        """Test compiling translations for PROPERTIES files"""

        self.test_properties_save2db(delete=False)
        handler = MozillaPropertiesHandler()
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        old_template = handler.compiled_template
        handler.compile()
        self.assertNotEqual(old_template, handler.compiled_template)

        handler.set_language(Language.objects.get(code="hi_IN"))
        old_template = handler.compiled_template
        handler.compile()
        self.assertNotEqual(old_template, handler.compiled_template)

        # Cleanup
        self.resource.delete()
Ejemplo n.º 3
0
    def test_properties_parser(self):
        """PROPERTIES file tests."""
        # Parsing PROPERTIES file
        handler = MozillaPropertiesHandler(os.path.join(os.path.dirname(__file__), "complex.properties"))

        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        self.stringset = handler.stringset
        entities = 0
        translations = 0
        for s in self.stringset.strings:
            entities += 1
            if s.translation.strip() != "":
                translations += 1

        # Asserting number of entities - PROPERTIES file has 25 entries.
        # we ignore keys without a value
        self.assertEqual(entities, 25)
        self.assertEqual(translations, 25)
Ejemplo n.º 4
0
    def test_properties_parser(self):
        """PROPERTIES file tests."""
        # Parsing PROPERTIES file
        handler = MozillaPropertiesHandler(
            os.path.join(os.path.dirname(__file__), 'complex.properties')
        )

        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        self.stringset = handler.stringset
        entities = 0
        translations = 0
        for s in self.stringset:
            entities += 1
            if s.translation.strip() != '':
                translations += 1

        # Asserting number of entities - PROPERTIES file has 25 entries.
        # we ignore keys without a value
        self.assertEqual(entities, 25)
        self.assertEqual(translations, 25)