Пример #1
0
def test_redirect_not_a_redirect():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(status_code=200)),
            mock.sentinel.expected_path,
            mock.sentinel.expected_query,
        )
Пример #2
0
def test_all_data(server_with_data):
    resp = server_with_data.server.client.get(
        flask.url_for(
            'graph.all_data',
            metric_name=PythonImportCount.__name__,
        ),
    )

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        # Tested more explicitly below
        mock.ANY,
    )
    # This part is a bit racey due to how the commits were made.
    # Instead of opting for more-exact timing here, I decided to unit test
    # the underlying function and give a fuzzy check here.  The important part
    # about this endpoint is it redirects to a show url and doesn't start at 0
    timestamp = server_with_data.cloneable_with_commits.commits[-1].date
    parsed_qs = six.moves.urllib_parse.parse_qs(
        six.moves.urllib_parse.urlparse(resp.response.location).query,
    )
    assert int(parsed_qs['start'][0]) > 0
    assert int(parsed_qs['start'][0]) <= timestamp
Пример #3
0
def test_redirect_not_a_redirect():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(status_code=200)),
            mock.sentinel.expected_path,
            mock.sentinel.expected_query,
        )
Пример #4
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        ), ),
        '/foo',
        {'bar': ['baz']},
    )
Пример #5
0
def test_correct_redirect():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=302,
            location='/foo?bar=baz',
        )),
        '/foo',
        {'bar': ['baz']},
    )
Пример #6
0
def test_redirect_wrong_query():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo?bar=baz',
            ), ),
            '/foo',
            {'bar': ['biz']},
        )
Пример #7
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            ), ),
            '/bar',
            {},
        )
Пример #8
0
def test_redirect_custom_status_code():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=303,
            location='/foo',
        ), ),
        '/foo',
        {},
        redirect_status_code=303,
    )
Пример #9
0
def test_redirect_wrong_query():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo?bar=baz',
            )),
            '/foo',
            {'bar': ['biz']},
        )
Пример #10
0
def test_redirect_wrong_path():
    with pytest.raises(AssertionError):
        assert_redirect(
            auto_namedtuple(response=auto_namedtuple(
                status_code=302,
                location='/foo',
            )),
            '/bar',
            {},
        )
Пример #11
0
def test_redirect_custom_status_code():
    assert_redirect(
        auto_namedtuple(response=auto_namedtuple(
            status_code=303,
            location='/foo',
        )),
        '/foo',
        {},
        redirect_status_code=303,
    )
Пример #12
0
def test_all_data_no_data_for_metric(server_with_data):
    resp = server_with_data.server.client.get(flask.url_for(
        'graph.all_data',
        metric_name=SymlinkCount.__name__,
    ))

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=SymlinkCount.__name__),
        {'start': ['0'], 'end': [mock.ANY]},
    )
Пример #13
0
def test_all_data_no_data(server):
    resp = server.client.get(flask.url_for(
        'graph.all_data',
        metric_name=PythonImportCount.__name__,
    ))

    # Should redirect to start of 0
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        {'start': ['0'], 'end': [mock.ANY]},
    )
Пример #14
0
def test_all_data_no_data_for_metric(server_with_data):
    resp = server_with_data.server.client.get(flask.url_for(
        'graph.all_data',
        metric_name=SymlinkCount.__name__,
    ))

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=SymlinkCount.__name__),
        {'start': ['0'], 'end': [mock.ANY]},
    )
Пример #15
0
def test_all_data_no_data(server):
    resp = server.client.get(
        flask.url_for(
            'graph.all_data',
            metric_name=PythonImportCount.__name__,
        ),
    )

    # Should redirect to start of 0
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        {'start': ['0'], 'end': [mock.ANY]},
    )
Пример #16
0
def test_all_data(server_with_data):
    resp = server_with_data.server.client.get(
        flask.url_for(
            'graph.all_data',
            metric_name=PythonImportCount.__name__,
        ), )

    # Should redirect to a show url
    assert_redirect(
        resp,
        flask.url_for('graph.show', metric_name=PythonImportCount.__name__),
        # Tested more explicitly below
        mock.ANY,
    )
    # This part is a bit racey due to how the commits were made.
    # Instead of opting for more-exact timing here, I decided to unit test
    # the underlying function and give a fuzzy check here.  The important part
    # about this endpoint is it redirects to a show url and doesn't start at 0
    timestamp = server_with_data.cloneable_with_commits.commits[-1].date
    parsed_qs = urllib.parse.parse_qs(
        urllib.parse.urlparse(resp.response.location).query, )
    assert int(parsed_qs['start'][0]) > 0
    assert int(parsed_qs['start'][0]) <= timestamp