def test_create_with_translatable_model(self): translatable = OrganizationBuilder().with_id('test_create_with_translatable_model_id').build() add_base_translation( translatable, name='translation_name_msgid' ) translatable_string = TranslatableString(translatable, 'name', 'translation_name_msgid', 'translation_name_msgstr') 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') self.assertEqual(str(translatable_string), 'organizations.organization@name@test_create_with_translatable_model_id')
def test_all_from_po_entry(self): translatable = OrganizationBuilder().with_id('test_all_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_all_from_po_entry_id', None) ] po_entry.msgid = 'translation_name_msgid' po_entry.msgstr = 'translation_name_msgstr' with patch.object(TranslatableString, 'from_po_entry') as from_po_entry: errors_list = [] results_iter = TranslatableString.all_from_po_entry(po_entry, errors_out=errors_list) results_list = [n for n in results_iter] self.assertEqual(from_po_entry.call_count, 1) from_po_entry.assert_has_calls([ call(po_entry, po_entry.occurrences[0]) ]) self.assertEqual(len(errors_list), 0) self.assertEqual(len(results_list), 1)
def test_create_from_translation_with_missing_msgid_raises_error(self): translatable = OrganizationBuilder().with_id('test_create_from_translation_with_missing_msgid_raises_error_id').build() base_translation = add_base_translation( translatable, name='' ) translation = add_translation( translatable, 'fr', name='translation_name_msgstr' ) with self.assertRaises(MissingMsgidError): TranslatableString.from_translation(translation, 'name')
def setUp(self): organization_1 = OrganizationBuilder().with_id('one').build() add_base_translation(organization_1, name='organization_one_translation_name_msgid', description='') add_translation(organization_1, 'fr', name='organization_one_translation_name_msgstr_fr') organization_2 = OrganizationBuilder().with_id('two').build() add_base_translation( organization_2, name='', description='organization_two_translation_description_msgid') add_translation( organization_2, 'fr', description='organization_two_translation_description_msgstr_fr') organization_3 = OrganizationBuilder().with_id('three').build() add_base_translation( organization_3, name='organization_three_translation_name_msgid', description='organization_three_translation_description_msgid') self.translatable_objects = [ organization_1, organization_2, organization_3 ] self.out_dir = TemporaryDirectory()
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_create_from_translation(self): translatable = OrganizationBuilder().with_id('test_create_from_translation_id').build() base_translation = add_base_translation( translatable, name='translation_name_msgid' ) translation = add_translation( translatable, 'fr', name='translation_name_msgstr' ) translatable_string = TranslatableString.from_translation(translation, 'name') 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')
def test_all_from_translation(self): translatable = OrganizationBuilder().with_id('test_all_from_translation_id').build() base_translation = add_base_translation( translatable, name='translation_name_msgid', description='translation_description_msgid' ) translation = add_translation( translatable, 'fr', name='translation_name_msgstr' ) with patch.object(TranslatableString, 'from_translation') as from_translation: errors_list = [] results_iter = TranslatableString.all_from_translation(translation, errors_out=errors_list) results_list = [n for n in results_iter] self.assertEqual(from_translation.call_count, 2) from_translation.assert_has_calls([ call(translation, 'name'), call(translation, 'description') ]) self.assertEqual(len(errors_list), 0) self.assertEqual(len(results_list), 2)
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')