Ejemplo n.º 1
0
    def test_create_from_po_entry_with_invalid_occurrence_format_raise_error(self):
        translatable = OrganizationBuilder().with_id('test_create_from_po_entry_with_invalid_occurrence_format_raise_error_id').build()

        po_entry = polib.POEntry()
        po_entry.occurrences = [
            ('bad format', None)
        ]
        po_entry.msgid = 'translation_name_msgid'
        po_entry.msgstr = 'translation_name_msgstr'

        with self.assertRaises(MasterInstanceLookupError):
            TranslatableString.from_po_entry(po_entry, po_entry.occurrences[0])
Ejemplo n.º 2
0
    def test_create_from_po_entry_with_nonexistent_master_instance_raises_error(self):
        translatable = OrganizationBuilder().with_id('test_create_from_po_entry_with_nonexistent_master_instance_raises_error_id').build()

        po_entry = polib.POEntry()
        po_entry.occurrences = [
            ('organizations.organization@name@not_an_id', None)
        ]
        po_entry.msgid = 'translation_name_msgid'
        po_entry.msgstr = 'translation_name_msgstr'

        with self.assertRaises(MasterInstanceLookupError):
            TranslatableString.from_po_entry(po_entry, po_entry.occurrences[0])
Ejemplo n.º 3
0
    def test_create_from_po_entry_with_not_translatable_master_instance_raises_error(self):
        translatable = TestNotTranslatable(id='test_create_from_po_entry_with_not_translatable_master_instance_raises_error_id')

        po_entry = polib.POEntry()
        po_entry.occurrences = [
            ('contenttranslationtools.testnottranslatable@name@test_create_from_po_entry_with_not_translatable_master_instance_raises_error_id', None)
        ]
        po_entry.msgid = 'translation_name_msgid'
        po_entry.msgstr = 'translation_name_msgstr'

        with patch('translation.translatable_string.parse_instance_field_id') as parse_instance_field_id:
            parse_instance_field_id.return_value = (translatable, 'name')
            with self.assertRaises(ModelNotTranslatableError):
                TranslatableString.from_po_entry(po_entry, po_entry.occurrences[0])
Ejemplo n.º 4
0
    def test_create_from_po_entry(self):
        translatable = OrganizationBuilder().with_id('test_create_from_po_entry_id').build()

        base_translation = add_base_translation(
            translatable, name='translation_name_msgid'
        )

        po_entry = polib.POEntry()
        po_entry.occurrences = [
            ('organizations.organization@name@test_create_from_po_entry', None)
        ]
        po_entry.msgid = 'translation_name_msgid'
        po_entry.msgstr = 'translation_name_msgstr'

        with patch('translation.translatable_string.parse_instance_field_id') as parse_instance_field_id:
            parse_instance_field_id.return_value = (translatable, 'name')
            translatable_string = TranslatableString.from_po_entry(po_entry, po_entry.occurrences[0])
            parse_instance_field_id.assert_called_once_with('organizations.organization@name@test_create_from_po_entry')

        self.assertEqual(translatable_string._instance, translatable)
        self.assertEqual(translatable_string._field_id, 'name')
        self.assertEqual(translatable_string._source_str, 'translation_name_msgid')
        self.assertEqual(translatable_string._translated_str, 'translation_name_msgstr')