def test_entity_project_locale_order(entity_test_models): """ Return entities in correct order. """ resource0 = entity_test_models[0].entity.resource locale_a = entity_test_models[0].locale project_a = resource0.project EntityFactory.create( order=2, resource=resource0, string='Second String', ) EntityFactory.create( order=1, resource=resource0, string='First String', ) entities = Entity.map_entities( locale_a, Entity.for_project_locale( project_a, locale_a, ), ) assert entities[1]['original'] == 'First String' assert entities[2]['original'] == 'Second String'
def test_locale_parts_stats_no_page_multiple_resources(locale_parts): """ Return resource paths and stats for locales resources are available for. """ locale_c, locale_b, entityX = locale_parts project = entityX.resource.project resourceY = ResourceFactory.create( total_strings=1, project=project, path='/other/path.po', ) EntityFactory.create(resource=resourceY, string="Entity Y") TranslatedResourceFactory.create( resource=resourceY, locale=locale_c, ) TranslatedResourceFactory.create( resource=resourceY, locale=locale_b, ) # results are sorted by title detailsX = locale_c.parts_stats(project) assert ( [detail["title"] for detail in detailsX][:2] == sorted([entityX.resource.path, '/other/path.po']) ) assert detailsX[0]['unreviewed_strings'] == 0 assert detailsX[1]['unreviewed_strings'] == 0 detailsY = locale_b.parts_stats(project) assert len(detailsY) == 2 assert detailsY[0]['title'] == '/other/path.po' assert detailsY[0]['unreviewed_strings'] == 0
def test_locale_parts_stats_pages_tied_to_resources(locale_parts): """ Return subpage name and stats for locales resources are available for. """ locale_a, locale_b, entity_a = locale_parts project = entity_a.resource.project resourceX = ResourceFactory.create( project=project, path='/other/path.po', ) EntityFactory.create(resource=resourceX, string="Entity X") TranslatedResourceFactory.create( resource=resourceX, locale=locale_a, ) TranslatedResourceFactory.create( resource=resourceX, locale=locale_b, ) sub1 = SubpageFactory.create( project=project, name='Subpage', ) sub1.resources.add(resourceX) sub2 = SubpageFactory.create( project=project, name='Other Subpage', ) sub2.resources.add(resourceX) details0 = locale_a.parts_stats(project) detailsX = locale_b.parts_stats(project) assert details0[0]['title'] == 'Other Subpage' assert details0[0]['unreviewed_strings'] == 0 assert details0[1]['title'] == 'Subpage' assert details0[1]['unreviewed_strings'] == 0 assert detailsX[0]['title'] == 'Other Subpage' assert detailsX[0]['unreviewed_strings'] == 0
def test_lookup_collation(resource_a, locale_a): """ Filter translations according to collation. """ entity = EntityFactory.create(resource=resource_a, string="string",) entity_args = [ {"string": u"First string", "comment": u"random Strıng"}, {"string": u"Second strİng", "comment": u"random string"}, {"string": u"Third Strıng", "comment": u"random strİng"}, ] entities = [ EntityFactory(resource=resource_a, string=x["string"], comment=x["comment"],) for x in entity_args ] translation_args = [ u"this is string", u"this is STRİNG", u"this is Strıng", u"this is StrInG", u"this is sTriNg", ] translations = [ TranslationFactory(entity=entity, locale=locale_a, string=s,) for s in translation_args ] # Check if 'Iı' and 'İi' are appropriately distinguished and filtered # according to turkish(tr_tr) collation assert set( resource_a.entities.filter(string__icontains_collate=(u"string", "tr_tr")) ) == set([entities[n] for n in [0, 1]] + [entity]) assert set( resource_a.entities.filter(comment__icontains_collate=(u"strİng", "tr_tr")) ) == set([entities[n] for n in [1, 2]]) assert set( Translation.objects.filter(string__icontains_collate=(u"string", "tr_tr")) ) == set([translations[n] for n in [0, 1, 4]]) assert set( Translation.objects.filter(string__icontains_collate=(u"string", "tr_tr")) ) == set([translations[n] for n in [0, 1, 4]]) assert set( Translation.objects.filter(string__icontains_collate=(u"strİng", "tr_tr")) ) == set([translations[n] for n in [0, 1, 4]]) assert set( Translation.objects.filter(string__icontains_collate=(u"strıng", "tr_tr")) ) == set([translations[n] for n in [2, 3]]) # Check if differentiation fails without any collation(C) assert set( Translation.objects.filter(string__icontains_collate=(u"string", "C")) ) == set([translations[n] for n in [0, 3, 4]]) # Compare the icontains_collate query with regular i_contains query assert list(Translation.objects.filter(string__icontains=u"string")) == [ translations[n] for n in [0, 2, 3, 4] ]
def test_translation_save_latest_missing_project_locale(locale_a, project_a): """ If a translation is saved for a locale that isn't active on the project, do not fail due to a missing ProjectLocale. """ resource = ResourceFactory.create( project=project_a, path="resource.po", format="po", ) tr = TranslatedResourceFactory.create(locale=locale_a, resource=resource) entity = EntityFactory.create(resource=resource, string="Entity X") # This calls .save, this should fail if we're not properly # handling the missing ProjectLocale. translation = TranslationFactory.create( locale=locale_a, entity=entity, date=aware_datetime(1970, 1, 1), ) locale_a.refresh_from_db() project_a.refresh_from_db() tr.refresh_from_db() assert locale_a.latest_translation == translation assert project_a.latest_translation == translation assert tr.latest_translation == translation
def test_mgr_entity_filter_warnings(resource_a, locale_a): entities = [ EntityFactory.create(resource=resource_a, string="testentity%s" % i) for i in range(0, 3) ] translations = [ TranslationFactory.create( locale=locale_a, entity=entities[i], fuzzy=True, ) for i in range(0, 3) ] WarningFactory.create(translation=translations[1]) WarningFactory.create(translation=translations[2]) TranslatedResource.objects.get( resource=translations[2].entity.resource, locale=translations[2].locale, ).calculate_stats() translations[2].fuzzy = False translations[2].save() assert set(Entity.objects.filter( Entity.objects.warnings(locale_a))) == {entities[1]}
def test_translation_save_latest_update_for_system_project(locale_a, system_project_a): """ When a translation is saved for a system project, update the latest_translation attribute on the project, translatedresource and project_locale objects, but not on the locale object. """ project_locale = ProjectLocaleFactory.create( project=system_project_a, locale=locale_a, ) resource = ResourceFactory.create( project=system_project_a, path="resource.po", format="po", ) tr = TranslatedResourceFactory.create(locale=locale_a, resource=resource) entity = EntityFactory.create(resource=resource, string="Entity X") assert locale_a.latest_translation is None assert system_project_a.latest_translation is None assert tr.latest_translation is None assert project_locale.latest_translation is None translation = TranslationFactory.create( locale=locale_a, entity=entity, date=aware_datetime(1970, 1, 1), ) for i in [locale_a, system_project_a, project_locale, tr]: i.refresh_from_db() assert locale_a.latest_translation is None assert system_project_a.latest_translation == translation assert tr.latest_translation == translation assert project_locale.latest_translation == translation
def test_entity_project_locale_filter(entity_test_models, locale_b, project_b): """ Evaluate entities filtering by locale, project, obsolete. """ tr0, tr0pl, trX, subpageX = entity_test_models locale_a = tr0.locale resource0 = tr0.entity.resource project_a = tr0.entity.resource.project EntityFactory.create( obsolete=True, resource=resource0, string='Obsolete String', ) assert len(Entity.for_project_locale(project_a, locale_b)) == 0 assert len(Entity.for_project_locale(project_b, locale_a)) == 0 assert len(Entity.for_project_locale(project_a, locale_a)) == 2
def test_reset_term_translation(locale_a): """ Test if TermTranslation gets properly updated when translation in the "Terminology" project changes. """ project, _ = Project.objects.get_or_create(slug="terminology") entity = EntityFactory.create(resource=project.resources.first()) term = TermFactory.create() entity.term = term # No approved Translations of an Entity: no TermTranslation TranslationFactory.create(locale=locale_a, entity=entity) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 0 # First approved Translation of an Entity added: create TermTranslation to match the Translation translation_approved = TranslationFactory.create(locale=locale_a, entity=entity, approved=True) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 1 assert (entity.term.translations.get( locale=locale_a).text == translation_approved.string) # Another approved Translation of an Entity added: update TermTranslation to match the Translation translation_approved_2 = TranslationFactory.create(locale=locale_a, entity=entity, approved=True) entity.reset_term_translation(locale_a) assert entity.term.translations.filter(locale=locale_a).count() == 1 assert (entity.term.translations.get( locale=locale_a).text == translation_approved_2.string)
def test_mgr_entity_filter_unchanged(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string='Unchanged string', ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], active=True, approved=True, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[2], active=True, fuzzy=True, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[1], active=False, approved=True, string='Unchanged string', ) assert ( set(Entity.objects.filter( Entity.objects.unchanged(locale_a) )) == {entities[0], entities[2]} )
def test_view_tm_minimal_quality(client, locale_a, resource_a): """ View shouldn't return any entries if 70% of quality at minimum. """ entities = [ EntityFactory(resource=resource_a, string='Entity %s' % i, order=i) for i in range(5) ] for i, entity in enumerate(entities): TranslationMemoryFactory.create( entity=entity, source="source %s" % entity.string, target="target %s" % entity.string, locale=locale_a, ) response = client.get( '/translation-memory/', { 'text': 'no match', 'pk': entities[0].pk, 'locale': locale_a.code, } ) assert response.status_code == 200 assert json.loads(response.content) == []
def test_mgr_entity_filter_partially_translated_plurals(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string='Unchanged string', string_plural='Unchanged plural string', ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], plural_form=0, approved=True, ) assert ( set(resource_a.entities.filter( Entity.objects.missing(locale_a) )) == {entities[1], entities[2]} )
def test_mgr_entity_filter_unreviewed(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], string='translation for 1', ) TranslationFactory.create( locale=locale_a, entity=entities[2], string='translation for 2', ) assert ( set(Entity.objects.filter( Entity.objects.unreviewed(locale_a) )) == {entities[1], entities[2]} )
def test_view_translation_memory_best_quality_entry( client, locale_a, resource_a, ): """ Translation memory should return results entries aggregated by translation string. """ entities = [ EntityFactory(resource=resource_a, string="Entity %s" % i, order=i) for i in range(3) ] tm = TranslationMemoryFactory.create( entity=entities[0], source="aaa", target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[1], source="aaa", target="ddd", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[2], source="bbb", target="ccc", locale=locale_a, ) response = client.get( "/translation-memory/", {"text": "aaa", "pk": tm.entity.pk, "locale": locale_a.code}, ) assert json.loads(response.content) == [ {"count": 1, "source": u"aaa", "quality": u"100", "target": u"ddd"} ]
def test_mgr_entity_filter_missing(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], ) assert ( set(resource_a.entities.filter( Entity.objects.missing(locale_a) )) == {entities[1]} )
def test_mgr_entity_filter_warnings(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i ) for i in range(0, 3) ] translations = [ TranslationFactory.create( locale=locale_a, entity=entities[i], fuzzy=True, ) for i in range(0, 3) ] WarningFactory.create( translation=translations[1] ) WarningFactory.create( translation=translations[2] ) TranslatedResource.objects.get( resource=translations[2].entity.resource, locale=translations[2].locale, ).calculate_stats() translations[2].fuzzy = False translations[2].save() assert ( set(Entity.objects.filter( Entity.objects.warnings(locale_a) )) == {entities[1]} )
def test_view_translation_memory_translation_counts( client, locale_a, resource_a, ): """ Translation memory should aggregate identical translations strings from the different entities and count up their occurrences. """ entities = [ EntityFactory(resource=resource_a, string=x, order=i) for i, x in enumerate(["abaa", "abaa", "aaab", "aaab"]) ] tm = TranslationMemoryFactory.create( entity=entities[0], source=entities[0].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[1], source=entities[1].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[2], source=entities[2].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[3], source=entities[3].string, target="ccc", locale=locale_a, ) response = client.get( "/translation-memory/", {"text": "aaaa", "pk": tm.entity.pk, "locale": locale_a.code}, ) result = json.loads(response.content) assert result[0].pop("source") in ("abaa", "aaab", "aaab") assert result == [{u"count": 3, u"quality": u"75", u"target": u"ccc"}]
def test_mgr_entity_filter_errors(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i ) for i in range(0, 3) ] translations = [ TranslationFactory.create( locale=locale_a, entity=entities[i], approved=True, ) for i in range(0, 3) ] ErrorFactory.create( translation=translations[0] ) ErrorFactory.create( translation=translations[2] ) assert ( set(Entity.objects.filter( Entity.objects.errors(locale_a) )) == {entities[0], entities[2]} )
def test_mgr_entity_filter_rejected_plural(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, fuzzy=False, rejected=False, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, fuzzy=False, rejected=False, plural_form=1, ) TranslationFactory.create( locale=locale_a, entity=entities[1], approved=True, fuzzy=False, rejected=False, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[1], approved=False, fuzzy=False, rejected=True, plural_form=1, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=False, fuzzy=False, rejected=True, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=False, fuzzy=False, rejected=True, plural_form=1, ) assert (set(Entity.objects.filter( Entity.objects.rejected(locale_a))) == {entities[1], entities[2]})
def test_view_entity_inplace_mode( member, resource_a, locale_a, ): """ Inplace mode of get_entites, should return all entities in a single batch. """ TranslatedResourceFactory.create(resource=resource_a, locale=locale_a) ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a) entities = EntityFactory.create_batch(size=3, resource=resource_a) entities_pks = [e.pk for e in entities] response = member.client.post( '/get-entities/', { 'project': resource_a.project.slug, 'locale': locale_a.code, 'paths[]': [resource_a.path], 'inplace_editor': True, # Inplace mode shouldn't respect paging or limiting page 'limit': 1, }, HTTP_X_REQUESTED_WITH='XMLHttpRequest', ) assert response.status_code == 200 assert json.loads(response.content)["has_next"] is False assert ( sorted([e['pk'] for e in json.loads(response.content)['entities']]) == sorted(entities_pks) )
def test_mgr_entity_filter_rejected(resource_a, locale_a): entities = [ EntityFactory.create(resource=resource_a, string="testentity%s" % i,) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=False, fuzzy=False, rejected=True, ) TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, fuzzy=False, rejected=False, ) TranslationFactory.create( locale=locale_a, entity=entities[1], approved=True, fuzzy=False, rejected=False, ) TranslationFactory.create( locale=locale_a, entity=entities[1], approved=False, fuzzy=False, rejected=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=False, fuzzy=False, rejected=False, ) assert set(Entity.objects.filter(Entity.objects.rejected(locale_a))) == { entities[0], entities[1], }
def test_mgr_entity_filter_combined(resource_a, locale_a, user_a): """ All filters should be joined by AND instead of OR. Tests filters against bug introduced by bug 1243115. """ entities = [ EntityFactory.create(resource=resource_a, string="testentity%s" % i,) for i in range(0, 2) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, user=user_a, ) TranslationFactory.create( locale=locale_a, entity=entities[1], fuzzy=True, user=user_a, ) assert ( list( Entity.for_project_locale( resource_a.project, locale_a, status="unreviewed", author=user_a.email, ) ) == [] ) assert ( list( Entity.for_project_locale( resource_a.project, locale_a, status="unreviewed", time="201001010100-205001010100", ) ) == [] )
def test_mgr_entity_filter_unchanged(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string='Unchanged string', ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], active=True, approved=True, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[2], active=True, fuzzy=True, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[1], active=False, approved=True, string='Unchanged string', ) assert (set(Entity.objects.filter( Entity.objects.unchanged(locale_a))) == {entities[0], entities[2]})
def test_mgr_entity_filter_missing_plural(resource_a, locale_a): locale_a.cldr_plurals = "1,5" locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], fuzzy=True, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], fuzzy=True, plural_form=1, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=True, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=True, plural_form=1, ) assert set(resource_a.entities.filter(Entity.objects.missing(locale_a))) == { entities[1] }
def test_view_entity_inplace_mode( member, resource_a, locale_a, ): """ Inplace mode of get_entites, should return all entities in a single batch. """ TranslatedResourceFactory.create(resource=resource_a, locale=locale_a) ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a) entities = EntityFactory.create_batch(size=3, resource=resource_a) entities_pks = [e.pk for e in entities] response = member.client.post( "/get-entities/", { "project": resource_a.project.slug, "locale": locale_a.code, "paths[]": [resource_a.path], "inplace_editor": True, # Inplace mode shouldn't respect paging or limiting page "limit": 1, }, HTTP_X_REQUESTED_WITH="XMLHttpRequest", ) assert response.status_code == 200 assert json.loads(response.content)["has_next"] is False assert sorted([e["pk"] for e in json.loads(response.content)["entities"] ]) == sorted(entities_pks)
def test_mgr_entity_filter_errors_plural(resource_a, locale_a): locale_a.cldr_plurals = "1,5" locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] translation00 = TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, approved=True, ) translation20 = TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=0, approved=True, ) translation21 = TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=1, approved=True, ) ErrorFactory.create(translation=translation00) ErrorFactory.create(translation=translation20) ErrorFactory.create(translation=translation21) assert set(Entity.objects.filter(Entity.objects.errors(locale_a))) == {entities[2]}
def test_mgr_entity_filter_warnings_plural(resource_a, locale_a): locale_a.cldr_plurals = "1,5" locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, fuzzy=True, ) translation20 = TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=0, fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=1, fuzzy=True, ) WarningFactory.create(translation=translation20) assert set(Entity.objects.filter(Entity.objects.warnings(locale_a))) == { entities[2] }
def test_mgr_bulk_update(get_word_count_mock, resource_a, locale_a): """ Update entities method works and updates word_count field """ get_word_count_mock.return_value = 2 objs = [ EntityFactory.create( resource=resource_a, string="testentity %s" % i, ) for i in range(0, 2) ] assert get_word_count_mock.call_count == 2 testEntitiesQuerySet = Entity.for_project_locale(resource_a.project, locale_a) updated_count = testEntitiesQuerySet.bulk_update( objs, update_fields=[ "resource", "string", "string_plural", "key", "comment", "group_comment", "resource_comment", "order", "source", ], ) assert get_word_count_mock.call_count == 4 assert updated_count == len(objs)
def test_mgr_entity_filter_partially_translated_plurals(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string='Unchanged string', string_plural='Unchanged plural string', ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], plural_form=0, approved=True, ) assert (set(resource_a.entities.filter( Entity.objects.missing(locale_a))) == {entities[1], entities[2]})
def test_view_entity_inplace_mode( member, resource_a, locale_a, ): """ Inplace mode of get_entites, should return all entities in a single batch. """ TranslatedResourceFactory.create(resource=resource_a, locale=locale_a) ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a) entities = EntityFactory.create_batch(size=3, resource=resource_a) entities_pks = [e.pk for e in entities] response = member.client.post( '/get-entities/', { 'project': resource_a.project.slug, 'locale': locale_a.code, 'paths[]': [resource_a.path], 'inplace_editor': True, # Inplace mode shouldn't respect paging or limiting page 'limit': 1, }, HTTP_X_REQUESTED_WITH='XMLHttpRequest', ) assert response.status_code == 200 assert json.loads(response.content)["has_next"] is False assert (sorted([e['pk'] for e in json.loads(response.content)['entities'] ]) == sorted(entities_pks))
def test_mgr_entity_filter_unreviewed(resource_a, locale_a): entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], string='translation for 1', ) TranslationFactory.create( locale=locale_a, entity=entities[2], string='translation for 2', ) assert (set(Entity.objects.filter( Entity.objects.unreviewed(locale_a))) == {entities[1], entities[2]})
def test_get_translations(gt_mock, locale_b, resource_a, google_translate_locale): entities = [ EntityFactory(resource=resource_a, string=x, order=i) for i, x in enumerate(["abaa", "abac", "aaab", "abab"]) ] entities[1].string_plural = entities[1].string entities[3].string_plural = entities[3].string entities[1].save() entities[3].save() google_translate_locale.cldr_plurals = "1, 2" google_translate_locale.save() for entity in entities[0:2]: TranslationMemoryFactory.create( entity=entity, source=entity.string, target=entity.string, locale=locale_b, ) TranslationMemoryFactory.create( entity=entity, source=entity.string, target=entity.string, locale=google_translate_locale, ) # Mock the return value of get_google_translate_data gt_mock.return_value = { "status": True, "translation": "gt_translation", } tm_user = User.objects.get(email="*****@*****.**") gt_user = User.objects.get(email="*****@*****.**") # 100% match exists in translation memory. response_a = get_translations(entities[0], locale_b) response_b = get_translations(entities[0], google_translate_locale) assert response_a == [(entities[0].string, None, tm_user)] assert response_b == [(entities[0].string, None, tm_user)] # 100% match does not exists and locale.google_translate_code is None. response = get_translations(entities[2], locale_b) assert response == [] # 100% match does not exists and locale.google_translate_code is not None. response = get_translations(entities[2], google_translate_locale) assert response == [("gt_translation", None, gt_user)] # Entity.string_plural is not None. response_a = get_translations(entities[1], google_translate_locale) response_b = get_translations(entities[3], google_translate_locale) assert response_a == [ (entities[1].string, 0, tm_user), (entities[1].string, 1, tm_user), ] assert response_b == [ ("gt_translation", 0, gt_user), ("gt_translation", 1, gt_user), ]
def test_mgr_user_translation_counts( resource_a, locale_a, ): """Checks if translation counts are calculated properly. Tests creates 3 contributors with different numbers translations and checks if their counts match. """ contributors = UserFactory.create_batch(size=3) entities = EntityFactory.create_batch(size=36, resource=resource_a) batch_kwargs = sum( [ [dict(user=contributors[0], approved=True)] * 7, [dict(user=contributors[0], approved=False, fuzzy=False)] * 3, [dict(user=contributors[0], fuzzy=True)] * 2, [dict(user=contributors[1], approved=True)] * 5, [dict(user=contributors[1], approved=False, fuzzy=False)] * 9, [dict(user=contributors[1], fuzzy=True)] * 2, [dict(user=contributors[2], approved=True)] * 1, [dict(user=contributors[2], approved=False, fuzzy=False)] * 2, [dict(user=contributors[2], fuzzy=True)] * 5, ], [] ) for i, kwa in enumerate(batch_kwargs): kwa.update(dict(entity=entities[i])) for args in batch_kwargs: TranslationFactory.create( locale=locale_a, user=args['user'], approved=args.get('approved', False), fuzzy=args.get('fuzzy', False), ) top_contribs = get_user_model().translators.with_translation_counts() assert len(top_contribs) == 3 assert top_contribs[0] == contributors[1] assert top_contribs[1] == contributors[0] assert top_contribs[2] == contributors[2] assert top_contribs[0].translations_count == 16 assert top_contribs[0].translations_approved_count == 5 assert top_contribs[0].translations_unapproved_count == 9 assert top_contribs[0].translations_needs_work_count == 2 assert top_contribs[1].translations_count == 12 assert top_contribs[1].translations_approved_count == 7 assert top_contribs[1].translations_unapproved_count == 3 assert top_contribs[1].translations_needs_work_count == 2 assert top_contribs[2].translations_count == 8 assert top_contribs[2].translations_approved_count == 1 assert top_contribs[2].translations_unapproved_count == 2 assert top_contribs[2].translations_needs_work_count == 5
def test_view_concordance_search(client, project_a, locale_a, resource_a): entities = [ EntityFactory( resource=resource_a, string=x, order=i, ) for i, x in enumerate(["abaa", "aBaf", "aaAb", "aAab"]) ] TranslationMemoryFactory.create( entity=entities[0], source=entities[0].string, target="ccc", locale=locale_a, project=project_a, ) TranslationMemoryFactory.create( entity=entities[1], source=entities[1].string, target="cCDd", locale=locale_a, project=project_a, ) response = client.get( "/concordance-search/", { "text": "cdd", "locale": locale_a.code }, ) result = json.loads(response.content) assert result == { "results": [{ "source": "aBaf", "target": "cCDd", "project_names": [project_a.name] }], "has_next": False, } response = client.get( "/concordance-search/", { "text": "abaa", "locale": locale_a.code }, ) result = json.loads(response.content) assert result == { "results": [{ "source": "abaa", "target": "ccc", "project_names": [project_a.name] }], "has_next": False, }
def test_pretranslate(gt_mock, project_a, locale_a, resource_a, locale_b): project_a.pretranslation_enabled = True project_a.save() resources = [ ResourceFactory(project=project_a, path=x, format="po") for x in ["resource_x.po", "resource_y.po"] ] for i, x in enumerate(["abaa", "abac"]): EntityFactory.create(resource=resources[0], string=x, order=i) for i, x in enumerate(["aaab", "abab"]): EntityFactory.create(resource=resources[1], string=x, order=i) TranslatedResourceFactory.create(resource=resources[0], locale=locale_a) TranslatedResourceFactory.create(resource=resources[0], locale=locale_b) TranslatedResourceFactory.create(resource=resources[1], locale=locale_a) ProjectLocaleFactory.create( project=project_a, locale=locale_a, pretranslation_enabled=True, ) ProjectLocaleFactory.create( project=project_a, locale=locale_b, pretranslation_enabled=True, ) tm_user = User.objects.get(email="*****@*****.**") gt_mock.return_value = [("pretranslation", None, tm_user)] pretranslate(project_a.pk) project_a.refresh_from_db() translations = Translation.objects.filter(user=tm_user) # Total pretranslations = 2(tr_ax) + 2(tr_bx) + 2(tr_ay) assert len(translations) == 6 # pretranslated count == total pretranslations. assert project_a.pretranslated_strings == 6 # latest_translation belongs to pretranslations. assert project_a.latest_translation in translations
def test_view_tm_translation_counts( client, locale_a, resource_a, ): """ Translation memory should aggregate identical translations strings from the different entities and count up their occurrences. """ entities = [ EntityFactory(resource=resource_a, string=x, order=i) for i, x in enumerate(["abaa", "abaa", "aaab", "aaab"]) ] tm = TranslationMemoryFactory.create( entity=entities[0], source=entities[0].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[1], source=entities[1].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[2], source=entities[2].string, target="ccc", locale=locale_a, ) TranslationMemoryFactory.create( entity=entities[3], source=entities[3].string, target="ccc", locale=locale_a, ) response = client.get( '/translation-memory/', { 'text': 'aaaa', 'pk': tm.entity.pk, 'locale': locale_a.code, } ) result = json.loads(response.content) assert result[0].pop('source') in ('abaa', 'aaab', 'aaab') assert ( result == [{ u'count': 3, u'quality': 75.0, u'target': u'ccc' }] )
def test_view_entity_exclude_entities( member, resource_a, locale_a, ): """ Excluded entities shouldn't be returned by get_entities. """ TranslatedResource.objects.create(resource=resource_a, locale=locale_a) ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a) entities = EntityFactory.create_batch(size=3, resource=resource_a) excluded_pk = entities[1].pk response = member.client.post( '/get-entities/', { 'project': resource_a.project.slug, 'locale': locale_a.code, 'paths[]': [resource_a.path], 'exclude_entities': [excluded_pk], 'limit': 1, }, HTTP_X_REQUESTED_WITH='XMLHttpRequest', ) assert response.status_code == 200 assert json.loads(response.content)["has_next"] is True assert ( [e['pk'] for e in json.loads(response.content)['entities']] != [excluded_pk] ) exclude_entities = ','.join(map( str, [ entities[2].pk, entities[1].pk, ] )) response = member.client.post( '/get-entities/', { 'project': resource_a.project.slug, 'locale': locale_a.code, 'paths[]': [resource_a.path], 'exclude_entities': exclude_entities, 'limit': 1, }, HTTP_X_REQUESTED_WITH='XMLHttpRequest', ) assert response.status_code == 200 assert json.loads(response.content)["has_next"] is False assert ( [e['pk'] for e in json.loads(response.content)['entities']] == [entities[0].pk] )
def locale_parts(project_b, locale_c, locale_b): ProjectLocaleFactory.create(project=project_b, locale=locale_c) ProjectLocaleFactory.create(project=project_b, locale=locale_b) resourceX = ResourceFactory.create( project=project_b, path="resourceX.po", format="po", ) entityX = EntityFactory.create(resource=resourceX, string="entityX") resourceX.total_strings = 1 resourceX.save() TranslatedResourceFactory.create(locale=locale_c, resource=resourceX) return locale_c, locale_b, entityX
def test_mgr_entity_filter_errors_plural(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] translation00 = TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, approved=True, ) translation20 = TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=0, approved=True, ) translation21 = TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=1, approved=True, ) ErrorFactory.create( translation=translation00 ) ErrorFactory.create( translation=translation20 ) ErrorFactory.create( translation=translation21 ) assert ( set(Entity.objects.filter( Entity.objects.errors(locale_a) )) == {entities[2]} )
def test_mgr_entity_filter_fuzzy_plurals(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=0, fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[0], plural_form=1, fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[1], plural_form=0, fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=0, fuzzy=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], plural_form=1, fuzzy=True, ) assert ( set(Entity.objects.filter( Entity.objects.fuzzy(locale_a) )) == {entities[0], entities[2]} )
def test_mgr_entity_filter_unreviewed_plural(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, string_plural="testpluralentity%s" % i, ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=False, fuzzy=False, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[0], approved=False, fuzzy=False, plural_form=1, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=False, fuzzy=False, plural_form=0, ) TranslationFactory.create( locale=locale_a, entity=entities[2], approved=False, fuzzy=False, plural_form=1, ) assert ( set(Entity.objects.filter( Entity.objects.unreviewed(locale_a) )) == {entities[0], entities[2]} )
def test_project_needs_sync(project_a, project_b, locale_a): """ Project.needs_sync should be True if ChangedEntityLocale objects exist for its entities or if Project has unsynced locales. """ resource = ResourceFactory.create(project=project_a, path="resourceX.po") entity = EntityFactory.create(resource=resource, string="entityX") assert not project_a.needs_sync ChangedEntityLocaleFactory.create(entity=entity, locale=locale_a) assert project_a.needs_sync assert not project_b.needs_sync assert project_b.unsynced_locales == [] del project_b.unsynced_locales ProjectLocaleFactory.create( project=project_b, locale=locale_a, ) assert project_b.needs_sync == [locale_a]
def test_translation_unapproved_not_in_tm(locale_a, project_a): """ Unapproved translation shouldn't be in the translation memory. """ resource = ResourceFactory.create( project=project_a, path="resource.po", format="po", ) entity = EntityFactory.create(resource=resource, string="Entity X") translation = TranslationFactory.create( locale=locale_a, entity=entity, ) with pytest.raises(TranslationMemoryEntry.DoesNotExist): TranslationMemoryEntry.objects.get( source=translation.entity.string, target=translation.string, locale=translation.locale, )
def test_mgr_user_contributors_limit( resource_a, locale_a, ): """ Checks if proper count of user is returned. """ contributors = UserFactory.create_batch(size=102) entities = EntityFactory.create_batch( size=102, resource=resource_a, ) for i, contrib in enumerate(contributors): TranslationFactory.create( locale=locale_a, approved=True, user=contrib, entity=entities[i], ) top_contributors = get_user_model().translators.with_translation_counts() assert len(top_contributors) == 100
def test_translation_approved_in_tm(locale_a, project_a): """ Every save of approved translation should generate a new entry in the translation memory. """ resource = ResourceFactory.create( project=project_a, path="resource.po", format="po", ) entity = EntityFactory.create(resource=resource, string="Entity X") translation = TranslationFactory.create( locale=locale_a, entity=entity, approved=True, ) assert TranslationMemoryEntry.objects.get( source=translation.entity.string, target=translation.string, locale=translation.locale, )
def test_mgr_entity_filter_combined(resource_a, locale_a, user_a): """ All filters should be joined by AND instead of OR. Tests filters against bug introduced by bug 1243115. """ entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, ) for i in range(0, 2) ] TranslationFactory.create( locale=locale_a, entity=entities[0], approved=True, user=user_a, ) TranslationFactory.create( locale=locale_a, entity=entities[1], fuzzy=True, user=user_a, ) assert ( list(Entity.for_project_locale( resource_a.project, locale_a, status='unreviewed', author=user_a.email, )) == [] ) assert ( list(Entity.for_project_locale( resource_a.project, locale_a, status='unreviewed', time='201001010100-205001010100', )) == [] )
def test_translation_rejected_not_in_tm(locale_a, project_a): """ When translation is deleted, its corresponding TranslationMemoryEntry needs to be deleted, too. """ resource = ResourceFactory.create( project=project_a, path="resource.po", format="po", ) entity = EntityFactory.create(resource=resource, string="Entity X") translation = TranslationFactory.create( locale=locale_a, entity=entity, rejected=True, ) with pytest.raises(TranslationMemoryEntry.DoesNotExist): TranslationMemoryEntry.objects.get( source=translation.entity.string, target=translation.string, locale=translation.locale, )
def test_mgr_user_contributors_order( resource_b, locale_a, ): """ Checks if users are ordered by count of contributions. """ contributors = UserFactory.create_batch(size=5) entities = EntityFactory.create_batch(size=22, resource=resource_b) # create a list of contributors/entity for translations for i, count in enumerate([2, 4, 9, 1, 6]): for j in range(count): TranslationFactory.create( locale=locale_a, user=contributors[i], entity=entities[i], ) # Ordered by approved count assert ( list(get_user_model().translators.with_translation_counts()) == [contributors[i] for i in [2, 4, 1, 0, 3]] )
def test_mgr_user_query_args_filtering( locale_a, resource_a, locale_b, ): """ Tests if query args are honored properly and contributors are filtered. """ contributors = UserFactory.create_batch(size=3) entities = EntityFactory.create_batch(size=53, resource=resource_a) batch_kwargs = sum( [ [dict( user=contributors[0], locale=locale_a, approved=True )] * 12, [dict( user=contributors[0], locale=locale_a, approved=False, fuzzy=False )] * 1, [dict( user=contributors[0], locale=locale_a, fuzzy=True )] * 2, [dict( user=contributors[1], locale=locale_b, approved=True )] * 11, [dict( user=contributors[1], locale=locale_b, approved=False, fuzzy=False )] * 1, [dict( user=contributors[1], locale=locale_b, fuzzy=True )] * 2, [dict( user=contributors[2], locale=locale_a, approved=True )] * 10, [dict( user=contributors[2], locale=locale_a, approved=False, fuzzy=False )] * 12, [dict( user=contributors[2], locale=locale_a, fuzzy=True )] * 2 ], [], ) for i, kwa in enumerate(batch_kwargs): kwa.update(dict(entity=entities[i])) for args in batch_kwargs: TranslationFactory.create( locale=args['locale'], user=args['user'], approved=args.get('approved', False), fuzzy=args.get('fuzzy', False), ) top_contribs = get_user_model().translators.with_translation_counts( aware_datetime(2015, 1, 1), Q(locale=locale_a), ) assert len(top_contribs) == 2 assert top_contribs[0] == contributors[2] assert top_contribs[0].translations_count == 24 assert top_contribs[0].translations_approved_count == 10 assert top_contribs[0].translations_unapproved_count == 12 assert top_contribs[0].translations_needs_work_count == 2 assert top_contribs[1] == contributors[0] assert top_contribs[1].translations_count == 15 assert top_contribs[1].translations_approved_count == 12 assert top_contribs[1].translations_unapproved_count == 1 assert top_contribs[1].translations_needs_work_count == 2 top_contribs = get_user_model().translators.with_translation_counts( aware_datetime(2015, 1, 1), Q(locale=locale_b), ) assert len(top_contribs) == 1 assert top_contribs[0] == contributors[1] assert top_contribs[0].translations_count == 14 assert top_contribs[0].translations_approved_count == 11 assert top_contribs[0].translations_unapproved_count == 1 assert top_contribs[0].translations_needs_work_count == 2
def test_mgr_user_period_filters( locale_a, resource_a, ): """Total counts should be filtered by given date. Test creates 2 contributors with different activity periods and checks if they are filtered properly. """ contributors = UserFactory.create_batch(size=2) entities = EntityFactory.create_batch(size=35, resource=resource_a) batch_kwargs = sum( [ [dict( user=contributors[0], date=aware_datetime(2015, 3, 2), approved=True, )] * 12, [dict( user=contributors[0], date=aware_datetime(2015, 7, 2), approved=True, )] * 5, [dict( user=contributors[0], date=aware_datetime(2015, 3, 2), approved=False, fuzzy=False, )] * 1, [dict( user=contributors[0], date=aware_datetime(2015, 3, 2), fuzzy=True, )] * 2, [dict( user=contributors[1], date=aware_datetime(2015, 6, 1), approved=True, )] * 2, [dict( user=contributors[1], date=aware_datetime(2015, 6, 1), approved=False, fuzzy=False, )] * 11, [dict( user=contributors[1], date=aware_datetime(2015, 6, 1), fuzzy=True, )] * 2 ], [], ) for i, kwa in enumerate(batch_kwargs): kwa.update(dict(entity=entities[i])) for args in batch_kwargs: TranslationFactory.create( locale=locale_a, user=args['user'], date=args['date'], approved=args.get('approved', False), fuzzy=args.get('fuzzy', False), ) top_contribs = get_user_model().translators.with_translation_counts( aware_datetime(2015, 6, 10) ) assert len(top_contribs) == 1 assert top_contribs[0].translations_count == 5 assert top_contribs[0].translations_approved_count == 5 assert top_contribs[0].translations_unapproved_count == 0 assert top_contribs[0].translations_needs_work_count == 0 top_contribs = get_user_model().translators.with_translation_counts( aware_datetime(2015, 5, 10) ) assert len(top_contribs) == 2 assert top_contribs[0].translations_count == 15 assert top_contribs[0].translations_approved_count == 2 assert top_contribs[0].translations_unapproved_count == 11 assert top_contribs[0].translations_needs_work_count == 2 assert top_contribs[1].translations_count == 5 assert top_contribs[1].translations_approved_count == 5 assert top_contribs[1].translations_unapproved_count == 0 assert top_contribs[1].translations_needs_work_count == 0 top_contribs = get_user_model().translators.with_translation_counts( aware_datetime(2015, 1, 10) ) assert len(top_contribs) == 2 assert top_contribs[0].translations_count == 20 assert top_contribs[0].translations_approved_count == 17 assert top_contribs[0].translations_unapproved_count == 1 assert top_contribs[0].translations_needs_work_count == 2 assert top_contribs[1].translations_count == 15 assert top_contribs[1].translations_approved_count == 2 assert top_contribs[1].translations_unapproved_count == 11 assert top_contribs[1].translations_needs_work_count == 2
def test_mgr_entity_reset_active_translations(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string="testentity%s" % i, ) for i in range(0, 4) ] + [ EntityFactory( resource=resource_a, string='testentity4', string_plural='testentity4plural', ) ] entities_qs = Entity.objects.filter(pk__in=[e.pk for e in entities]) # Translations for Entity 0: # No translations pass # Translations for Entity 1: # 2 unreviewed translations TranslationFactory.create( locale=locale_a, entity=entities[1], string=entities[1].string + ' translation1', ) TranslationFactory.create( locale=locale_a, entity=entities[1], string=entities[1].string + ' translation2', ) # Translations for Entity 2: # Approved and unreviewed translation TranslationFactory.create( locale=locale_a, entity=entities[2], string=entities[2].string + ' translation1', approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[2], string=entities[2].string + ' translation2', ) # Translations for Entity 3: # Fuzzy and unreviewed translation TranslationFactory.create( locale=locale_a, entity=entities[3], string=entities[3].string + ' translation1', ) TranslationFactory.create( locale=locale_a, entity=entities[3], string=entities[3].string + ' translation2', fuzzy=True, ) # Translations for Entity 4 - pluralized: # Approved and unreviewed translation for first form, # a single unreviewed translation for second form TranslationFactory.create( locale=locale_a, entity=entities[4], plural_form=0, string=entities[4].string + ' translation1', approved=True, ) TranslationFactory.create( locale=locale_a, entity=entities[4], plural_form=0, string=entities[4].string + ' translation2', ) TranslationFactory.create( locale=locale_a, entity=entities[4], plural_form=1, string=entities[4].string_plural + ' translation1plural', ) entities_qs.reset_active_translations(locale=locale_a) # Active translations for Entity 0: # no active translations assert entities[0].translation_set.filter(active=True).count() == 0 # Active translations for Entity 1: # latest translation is active assert ( entities[1].translation_set.get(active=True).string == entities[1].string + ' translation2' ) # Active translations for Entity 2: # approved translation is active assert ( entities[2].translation_set.get(active=True).string == entities[2].string + ' translation1' ) # Active translations for Entity 3: # fuzzy translation is active assert ( entities[3].translation_set.get(active=True).string == entities[3].string + ' translation2' ) # Active translations for Entity 4 - pluralized: # Approved translation for first form, # a single unreviewed translation for second form active = entities[4].translation_set.filter(active=True) assert active[0].string == entities[4].string + ' translation1' assert active[1].string == entities[4].string_plural + ' translation1plural'
def test_lookup_collation(resource_a, locale_a): """ Filter translations according to collation. """ entity = EntityFactory.create( resource=resource_a, string="string", ) entity_args = [ { 'string': u'First string', 'comment': u'random Strıng', }, { 'string': u'Second strİng', 'comment': u'random string', }, { 'string': u'Third Strıng', 'comment': u'random strİng', }, ] entities = [ EntityFactory( resource=resource_a, string=x['string'], comment=x['comment'], ) for x in entity_args ] translation_args = [ u'this is string', u'this is STRİNG', u'this is Strıng', u'this is StrInG', u'this is sTriNg' ] translations = [ TranslationFactory( entity=entity, locale=locale_a, string=s, ) for s in translation_args ] # Check if 'Iı' and 'İi' are appropriately distinguished and filtered # according to turkish(tr_tr) collation assert ( set(resource_a.entities.filter( string__icontains_collate=(u'string', 'tr_tr') )) == set([entities[n] for n in [0, 1]] + [entity]) ) assert ( set(resource_a.entities.filter( comment__icontains_collate=(u'strİng', 'tr_tr') )) == set([entities[n] for n in [1, 2]]) ) assert ( set(Translation.objects.filter( string__icontains_collate=(u'string', 'tr_tr') )) == set([translations[n] for n in [0, 1, 4]]) ) assert ( set(Translation.objects.filter( string__icontains_collate=(u'string', 'tr_tr') )) == set([translations[n] for n in [0, 1, 4]]) ) assert ( set(Translation.objects.filter( string__icontains_collate=(u'strİng', 'tr_tr') )) == set([translations[n] for n in [0, 1, 4]]) ) assert ( set(Translation.objects.filter( string__icontains_collate=(u'strıng', 'tr_tr') )) == set([translations[n] for n in [2, 3]]) ) # Check if differentiation fails without any collation(C) assert ( set(Translation.objects.filter( string__icontains_collate=(u'string', 'C') )) == set([translations[n] for n in [0, 3, 4]]) ) # Compare the icontains_collate query with regular i_contains query assert ( list(Translation.objects.filter( string__icontains=u'string' )) == [translations[n] for n in [0, 2, 3, 4]] )
def test_mgr_entity_filter_unchanged_plural(resource_a, locale_a): locale_a.cldr_plurals = '1,5' locale_a.save() entities = [ EntityFactory.create( resource=resource_a, string='Unchanged string', string_plural='Unchanged plural string', ) for i in range(0, 3) ] TranslationFactory.create( locale=locale_a, entity=entities[0], active=True, approved=True, plural_form=0, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[0], active=True, approved=True, plural_form=1, string='Unchanged plural string', ) TranslationFactory.create( locale=locale_a, entity=entities[1], active=False, fuzzy=True, plural_form=0, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[1], active=False, fuzzy=True, plural_form=1, string='Unchanged plural string', ) TranslationFactory.create( locale=locale_a, entity=entities[2], active=True, fuzzy=True, plural_form=0, string='Unchanged string', ) TranslationFactory.create( locale=locale_a, entity=entities[2], active=True, fuzzy=True, plural_form=1, string='Unchanged plural string', ) assert ( set(Entity.objects.filter( Entity.objects.unchanged(locale_a) )) == {entities[0], entities[2]} )