예제 #1
0
파일: test_user.py 프로젝트: Pike/pontoon
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
예제 #2
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #3
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #4
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #5
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #6
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
예제 #7
0
파일: test_views.py 프로젝트: Pike/pontoon
def test_view_caighdean(client, entity_a):
    gd = Locale.objects.get(code='gd')
    url = reverse('pontoon.caighdean')

    response = client.get(url, dict(id=entity_a.id))
    assert json.loads(response.content) == {}

    translation = TranslationFactory.create(
        entity=entity_a, locale=gd, string='GD translation'
    )
    entity_a.translation_set.add(translation)

    translator = caighdean.Translator()

    with requests_mock.mock() as m:
        m.post(translator.service_url, text='[["source", "target"]]')
        response = client.get(url, dict(id=entity_a.id))

    assert (
        json.loads(response.content)
        == {
            "translation": "target",
            "original": translation.string,
        }
    )
    assert (
        urlparse.parse_qs(m.request_history[0].text)
        == {
            u'teacs': [translation.string],
            u'foinse': [gd.code],
        }
    )
예제 #8
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #9
0
def test_view_caighdean_bad(client, entity_a):
    gd = Locale.objects.get(code='gd')
    url = reverse('pontoon.caighdean')

    response = client.get(url)
    assert response.status_code == 400
    assert response.get("Content-Type") == 'application/json'
    assert (
        json.loads(response.content)["message"]
        == 'Bad Request: "\'id\'"'
    )

    response = client.get(url, dict(id="DOESNOTEXIST"))
    assert response.status_code == 400
    assert response.get("Content-Type") == 'application/json'
    assert (
        json.loads(response.content)["message"]
        == ("Bad Request: invalid literal for int() "
            "with base 10: 'DOESNOTEXIST'")
    )

    maxid = (
        Entity.objects
        .values_list("id", flat=True)
        .order_by("-id")
        .first()
    )
    response = client.get(url, dict(id=maxid + 1))
    assert response.status_code == 404
    assert response.get("Content-Type") == 'application/json'
    assert (
        json.loads(response.content)["message"]
        == 'Not Found: Entity matching query does not exist.'
    )

    translator = caighdean.Translator()
    translation = TranslationFactory.create(
        entity=entity_a,
        locale=gd,
        string='foo',
        plural_form=None,
        approved=True,
    )
    entity_a.translation_set.add(translation)

    with requests_mock.mock() as m:
        m.post(translator.service_url, status_code=403)
        response = client.get(url, dict(id=entity_a.id))

    assert response.status_code == 500
    assert response.get("Content-Type") == 'application/json'
    assert (
        json.loads(response.content)["message"]
        == 'Server Error: Unable to connect to translation service'
    )
예제 #10
0
파일: test_user.py 프로젝트: Pike/pontoon
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
예제 #11
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #12
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #13
0
파일: test_entity.py 프로젝트: Pike/pontoon
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',
        )) == []
    )
예제 #14
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #15
0
파일: test_user.py 프로젝트: Pike/pontoon
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]]
    )
예제 #16
0
파일: test_entity.py 프로젝트: Pike/pontoon
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]}
    )
예제 #17
0
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,
        )
예제 #18
0
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,
    )
예제 #19
0
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,
        )
예제 #20
0
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,
                     rejected=True)
            ] * 3,
            [dict(user=contributors[0], fuzzy=True)] * 2,
            [dict(user=contributors[1], approved=True)] * 5,
            [
                dict(user=contributors[1],
                     approved=False,
                     fuzzy=False,
                     rejected=True)
            ] * 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),
            rejected=args.get("rejected", False),
            fuzzy=args.get("fuzzy", False),
        )

    top_contribs = users_with_translations_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_rejected_count == 9
    assert top_contribs[0].translations_unapproved_count == 0
    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_rejected_count == 3
    assert top_contribs[1].translations_unapproved_count == 0
    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_rejected_count == 0
    assert top_contribs[2].translations_unapproved_count == 2
    assert top_contribs[2].translations_needs_work_count == 5
예제 #21
0
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 = users_with_translations_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_rejected_count == 0
    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_rejected_count == 0
    assert top_contribs[1].translations_unapproved_count == 1
    assert top_contribs[1].translations_needs_work_count == 2

    top_contribs = users_with_translations_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_rejected_count == 0
    assert top_contribs[0].translations_unapproved_count == 1
    assert top_contribs[0].translations_needs_work_count == 2
예제 #22
0
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 = users_with_translations_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_rejected_count == 0
    assert top_contribs[0].translations_unapproved_count == 0
    assert top_contribs[0].translations_needs_work_count == 0

    top_contribs = users_with_translations_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_rejected_count == 0
    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_rejected_count == 0
    assert top_contribs[1].translations_unapproved_count == 0
    assert top_contribs[1].translations_needs_work_count == 0

    top_contribs = users_with_translations_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_rejected_count == 0
    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_rejected_count == 0
    assert top_contribs[1].translations_unapproved_count == 11
    assert top_contribs[1].translations_needs_work_count == 2
예제 #23
0
def rejected_translation(locale_a, project_locale_a, entity_a, user_a):
    return TranslationFactory(entity=entity_a,
                              locale=locale_a,
                              user=user_a,
                              rejected=True)
예제 #24
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": "First string",
            "comment": "random Strıng"
        },
        {
            "string": "Second strİng",
            "comment": "random string"
        },
        {
            "string": "Third Strıng",
            "comment": "random strİng"
        },
    ]
    entities = [
        EntityFactory(
            resource=resource_a,
            string=x["string"],
            comment=x["comment"],
        ) for x in entity_args
    ]

    translation_args = [
        "this is string",
        "this is STRİNG",
        "this is Strıng",
        "this is StrInG",
        "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=(
            "string", "tr_tr"))) == set([entities[n]
                                         for n in [0, 1]] + [entity])
    assert set(
        resource_a.entities.filter(
            comment__icontains_collate=("strİng", "tr_tr"))) == {
                entities[n]
                for n in [1, 2]
            }
    assert set(
        Translation.objects.filter(
            string__icontains_collate=("string", "tr_tr"))) == {
                translations[n]
                for n in [0, 1, 4]
            }
    assert set(
        Translation.objects.filter(
            string__icontains_collate=("string", "tr_tr"))) == {
                translations[n]
                for n in [0, 1, 4]
            }
    assert set(
        Translation.objects.filter(
            string__icontains_collate=("strİng", "tr_tr"))) == {
                translations[n]
                for n in [0, 1, 4]
            }
    assert set(
        Translation.objects.filter(
            string__icontains_collate=("strıng", "tr_tr"))) == {
                translations[n]
                for n in [2, 3]
            }
    # Check if differentiation fails without any collation(C)
    assert set(
        Translation.objects.filter(
            string__icontains_collate=("string", "C"))) == {
                translations[n]
                for n in [0, 3, 4]
            }
    # Compare the icontains_collate query with regular i_contains query
    assert set(Translation.objects.filter(string__icontains="string")) == {
        translations[n]
        for n in [0, 2, 3, 4]
    }
예제 #25
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
예제 #26
0
def test_mgr_entity_filter_stale(resource_a, locale_a):
    now = timezone.now()
    before = now - timedelta(minutes=1)
    after = now + timedelta(minutes=1)

    locale_a.cldr_plurals = "1,5"
    locale_a.save()
    entities = [
        EntityFactory.create(
            resource=resource_a,
            string="Source string",
            string_plural="Source string plural",
            date_updated=now,
        ) for i in range(0, 3)
    ]

    # Approved, stale
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=True,
        plural_form=0,
        string="Translated string",
        approved_date=before,
        date=before,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=True,
        plural_form=1,
        string="Translated plural string",
        approved_date=before,
        date=before,
    )
    # Not approved, stale
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[1],
        approved=False,
        plural_form=0,
        string="Translated string",
        date=before,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[1],
        approved=False,
        plural_form=1,
        string="Translated plural string",
        date=before,
    )
    # Approved, up to date
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[2],
        approved=True,
        plural_form=0,
        string="Translated string",
        approved_date=after,
        date=after,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[2],
        approved=True,
        plural_form=1,
        string="Translated plural string",
        approved_date=after,
        date=before,
    )

    assert set(Entity.objects.filter(
        Entity.objects.stale(locale_a))) == {entities[0]}
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]}
    )
예제 #28
0
def test_manage_project_strings_download_csv(client_superuser):
    locale_kl = LocaleFactory.create(code="kl", name="Klingon")
    locale_gs = LocaleFactory.create(code="gs", name="Geonosian")
    project = ProjectFactory.create(data_source="database",
                                    locales=[locale_kl, locale_gs],
                                    repositories=[])

    url = reverse("pontoon.admin.project.strings", args=(project.slug, ))

    new_strings = """
        And on the pedestal these words appear:
        'My name is Ozymandias, king of kings:
        Look on my works, ye Mighty, and despair!'
    """
    response = client_superuser.post(url, {"new_strings": new_strings})
    assert response.status_code == 200

    # Test downloading the data.
    response = client_superuser.get(url, {"format": "csv"})
    assert response.status_code == 200
    assert response._headers["content-type"] == ("Content-Type", "text/csv")

    # Verify the original content is here.
    assert b"pedestal" in response.content
    assert b"Ozymandias" in response.content
    assert b"Mighty" in response.content

    # Verify we have the locale columns.
    assert b"kl" in response.content
    assert b"gs" in response.content

    # Now add some translations.
    entity = Entity.objects.filter(
        string="And on the pedestal these words appear:")[0]
    TranslationFactory.create(
        string="Et sur le piédestal il y a ces mots :",
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string="Und auf dem Sockel steht die Schrift: ‚Mein Name",
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(
        string="'My name is Ozymandias, king of kings:")[0]
    TranslationFactory.create(
        string='"Mon nom est Ozymandias, Roi des Rois.',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string="Ist Osymandias, aller Kön’ge König: –",
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(
        string="Look on my works, ye Mighty, and despair!'")[0]
    TranslationFactory.create(
        string='Voyez mon œuvre, vous puissants, et désespérez !"',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string="Seht meine Werke, Mächt’ge, und erbebt!‘",
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    response = client_superuser.get(url, {"format": "csv"})

    # Verify the translated content is here.
    assert b"pedestal" in response.content
    assert "piédestal".encode("utf-8") in response.content
    assert b"Sockel" in response.content

    assert b"Mighty" in response.content
    assert b"puissants" in response.content
    assert "Mächt’ge".encode("utf-8") in response.content
예제 #29
0
파일: test_views.py 프로젝트: Pike/pontoon
def test_manage_project_strings_download_csv(client_superuser):
    locale_kl = LocaleFactory.create(code='kl', name='Klingon')
    locale_gs = LocaleFactory.create(code='gs', name='Geonosian')
    project = ProjectFactory.create(
        data_source='database',
        locales=[locale_kl, locale_gs],
        repositories=[]
    )

    url = reverse('pontoon.admin.project.strings', args=(project.slug,))

    new_strings = """
        And on the pedestal these words appear:
        'My name is Ozymandias, king of kings:
        Look on my works, ye Mighty, and despair!'
    """
    response = client_superuser.post(url, {'new_strings': new_strings})
    assert response.status_code == 200

    # Test downloading the data.
    response = client_superuser.get(url, {'format': 'csv'})
    assert response.status_code == 200
    assert response._headers['content-type'] == ('Content-Type', 'text/csv')

    # Verify the original content is here.
    assert 'pedestal' in response.content
    assert 'Ozymandias' in response.content
    assert 'Mighty' in response.content

    # Verify we have the locale columns.
    assert 'kl' in response.content
    assert 'gs' in response.content

    # Now add some translations.
    entity = Entity.objects.filter(string='And on the pedestal these words appear:')[0]
    TranslationFactory.create(
        string='Et sur le piédestal il y a ces mots :',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Und auf dem Sockel steht die Schrift: ‚Mein Name',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(string='\'My name is Ozymandias, king of kings:')[0]
    TranslationFactory.create(
        string='"Mon nom est Ozymandias, Roi des Rois.',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Ist Osymandias, aller Kön’ge König: –',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(string='Look on my works, ye Mighty, and despair!\'')[0]
    TranslationFactory.create(
        string='Voyez mon œuvre, vous puissants, et désespérez !"',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Seht meine Werke, Mächt’ge, und erbebt!‘',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    response = client_superuser.get(url, {'format': 'csv'})

    # Verify the translated content is here.
    assert 'pedestal' in response.content
    assert 'piédestal' in response.content
    assert 'Sockel' in response.content

    assert 'Mighty' in response.content
    assert 'puissants' in response.content
    assert 'Mächt’ge' in response.content
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'
예제 #31
0
def test_mgr_entity_filter_missing_without_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, 4)
    ]

    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=False,
        fuzzy=False,
        rejected=True,
        plural_form=0,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=False,
        fuzzy=False,
        rejected=True,
        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=False,
        plural_form=0,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[2],
        approved=True,
        fuzzy=False,
        rejected=False,
        plural_form=1,
    )
    assert set(
        resource_a.entities.filter(
            Entity.objects.missing_without_unreviewed(locale_a))) == {
                entities[0], entities[1], entities[3]
            }
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,
            )
        )
    )
예제 #33
0
파일: test_user.py 프로젝트: Pike/pontoon
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_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]}
    )
예제 #35
0
파일: test_user.py 프로젝트: Pike/pontoon
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
예제 #36
0
def test_manage_project_strings_download_csv(client_superuser):
    locale_kl = LocaleFactory.create(code='kl', name='Klingon')
    locale_gs = LocaleFactory.create(code='gs', name='Geonosian')
    project = ProjectFactory.create(data_source='database',
                                    locales=[locale_kl, locale_gs],
                                    repositories=[])

    url = reverse('pontoon.admin.project.strings', args=(project.slug, ))

    new_strings = """
        And on the pedestal these words appear:
        'My name is Ozymandias, king of kings:
        Look on my works, ye Mighty, and despair!'
    """
    response = client_superuser.post(url, {'new_strings': new_strings})
    assert response.status_code == 200

    # Test downloading the data.
    response = client_superuser.get(url, {'format': 'csv'})
    assert response.status_code == 200
    assert response._headers['content-type'] == ('Content-Type', 'text/csv')

    # Verify the original content is here.
    assert 'pedestal' in response.content
    assert 'Ozymandias' in response.content
    assert 'Mighty' in response.content

    # Verify we have the locale columns.
    assert 'kl' in response.content
    assert 'gs' in response.content

    # Now add some translations.
    entity = Entity.objects.filter(
        string='And on the pedestal these words appear:')[0]
    TranslationFactory.create(
        string='Et sur le piédestal il y a ces mots :',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Und auf dem Sockel steht die Schrift: ‚Mein Name',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(
        string='\'My name is Ozymandias, king of kings:')[0]
    TranslationFactory.create(
        string='"Mon nom est Ozymandias, Roi des Rois.',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Ist Osymandias, aller Kön’ge König: –',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    entity = Entity.objects.filter(
        string='Look on my works, ye Mighty, and despair!\'')[0]
    TranslationFactory.create(
        string='Voyez mon œuvre, vous puissants, et désespérez !"',
        entity=entity,
        locale=locale_kl,
        approved=True,
    )
    TranslationFactory.create(
        string='Seht meine Werke, Mächt’ge, und erbebt!‘',
        entity=entity,
        locale=locale_gs,
        approved=True,
    )

    response = client_superuser.get(url, {'format': 'csv'})

    # Verify the translated content is here.
    assert 'pedestal' in response.content
    assert 'piédestal' in response.content
    assert 'Sockel' in response.content

    assert 'Mighty' in response.content
    assert 'puissants' in response.content
    assert 'Mächt’ge' in response.content
예제 #37
0
def entity_test_search(admin, 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(
                admin,
                resource_a.project,
                locale_a,
                search=q,
            )),
    )
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]]
    )
예제 #39
0
def approved_translation(locale_a, project_locale_a, entity_a, user_a):
    return TranslationFactory(
        entity=entity_a, locale=locale_a, user=user_a, approved=True, active=True,
    )
예제 #40
0
def test_mgr_entity_filter_missing_without_unreviewed(resource_a, locale_a):
    entities = [
        EntityFactory.create(
            resource=resource_a,
            string="testentity%s" % i,
        ) for i in range(0, 5)
    ]

    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=False,
        fuzzy=False,
        rejected=True,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[0],
        approved=False,
        fuzzy=False,
        rejected=True,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[2],
        approved=True,
        fuzzy=False,
        rejected=False,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[3],
        approved=False,
        fuzzy=True,
        rejected=False,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[1],
        approved=False,
        fuzzy=False,
        rejected=True,
    )
    TranslationFactory.create(
        locale=locale_a,
        entity=entities[1],
        approved=False,
        fuzzy=False,
        rejected=False,
    )

    assert set(
        resource_a.entities.filter(
            Entity.objects.missing_without_unreviewed(locale_a))) == {
                entities[0], entities[4]
            }