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 test_can_get_entities(self): OrganizationBuilder().with_id('First').create() OrganizationBuilder().with_id('Second').create() url = '/v1/organizations/' response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.json()), 2)
def setUp(self): self.first_organization = OrganizationBuilder().create() self.second_organization = OrganizationBuilder().create() self.first_location = LocationBuilder(self.first_organization).create() self.second_location = LocationBuilder(self.first_organization).create() self.first_service = ServiceBuilder(self.first_organization).create() self.second_service = ServiceBuilder(self.second_organization).create() add_service_to_location(self.first_service, self.first_location) add_service_to_location(self.second_service, self.second_location)
def test_empty_website_is_saved_as_none(self): empty_website = '' no_website = None organization = OrganizationBuilder().with_website( empty_website).build() organization_from_db = validate_save_and_reload(organization) self.assertEqual(organization_from_db.website, no_website)
def test_returns_services_ordered_by_score(self): task_id = a_string() task = Task(id=task_id, name=a_string(), description=a_string()) task.save() organization = OrganizationBuilder().create() more_related_service = ServiceBuilder(organization).create() less_related_service = ServiceBuilder(organization).create() higher_score = 0.9 lower_score = 0.1 TaskServiceSimilarityScore(task=task, service=more_related_service, similarity_score=higher_score).save() TaskServiceSimilarityScore(task=task, service=less_related_service, similarity_score=lower_score).save() url = '/v1/tasks/{}/related_services/'.format(task_id) response = self.client.get(url) self.assertEqual(response.json()[0]['service_id'], more_related_service.id) self.assertEqual(response.json()[1]['service_id'], less_related_service.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_cannot_delete(self): organization = OrganizationBuilder().build() organization.save() url = '/v1/organizations/{0}/'.format(organization.pk) response = self.client.delete(url) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
def create_many(self, count=3): organization = OrganizationBuilder().create() return ([ ServiceAtLocation.objects.create( location=LocationBuilder(organization).create(), service=ServiceBuilder(organization).create()) for _ in range(0, count) ])
def setUp(self): self.organization = OrganizationBuilder().create() self.three_task_ids = [a_string() for i in range(3)] create_tasks(self.three_task_ids) services = [ ServiceBuilder(self.organization).create() for i in range(3) ] self.three_service_ids = [service.id for service in services]
def setUp(self): self.organization = OrganizationBuilder().build() self.organization.save() self.service = ServiceBuilder(self.organization).build() self.service.save() self.location = LocationBuilder(self.organization).build() self.location.save()
def test_can_get_one_entity(self): organization = OrganizationBuilder().with_description( 'Organization description').build() organization.save() url = '/v1/organizations/{0}/'.format(organization.pk) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.json()['description'], 'Organization description')
def test_description_is_multilingual(self): organization = OrganizationBuilder().build() set_description_in_language(organization, 'en', 'In English') set_description_in_language(organization, 'fr', 'En français') organization_from_db = validate_save_and_reload(organization) self.assert_description_in_language_equals(organization_from_db, 'en', 'In English') self.assert_description_in_language_equals(organization_from_db, 'fr', 'En français')
def setUp(self): self.organization_id = 'the_organization_id' self.organization = OrganizationBuilder().with_id( self.organization_id).build() self.organization.save() self.data = { 'id': 'the_location_id', 'name': 'the name', 'organization_id': self.organization_id, 'description': 'the description' }
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])
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 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])
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_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_can_create_row(self): organization = OrganizationBuilder().create() service = ServiceBuilder(organization).create() task_id = a_string() score = a_float() create_tasks([task_id]) score_record = TaskServiceSimilarityScore(task_id=task_id, service=service, similarity_score=score) score_record_from_db = validate_save_and_reload(score_record) self.assertEqual(score_record_from_db.task_id, task_id) self.assertEqual(score_record_from_db.service_id, service.id) self.assertAlmostEqual(score_record_from_db.similarity_score, score)
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 setUp(self): translation.activate('en') self.task_id = a_string() self.task = Task(id=self.task_id, name=a_string(), description=a_string()) self.task.save() organization = OrganizationBuilder().create() self.service = ServiceBuilder(organization).create() self.similarity_score = a_float() TaskServiceSimilarityScore( task=self.task, service=self.service, similarity_score=self.similarity_score).save()
def setUp(self): self.task_id = a_string() self.english_task_title = a_string() self.english_task_description = a_string() self.data = { 'taskMap': { self.task_id: { 'completed': False, 'id': self.task_id, 'title': { 'en': self.english_task_title, }, 'description': { 'en': self.english_task_description } } } } self.organization = OrganizationBuilder().create()
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')
def setUp(self): self.organization = OrganizationBuilder().build() self.organization.save()
def setUp(self): self.organization = OrganizationBuilder().create() self.service = ServiceBuilder(self.organization).create() self.location = LocationBuilder(self.organization).create()
def setUp(self): self.organization = OrganizationBuilder().create()
def test_create_with_different_msgid_from_base_translation_raises_error(self): translatable = OrganizationBuilder().with_id('test_create_with_different_msgid_from_base_translation_raises_error_id').with_name('translated_name_msgid').build() with self.assertRaises(InvalidMsgidError): TranslatableString(translatable, 'name', 'not_translation_name_msgid', 'translation_name_msgstr')
def test_create_without_msgid_raises_error(self): translatable = OrganizationBuilder().with_id('test_create_without_msgid_raises_error_id').with_name('').build() with self.assertRaises(MissingMsgidError): TranslatableString(translatable, 'name', '', 'translation_name_msgstr')
def test_create_with_invalid_field_raises_error(self): translatable = OrganizationBuilder().build() with self.assertRaises(FieldNotTranslatableError): TranslatableString(translatable, 'not_a_field', 'translation_name_msgid', 'translation_name_msgstr')