コード例 #1
0
ファイル: test_locale.py プロジェクト: desmosinc/pontoon
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
コード例 #2
0
ファイル: test_locale.py プロジェクト: Pike/pontoon
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
コード例 #3
0
ファイル: test_locale.py プロジェクト: Pike/pontoon
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_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))
コード例 #5
0
def test_view_translate_not_authed_public_project(
    client,
    locale_a,
    settings_debug,
):
    """
    If the user is not authenticated and we're translating project
    ID 1, return a 200.
    """
    project = ProjectFactory.create(slug='valid-project')
    ProjectLocaleFactory.create(
        project=project,
        locale=locale_a,
    )
    resource = ResourceFactory.create(
        project=project,
        path='foo.lang',
        total_strings=1,
    )
    TranslatedResourceFactory.create(
        resource=resource,
        locale=locale_a,
    )
    response = client.get('/%s/%s/%s/' %
                          (locale_a.code, project.slug, resource.path))
    assert response.status_code == 200
コード例 #6
0
ファイル: test_translation.py プロジェクト: mathjazz/pontoon
def test_view_translate_not_authed_public_project(
    client,
    locale_a,
    settings_debug,
):
    """
    If the user is not authenticated and we're translating project
    ID 1, return a 200.
    """
    project = ProjectFactory.create(slug='valid-project')
    ProjectLocaleFactory.create(
        project=project, locale=locale_a,
    )
    resource = ResourceFactory.create(
        project=project,
        path='foo.lang',
        total_strings=1,
    )
    TranslatedResourceFactory.create(
        resource=resource, locale=locale_a,
    )
    response = client.get(
        '/%s/%s/%s/'
        % (locale_a.code, project.slug, resource.path)
    )
    assert response.status_code == 200
コード例 #7
0
ファイル: test_locale.py プロジェクト: desmosinc/pontoon
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
コード例 #8
0
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)
コード例 #9
0
ファイル: test_entity.py プロジェクト: Pike/pontoon
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)
    )
コード例 #10
0
ファイル: conftest.py プロジェクト: Pike/pontoon
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
コード例 #11
0
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
コード例 #12
0
ファイル: test_translation.py プロジェクト: Pike/pontoon
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
コード例 #13
0
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
コード例 #14
0
def test_translation_save_latest_update_approved_translation(
        locale_a, project_a, project_locale_a, resource_a, entity_a):
    """
    When a translation is approved, update the latest_translation
    attribute on the related project, locale, translatedresource,
    and project_locale objects if it was approved later than the last
    translation was saved before.
    """
    tr = TranslatedResourceFactory.create(locale=locale_a, resource=resource_a)

    translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity_a,
        date=aware_datetime(1970, 2, 1),
        approved_date=aware_datetime(1970, 2, 1),
    )
    for i in [locale_a, project_a, project_locale_a, tr]:
        i.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
    assert project_locale_a.latest_translation == translation

    later_approved_translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity_a,
        date=aware_datetime(1970, 1, 1),
        approved_date=aware_datetime(1970, 3, 1),
    )
    for i in [locale_a, project_a, project_locale_a, tr]:
        i.refresh_from_db()
    assert locale_a.latest_translation == later_approved_translation
    assert project_a.latest_translation == later_approved_translation
    assert tr.latest_translation == later_approved_translation
    assert project_locale_a.latest_translation == later_approved_translation
コード例 #15
0
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
コード例 #16
0
def test_translation_save_latest_update_older_translation(
    locale_a, project_a, project_locale_a, resource_a, entity_a
):
    """
    When an older translation is saved, do not update the latest_translation
    attribute on the related project, locale, translatedresource,
    and project_locale objects.
    """
    tr = TranslatedResourceFactory.create(locale=locale_a, resource=resource_a)

    translation = TranslationFactory.create(
        locale=locale_a, entity=entity_a, date=aware_datetime(1970, 2, 1),
    )
    for i in [locale_a, project_a, project_locale_a, tr]:
        i.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
    assert project_locale_a.latest_translation == translation

    # older translation
    TranslationFactory.create(
        locale=locale_a, entity=entity_a, date=aware_datetime(1970, 1, 1),
    )
    for i in [locale_a, project_a, project_locale_a, tr]:
        i.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
    assert project_locale_a.latest_translation == translation
コード例 #17
0
def test_translation_save_latest_missing_project_locale(
    locale_a, project_a, resource_a, entity_a
):
    """
    If a translation is saved for a locale that isn't active on the
    project, do not fail due to a missing ProjectLocale.
    """
    tr = TranslatedResourceFactory.create(locale=locale_a, resource=resource_a)

    # This calls .save, this should fail if we're not properly
    # handling the missing ProjectLocale.
    translation = TranslationFactory.create(
        locale=locale_a, entity=entity_a, date=aware_datetime(1970, 1, 1),
    )

    for i in [locale_a, project_a, tr]:
        i.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
コード例 #18
0
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
コード例 #19
0
ファイル: test_translation.py プロジェクト: Pike/pontoon
def test_translation_save_latest_update(locale_a, project_a):
    """
    When a translation is saved, update the latest_translation
    attribute on the related project, locale, translatedresource,
    and project_locale objects.
    """
    project_locale = ProjectLocaleFactory.create(
        project=project_a, locale=locale_a,
    )
    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")

    assert locale_a.latest_translation is None
    assert 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),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
    assert project_locale.latest_translation == translation

    # Ensure translation is replaced for newer translations
    newer_translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        date=aware_datetime(1970, 2, 1),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_translation
    assert project_a.latest_translation == newer_translation
    assert tr.latest_translation == newer_translation
    assert project_locale.latest_translation == newer_translation

    # Ensure translation isn't replaced for older translations.
    TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        date=aware_datetime(1970, 1, 5),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_translation
    assert project_a.latest_translation == newer_translation
    assert tr.latest_translation == newer_translation
    assert project_locale.latest_translation == newer_translation

    # Ensure approved_date is taken into consideration as well.
    newer_approved_translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        approved_date=aware_datetime(1970, 3, 1),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_approved_translation
    assert project_a.latest_translation == newer_approved_translation
    assert tr.latest_translation == newer_approved_translation
    assert project_locale.latest_translation == newer_approved_translation
コード例 #20
0
ファイル: test_entity.py プロジェクト: Pike/pontoon
def entity_test_search(resource_a, locale_a):
    """This fixture provides:

    - 7 translated entities
    - A lambda for searching for entities using Entity.for_project_locale
    """
    TranslatedResourceFactory.create(
        locale=locale_a,
        resource=resource_a,
    )

    entity_args = [
        {
            'string': 'First entity string',
            'string_plural': 'First plural string',
            'comment': 'random notes',
        }, {
            'string': 'Second entity string',
            'string_plural': 'Second plural string',
            'comment': 'random',
        }, {
            'string': u'Third entity string with some twist: ZAŻÓŁĆ GĘŚLĄ',
            'string_plural': 'Third plural',
            'comment': 'even more random notes',
        }, {
            'string': 'Entity with first string',
            'string_plural': 'Entity with plural first string',
            'comment': 'random notes',
        }, {
            'string': 'First Entity',
            'string_plural': 'First plural entity',
            'comment': 'random notes',
        }, {
            'string': 'First Entity with string',
            'string_plural': 'First plural entity',
            'comment': 'random notes',
        }, {
            'string': 'Entity with quoted "string"',
            'string_plural': 'plural entity',
            'comment': 'random notes',
        },
    ]
    entities = [
        EntityFactory(
            resource=resource_a,
            string=x['string'],
            string_plural=x['string_plural'],
            comment=x['comment'],
            order=i,
        ) for i, x in enumerate(entity_args)
    ]

    translation_args = [
        {'string': 'First translation', 'entity': entities[0]},
        {'string': 'Second translation', 'entity': entities[1]},
        {'string': 'Third translation', 'entity': entities[2]},
        {'string': 'Fourth translation', 'entity': entities[3]},
        {'string': 'Fifth translation', 'entity': entities[4]},
        {'string': 'Sixth translation', 'entity': entities[5]},
        {'string': 'Seventh translation', 'entity': entities[6]},
    ]
    for x in translation_args:
        TranslationFactory.create(
            locale=locale_a,
            string=x['string'],
            entity=x['entity'],
        )

    return (
        entities,
        lambda q: list(
            Entity.for_project_locale(
                resource_a.project,
                locale_a,
                search=q,
            )
        )
    )
コード例 #21
0
def test_translation_save_latest_update(locale_a, project_a):
    """
    When a translation is saved, update the latest_translation
    attribute on the related project, locale, translatedresource,
    and project_locale objects.
    """
    project_locale = ProjectLocaleFactory.create(
        project=project_a,
        locale=locale_a,
    )
    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")

    assert locale_a.latest_translation is None
    assert 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),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == translation
    assert project_a.latest_translation == translation
    assert tr.latest_translation == translation
    assert project_locale.latest_translation == translation

    # Ensure translation is replaced for newer translations
    newer_translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        date=aware_datetime(1970, 2, 1),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_translation
    assert project_a.latest_translation == newer_translation
    assert tr.latest_translation == newer_translation
    assert project_locale.latest_translation == newer_translation

    # Ensure translation isn't replaced for older translations.
    TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        date=aware_datetime(1970, 1, 5),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_translation
    assert project_a.latest_translation == newer_translation
    assert tr.latest_translation == newer_translation
    assert project_locale.latest_translation == newer_translation

    # Ensure approved_date is taken into consideration as well.
    newer_approved_translation = TranslationFactory.create(
        locale=locale_a,
        entity=entity,
        approved_date=aware_datetime(1970, 3, 1),
    )
    locale_a.refresh_from_db()
    project_a.refresh_from_db()
    tr.refresh_from_db()
    project_locale.refresh_from_db()
    assert locale_a.latest_translation == newer_approved_translation
    assert project_a.latest_translation == newer_approved_translation
    assert tr.latest_translation == newer_approved_translation
    assert project_locale.latest_translation == newer_approved_translation
コード例 #22
0
ファイル: test_entity.py プロジェクト: mferra34-ford/pontoon
def entity_test_search(resource_a, locale_a):
    """This fixture provides:

    - 7 translated entities
    - A lambda for searching for entities using Entity.for_project_locale
    """
    TranslatedResourceFactory.create(
        locale=locale_a, resource=resource_a,
    )

    entity_args = [
        {
            "string": "First entity string",
            "string_plural": "First plural string",
            "comment": "random notes",
        },
        {
            "string": "Second entity string",
            "string_plural": "Second plural string",
            "comment": "random",
        },
        {
            "string": u"Third entity string with some twist: ZAŻÓŁĆ GĘŚLĄ",
            "string_plural": "Third plural",
            "comment": "even more random notes",
        },
        {
            "string": "Entity with first string",
            "string_plural": "Entity with plural first string",
            "comment": "random notes",
        },
        {
            "string": "First Entity",
            "string_plural": "First plural entity",
            "comment": "random notes",
        },
        {
            "string": "First Entity with string",
            "string_plural": "First plural entity",
            "comment": "random notes",
        },
        {
            "string": 'Entity with quoted "string"',
            "string_plural": "plural entity",
            "comment": "random notes",
        },
    ]
    entities = [
        EntityFactory(
            resource=resource_a,
            string=x["string"],
            string_plural=x["string_plural"],
            comment=x["comment"],
            order=i,
        )
        for i, x in enumerate(entity_args)
    ]

    translation_args = [
        {"string": "First translation", "entity": entities[0]},
        {"string": "Second translation", "entity": entities[1]},
        {"string": "Third translation", "entity": entities[2]},
        {"string": "Fourth translation", "entity": entities[3]},
        {"string": "Fifth translation", "entity": entities[4]},
        {"string": "Sixth translation", "entity": entities[5]},
        {"string": "Seventh translation", "entity": entities[6]},
    ]
    for x in translation_args:
        TranslationFactory.create(
            locale=locale_a, string=x["string"], entity=x["entity"],
        )

    return (
        entities,
        lambda q: list(
            Entity.for_project_locale(resource_a.project, locale_a, search=q,)
        ),
    )
コード例 #23
0
def entity_test_search(resource_a, locale_a):
    """This fixture provides:

    - 7 translated entities
    - A lambda for searching for entities using Entity.for_project_locale
    """
    TranslatedResourceFactory.create(
        locale=locale_a,
        resource=resource_a,
    )

    entity_args = [
        {
            'string': 'First entity string',
            'string_plural': 'First plural string',
            'comment': 'random notes',
        },
        {
            'string': 'Second entity string',
            'string_plural': 'Second plural string',
            'comment': 'random',
        },
        {
            'string': u'Third entity string with some twist: ZAŻÓŁĆ GĘŚLĄ',
            'string_plural': 'Third plural',
            'comment': 'even more random notes',
        },
        {
            'string': 'Entity with first string',
            'string_plural': 'Entity with plural first string',
            'comment': 'random notes',
        },
        {
            'string': 'First Entity',
            'string_plural': 'First plural entity',
            'comment': 'random notes',
        },
        {
            'string': 'First Entity with string',
            'string_plural': 'First plural entity',
            'comment': 'random notes',
        },
        {
            'string': 'Entity with quoted "string"',
            'string_plural': 'plural entity',
            'comment': 'random notes',
        },
    ]
    entities = [
        EntityFactory(
            resource=resource_a,
            string=x['string'],
            string_plural=x['string_plural'],
            comment=x['comment'],
            order=i,
        ) for i, x in enumerate(entity_args)
    ]

    translation_args = [
        {
            'string': 'First translation',
            'entity': entities[0]
        },
        {
            'string': 'Second translation',
            'entity': entities[1]
        },
        {
            'string': 'Third translation',
            'entity': entities[2]
        },
        {
            'string': 'Fourth translation',
            'entity': entities[3]
        },
        {
            'string': 'Fifth translation',
            'entity': entities[4]
        },
        {
            'string': 'Sixth translation',
            'entity': entities[5]
        },
        {
            'string': 'Seventh translation',
            'entity': entities[6]
        },
    ]
    for x in translation_args:
        TranslationFactory.create(
            locale=locale_a,
            string=x['string'],
            entity=x['entity'],
        )

    return (entities, lambda q: list(
        Entity.for_project_locale(
            resource_a.project,
            locale_a,
            search=q,
        )))