Ejemplo n.º 1
0
    def test_save_translation_changes_fields_if_modified(self):
        new_translatable_string = TranslatableString(
            self.translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr_2'
        )

        self.translatable_string.save_translation('fr')
        new_translatable_string.save_translation('fr')

        translation = self.translatable.get_translation('fr')
        self.assertEqual(translation.master, self.translatable)
        self.assertEqual(translation.name, 'translation_name_msgstr_2')
Ejemplo n.º 2
0
    def test_save_translation_returns_true_if_modified(self):
        new_translatable_string = TranslatableString(
            self.translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr_2'
        )

        self.translatable_string.save_translation('fr')
        modified = new_translatable_string.save_translation('fr')
        self.assertTrue(modified)
Ejemplo n.º 3
0
class ValidTranslatableStringTests(TestCase):
    def setUp(self):
        self.translatable = OrganizationBuilder().with_id('translatable_string_tests_id').build()

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

        if self.translatable.has_translation('fr'):
            self.translatable.delete_translation('fr')

        self.translatable_string = TranslatableString(
            self.translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr'
        )

    def test_as_po_entry(self):
        po_entry = self.translatable_string.as_po_entry()

        self.assertEqual(po_entry.msgid, 'translation_name_msgid')
        self.assertEqual(po_entry.msgstr, 'translation_name_msgstr')
        self.assertEqual(po_entry.occurrences, [
            ('organizations.organization@{}@{}'.format('name', 'translatable_string_tests_id'), None)
        ])

    def test_save_translation_returns_true_if_created(self):
        modified = self.translatable_string.save_translation('fr')
        self.assertTrue(modified)

        translation = self.translatable.get_translation('fr')
        self.assertTrue(modified)
        self.assertEqual(translation.master, self.translatable)
        self.assertEqual(translation.name, 'translation_name_msgstr')

    def test_save_translation_returns_false_if_unchanged(self):
        self.translatable_string.save_translation('fr')
        modified = self.translatable_string.save_translation('fr')
        self.assertFalse(modified)

    def test_save_translation_returns_true_if_modified(self):
        new_translatable_string = TranslatableString(
            self.translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr_2'
        )

        self.translatable_string.save_translation('fr')
        modified = new_translatable_string.save_translation('fr')
        self.assertTrue(modified)

    def test_save_translation_creates_translation(self):
        self.translatable_string.save_translation('fr')

        translation = self.translatable.get_translation('fr')
        self.assertEqual(translation.master, self.translatable)
        self.assertEqual(translation.name, 'translation_name_msgstr')

    def test_save_translation_changes_fields_if_modified(self):
        new_translatable_string = TranslatableString(
            self.translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr_2'
        )

        self.translatable_string.save_translation('fr')
        new_translatable_string.save_translation('fr')

        translation = self.translatable.get_translation('fr')
        self.assertEqual(translation.master, self.translatable)
        self.assertEqual(translation.name, 'translation_name_msgstr_2')

    def test_save_translation_with_base_translation_raises_error(self):
        base_language = self.base_translation.language_code
        with self.assertRaises(ProtectedTranslationError):
            self.translatable_string.save_translation(base_language)