Exemplo n.º 1
0
def test_duedate_delete(client, request_users, test_name, snapshot_stack,
                        path):
    """Tests removing existing due dates."""
    user = request_users['user']

    data = {
        'due_on': datetime.now(),
        'modified_by': user,
        'pootle_path': path,
    }
    due_date = DueDateFactory.create(**data)
    assert due_date.id is not None

    url = '/xhr/duedates/%s/' % due_date.id

    with snapshot_stack.push(
        [as_dir(test_name),
         as_dir(user.username),
         url_name(path)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.delete(url, content_type='application/json')

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 2
0
def test_stats_checks(client, request_users, test_name, request,
                      snapshot_stack, path):
    """Tests the /xhr/stats/checks/ endpoint's context."""
    user = request_users['user']

    # FIXME: stats refreshing boilerplate
    global users_with_stats
    if user not in users_with_stats:
        request.getfixturevalue('refresh_stats')
        users_with_stats.add(user)

    with snapshot_stack.push(
        [as_dir(test_name),
         as_dir(user.username),
         url_name(path)]):
        if not user.is_anonymous:
            client.force_login(user)
        url = '/xhr/stats/checks/?path=%s' % path
        response = client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('response_body') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 3
0
def test_taskresultset_importance_order(test_name, snapshot_stack, sort_type,
                                        fake_task_args):
    """Tests ordering of tasks according to their importance."""
    tasks = [LightTask(*task_args) for task_args in fake_task_args]
    with snapshot_stack.push([as_dir(test_name), sort_type]) as snapshot:
        task_resultset = TaskResultSet(tasks).order_by_importance()
        snapshot.assert_matches([task for task in task_resultset])
Exemplo n.º 4
0
def test_get_tasks_invalid_language(client, request_users, test_name,
                                    snapshot_stack):
    """Tests attempting to retrieve tasks for an invalid language."""
    url = '/xhr/tasks/invalid-language-code/'
    user = request_users['user']

    with snapshot_stack.push([as_dir(test_name), as_dir(user.username)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.get(url)

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 5
0
def test_translate(client, request_users, test_name, snapshot_stack, url):
    """Tests correctness of the translate view context."""
    user = request_users['user']

    with snapshot_stack.push(
        [as_dir(test_name),
         as_dir(user.username),
         url_name(url)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.get(url)

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.context)
Exemplo n.º 6
0
def test_get_tasks_permissions(client, test_name, snapshot_stack,
                               refresh_stats, request, request_users,
                               patch_timezone_now, project0, hide):
    """Tests pending tasks retrieval with restricted permissions."""
    language = 'language0'
    url = '/xhr/tasks/%s/' % language
    user = request_users['user']

    # Disallow `project0` access to `member`
    if user.username == 'member':
        _require_permission_set(user,
                                project0.directory,
                                negative_permissions=[hide])

    # FIXME: stats refreshing boilerplate
    global users_with_stats
    if user not in users_with_stats:
        request.getfixturevalue('refresh_stats')
        users_with_stats.add(user)

    now = aware_datetime(2017, 02, 28, 9, 00)
    patch_timezone_now(now)

    DueDateFactory.create(
        pootle_path='/projects/project0/',
        due_on=now + timedelta(days=8),
    )
    DueDateFactory.create(
        pootle_path='/%s/project0/store0.po' % language,
        due_on=now + timedelta(days=2),
    )
    DueDateFactory.create(
        pootle_path='/%s/project1/store0.po' % language,
        due_on=now + timedelta(days=4),
    )

    with snapshot_stack.push([as_dir(test_name), as_dir(user.username)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.get(url)

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 7
0
def test_export(client, request_users, test_name, monkeypatch, snapshot_stack,
                url, limit):
    """Tests correctness of the export view context."""
    user = request_users['user']

    stack = [as_dir(test_name), as_dir(user.username), url_name(url)]
    if limit is not None:
        stack.append('limit=%s' % limit)
        monkeypatch.setattr('pootle.core.views.export.UNITS_LIMIT', limit)

    with snapshot_stack.push(stack):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.get(url)

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.context)
Exemplo n.º 8
0
def test_duedate_update(client, request_users, test_name, snapshot_stack,
                        path):
    """Tests updating existing due dates."""
    user = request_users['user']

    initial_due_on = aware_datetime(2017, 01, 26, 01, 02, 03)
    data = {
        'due_on': initial_due_on,
        'modified_by': user,
        'pootle_path': path,
    }
    due_date = DueDateFactory.create(**data)
    assert due_date.id is not None

    url = '/xhr/duedates/%s/' % due_date.id
    put_data = {
        'due_on': '2017-01-27',
        'pootle_path': path,
    }

    with snapshot_stack.push(
        [as_dir(test_name),
         as_dir(user.username),
         url_name(path)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.put(url,
                              jsonify(put_data),
                              content_type='application/json')

        if response.status_code == 200:
            due_date.refresh_from_db()
            assert due_date.due_on != initial_due_on

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 9
0
def test_browse(client, request_users, test_name, request,
                snapshot_stack, url):
    """Tests correctness of the browsing view context."""
    user = request_users['user']

    # stats refreshing boilerplate
    global users_with_stats
    if user not in users_with_stats:
        request.getfixturevalue('refresh_stats')
        users_with_stats.add(user)

    with snapshot_stack.push([
        as_dir(test_name), as_dir(user.username), url_name(url)
    ]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.get(url)

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.context)
Exemplo n.º 10
0
def test_duedate_post(client, request_users, test_name, snapshot_stack, path):
    """Tests creating new due dates."""
    url = '/xhr/duedates/'
    user = request_users['user']
    post_data = {
        'due_on': '2017-01-26',
        'pootle_path': path,
    }

    with snapshot_stack.push(
        [as_dir(test_name),
         as_dir(user.username),
         url_name(path)]):
        if not user.is_anonymous:
            client.force_login(user)
        response = client.post(url,
                               jsonify(post_data),
                               content_type='application/json')

        with snapshot_stack.push('status_code') as snapshot:
            snapshot.assert_matches(response.status_code)

        with snapshot_stack.push('context') as snapshot:
            snapshot.assert_matches(response.json())
Exemplo n.º 11
0
def test_stats_retrieval_no_stats(test_name, snapshot_stack, flush_stats):
    """Tests no stats are provided when these haven't been calculated."""
    path = '/language0/project0/'
    with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot:
        stats = Stats(path)
        stats_data = {
            'total': stats.total,
            'translated': stats.translated,
            'fuzzy': stats.fuzzy,
            'incomplete': stats.incomplete,
            'critical': stats.critical,
            'suggestions': stats.suggestions,
            'last_action': stats.last_action,
            'last_updated': stats.last_updated,
        }
        snapshot.assert_matches(stats_data)
Exemplo n.º 12
0
def test_stats_retrieval_dummy(test_name, snapshot_stack, refresh_stats):
    """Tests no stats are provided for dummy paths."""
    path = '/non/existing/'
    with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot:
        stats = Stats(path)
        stats_data = {
            'total': stats.total,
            'translated': stats.translated,
            'fuzzy': stats.fuzzy,
            'incomplete': stats.incomplete,
            'critical': stats.critical,
            'suggestions': stats.suggestions,
            'last_action': stats.last_action,
            'last_updated': stats.last_updated,
        }
        snapshot.assert_matches(stats_data)
Exemplo n.º 13
0
def test_stats_retrieval(test_name, snapshot_stack, refresh_stats):
    """Tests stats values are retrieved properly."""
    path = '/language0/project0/'
    with snapshot_stack.push([as_dir(test_name), url_name(path)]) as snapshot:
        stats = Stats(path)
        stats_data = {
            'total': stats.total,
            'translated': stats.translated,
            'fuzzy': stats.fuzzy,
            'incomplete': stats.incomplete,
            'critical': stats.critical,
            'suggestions': stats.suggestions,
            'last_action': stats.last_action,
            'last_updated': stats.last_updated,
        }
        snapshot.assert_matches(stats_data)