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))
예제 #2
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)
예제 #3
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)
    )
예제 #4
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)] * 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
예제 #5
0
파일: test_entity.py 프로젝트: Pike/pontoon
def test_view_entity_exclude_entities(
    member,
    resource_a,
    locale_a,
):
    """
    Excluded entities shouldn't be returned by get_entities.
    """
    TranslatedResource.objects.create(resource=resource_a, locale=locale_a)
    ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a)
    entities = EntityFactory.create_batch(size=3, resource=resource_a)
    excluded_pk = entities[1].pk
    response = member.client.post(
        '/get-entities/',
        {
            'project': resource_a.project.slug,
            'locale': locale_a.code,
            'paths[]': [resource_a.path],
            'exclude_entities': [excluded_pk],
            'limit': 1,
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest',
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is True
    assert (
        [e['pk'] for e in json.loads(response.content)['entities']]
        != [excluded_pk]
    )

    exclude_entities = ','.join(map(
        str,
        [
            entities[2].pk,
            entities[1].pk,
        ]
    ))
    response = member.client.post(
        '/get-entities/',
        {
            'project': resource_a.project.slug,
            'locale': locale_a.code,
            'paths[]': [resource_a.path],
            'exclude_entities': exclude_entities,
            'limit': 1,
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest',
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is False
    assert (
        [e['pk'] for e in json.loads(response.content)['entities']]
        == [entities[0].pk]
    )
예제 #6
0
def test_view_entity_exclude_entities(
    member,
    resource_a,
    locale_a,
):
    """
    Excluded entities shouldn't be returned by get_entities.
    """
    TranslatedResource.objects.create(resource=resource_a, locale=locale_a)
    entities = EntityFactory.create_batch(size=3, resource=resource_a)
    excluded_pk = entities[1].pk
    response = member.client.post(
        '/get-entities/',
        {
            'project': resource_a.project.slug,
            'locale': locale_a.code,
            'paths[]': [resource_a.path],
            'exclude_entities': [excluded_pk],
            'limit': 1,
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest',
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is True
    assert (
        [e['pk'] for e in json.loads(response.content)['entities']]
        != [excluded_pk]
    )

    exclude_entities = ','.join(map(
        str,
        [
            entities[2].pk,
            entities[1].pk,
        ]
    ))
    response = member.client.post(
        '/get-entities/',
        {
            'project': resource_a.project.slug,
            'locale': locale_a.code,
            'paths[]': [resource_a.path],
            'exclude_entities': exclude_entities,
            'limit': 1,
        },
        HTTP_X_REQUESTED_WITH='XMLHttpRequest',
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is False
    assert (
        [e['pk'] for e in json.loads(response.content)['entities']]
        == [entities[0].pk]
    )
예제 #7
0
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 = users_with_translations_counts()
    assert len(top_contributors) == 100
예제 #8
0
def test_view_entity_exclude_entities(
    member,
    resource_a,
    locale_a,
):
    """
    Excluded entities shouldn't be returned by get_entities.
    """
    TranslatedResource.objects.create(resource=resource_a, locale=locale_a)
    ProjectLocaleFactory.create(project=resource_a.project, locale=locale_a)
    entities = EntityFactory.create_batch(size=3, resource=resource_a)
    excluded_pk = entities[1].pk
    response = member.client.post(
        "/get-entities/",
        {
            "project": resource_a.project.slug,
            "locale": locale_a.code,
            "paths[]": [resource_a.path],
            "exclude_entities": [excluded_pk],
            "limit": 1,
        },
        HTTP_X_REQUESTED_WITH="XMLHttpRequest",
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is True
    assert [e["pk"] for e in json.loads(response.content)["entities"]
            ] != [excluded_pk]

    exclude_entities = ",".join(map(str, [entities[2].pk, entities[1].pk]))
    response = member.client.post(
        "/get-entities/",
        {
            "project": resource_a.project.slug,
            "locale": locale_a.code,
            "paths[]": [resource_a.path],
            "exclude_entities": exclude_entities,
            "limit": 1,
        },
        HTTP_X_REQUESTED_WITH="XMLHttpRequest",
    )
    assert response.status_code == 200
    assert json.loads(response.content)["has_next"] is False
    assert [e["pk"] for e in json.loads(response.content)["entities"]
            ] == [entities[0].pk]
예제 #9
0
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(users_with_translations_counts()) == [
        contributors[i] for i in [2, 4, 1, 0, 3]
    ]
예제 #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_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]]
    )
예제 #12
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
예제 #13
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
예제 #14
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
예제 #15
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
예제 #16
0
def test_manage_project_strings_list(client_superuser):
    project = ProjectFactory.create(data_source="database", repositories=[])
    resource = ResourceFactory.create(project=project)
    nb_entities = 2
    entities = EntityFactory.create_batch(nb_entities, resource=resource)

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

    response = client_superuser.get(url)
    assert response.status_code == 200
    for i in range(nb_entities):
        assert (entities[i].string).encode("utf-8") in response.content

    # Test editing strings and comments.
    form_data = {
        "form-TOTAL_FORMS": nb_entities,
        "form-INITIAL_FORMS": nb_entities,
        "form-MIN_NUM_FORMS": 0,
        "form-MAX_NUM_FORMS": 1000,
        "form-0-id": entities[0].id,
        "form-0-string": "changed 0",
        "form-0-comment": "Wubba lubba dub dub",
        "form-1-id": entities[1].id,
        "form-1-string": "string 1",
        "form-1-obsolete": "on",  # Remove this one.
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert b"changed 0" in response.content
    assert b"Wubba lubba dub dub" in response.content
    assert b"string 0" not in response.content
    assert b"string 1" not in response.content  # It's been removed.

    total = Entity.objects.filter(
        resource=resource,
        obsolete=False,
    ).count()
    assert total == nb_entities - 1

    # Test adding a new string.
    form_data = {
        "form-TOTAL_FORMS": nb_entities,
        "form-INITIAL_FORMS": nb_entities - 1,
        "form-MIN_NUM_FORMS": 0,
        "form-MAX_NUM_FORMS": 1000,
        "form-0-id": entities[0].id,
        "form-0-string": "changed 0",
        "form-0-comment": "Wubba lubba dub dub",
        "form-1-id": "",
        "form-1-string": "new string",
        "form-1-comment": "adding this entity now",
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert b"changed 0" in response.content
    assert b"new string" in response.content
    assert b"adding this entity now" in response.content

    total = Entity.objects.filter(
        resource=resource,
        obsolete=False,
    ).count()
    assert total == nb_entities

    # Verify the new string has the correct order.
    new_string = Entity.objects.filter(
        resource=resource,
        obsolete=False,
        string="new string",
    ).first()
    # The order of the new string should be that of the highest existing order
    # plus one. In our case, we know the highest was simply the other string.
    assert new_string.order == entities[0].order + 1
예제 #17
0
def test_manage_project_strings_list(client_superuser):
    project = ProjectFactory.create(data_source='database', repositories=[])
    resource = ResourceFactory.create(project=project)
    nb_entities = 2
    entities = EntityFactory.create_batch(nb_entities, resource=resource)

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

    response = client_superuser.get(url)
    assert response.status_code == 200
    for i in range(nb_entities):
        assert ('string %s' % i).encode('utf-8') in response.content

    # Test editing strings and comments.
    form_data = {
        'form-TOTAL_FORMS': nb_entities,
        'form-INITIAL_FORMS': nb_entities,
        'form-MIN_NUM_FORMS': 0,
        'form-MAX_NUM_FORMS': 1000,
        'form-0-id': entities[0].id,
        'form-0-string': 'changed 0',
        'form-0-comment': 'Wubba lubba dub dub',
        'form-1-id': entities[1].id,
        'form-1-string': 'string 1',
        'form-1-obsolete': 'on',  # Remove this one.
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert b'changed 0' in response.content
    assert b'Wubba lubba dub dub' in response.content
    assert b'string 0' not in response.content
    assert b'string 1' not in response.content  # It's been removed.

    total = Entity.objects.filter(
        resource=resource,
        obsolete=False,
    ).count()
    assert total == nb_entities - 1

    # Test adding a new string.
    form_data = {
        'form-TOTAL_FORMS': nb_entities,
        'form-INITIAL_FORMS': nb_entities - 1,
        'form-MIN_NUM_FORMS': 0,
        'form-MAX_NUM_FORMS': 1000,
        'form-0-id': entities[0].id,
        'form-0-string': 'changed 0',
        'form-0-comment': 'Wubba lubba dub dub',
        'form-1-id': '',
        'form-1-string': 'new string',
        'form-1-comment': 'adding this entity now',
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert b'changed 0' in response.content
    assert b'new string' in response.content
    assert b'adding this entity now' in response.content

    total = Entity.objects.filter(
        resource=resource,
        obsolete=False,
    ).count()
    assert total == nb_entities

    # Verify the new string has the correct order.
    new_string = Entity.objects.filter(
        resource=resource,
        obsolete=False,
        string='new string',
    ).first()
    # The highest order before adding new string was 0,
    # so the order of that new one should be 1.
    assert new_string.order == 1
예제 #18
0
파일: test_views.py 프로젝트: Pike/pontoon
def test_manage_project_strings_list(client_superuser):
    project = ProjectFactory.create(data_source='database', repositories=[])
    resource = ResourceFactory.create(project=project)
    nb_entities = 2
    entities = EntityFactory.create_batch(nb_entities, resource=resource)

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

    response = client_superuser.get(url)
    assert response.status_code == 200
    for i in range(nb_entities):
        assert 'string %s' % i in response.content

    # Test editing strings and comments.
    form_data = {
        'form-TOTAL_FORMS': nb_entities,
        'form-INITIAL_FORMS': nb_entities,
        'form-MIN_NUM_FORMS': 0,
        'form-MAX_NUM_FORMS': 1000,
        'form-0-id': entities[0].id,
        'form-0-string': 'changed 0',
        'form-0-comment': 'Wubba lubba dub dub',
        'form-1-id': entities[1].id,
        'form-1-string': 'string 1',
        'form-1-obsolete': 'on',  # Remove this one.
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert 'changed 0' in response.content
    assert 'Wubba lubba dub dub' in response.content
    assert 'string 0' not in response.content
    assert 'string 1' not in response.content  # It's been removed.

    total = Entity.objects.filter(
        resource=resource, obsolete=False,
    ).count()
    assert total == nb_entities - 1

    # Test adding a new string.
    form_data = {
        'form-TOTAL_FORMS': nb_entities,
        'form-INITIAL_FORMS': nb_entities - 1,
        'form-MIN_NUM_FORMS': 0,
        'form-MAX_NUM_FORMS': 1000,
        'form-0-id': entities[0].id,
        'form-0-string': 'changed 0',
        'form-0-comment': 'Wubba lubba dub dub',
        'form-1-id': '',
        'form-1-string': 'new string',
        'form-1-comment': 'adding this entity now',
    }

    response = client_superuser.post(url, form_data)
    assert response.status_code == 200
    assert 'changed 0' in response.content
    assert 'new string' in response.content
    assert 'adding this entity now' in response.content

    total = Entity.objects.filter(
        resource=resource, obsolete=False,
    ).count()
    assert total == nb_entities

    # Verify the new string has the correct order.
    new_string = Entity.objects.filter(
        resource=resource, obsolete=False, string='new string',
    ).first()
    # The highest order before adding new string was 0,
    # so the order of that new one should be 1.
    assert new_string.order == 1