示例#1
0
def test_no_token(client: Client, settings, dummy_server: DummyServer):
    settings.recaptcha_url = f'{dummy_server.server_name}/recaptcha_url/'
    assert client.get_json('/') == {'app': 'foxglove-demo'}
    assert client.post_json('/captcha-check/', {}, status=400) == {
        'message': 'No recaptcha value'
    }
    assert dummy_server.log == []
示例#2
0
def test_errors_raise_unexpected(client: Client, caplog):
    assert client.get_json('/error/', status=400) == {'message': 'raised HttpBadRequest'}
    assert len(caplog.records) == 1, caplog.text
    assert '"GET /error/", unexpected response: 400' in caplog.text
    r = caplog.records[0]
    assert r.user == {'ip_address': 'testclient'}
    assert r.request['url'] == 'http://testserver/error/'
    assert r.extra['route_endpoint'] == 'error'
    assert r.extra['response_body'] == {'message': 'raised HttpBadRequest'}
示例#3
0
def test_errors_expected_sentry(client_sentry: Client, caplog, mocker):
    m = mocker.patch('foxglove.middleware.capture_event')
    assert client_sentry.get_json('/error/', status=400) == {'message': 'raised HttpBadRequest'}
    assert len(caplog.records) == 1, caplog.text
    msg = '"GET /error/", unexpected response: 400'
    assert msg in caplog.text

    m.assert_called_once()
    assert m.call_args.args[0]['message'] == msg
    assert m.call_args.args[0]['fingerprint'] == ('/error/', 'GET', '400')
    assert m.call_args.args[1] is None
示例#4
0
def test_errors_request_return_unexpected(client: Client, caplog, mocker):
    m = mocker.patch('foxglove.middleware.capture_event')
    assert client.get_json('/error/', params={'error': 'return'}, status=400) == {'error': 'return'}
    assert len(caplog.records) == 1, caplog.text
    assert '"GET /error/?error=return", unexpected response: 400' in caplog.text
    r = caplog.records[0]
    assert r.user == {'ip_address': 'testclient'}
    assert r.request['url'] == 'http://testserver/error/?error=return'
    assert r.extra['route_endpoint'] == 'error'
    assert r.extra['response_body'] == {'error': 'return'}
    assert m.call_count == 0
示例#5
0
def test_success(client: Client, settings, dummy_server: DummyServer, caplog):
    caplog.set_level(logging.INFO)
    settings.recaptcha_url = f'{dummy_server.server_name}/recaptcha_url/'
    assert client.get_json('/') == {'app': 'foxglove-demo'}
    assert client.post_json('/captcha-check/',
                            {'recaptcha_token': '__ok__'}) == {
                                'status': 'ok'
                            }
    assert dummy_server.log == [
        'POST /recaptcha_url/ > 200 (recaptcha __ok__)'
    ]
    logs = [
        r.message for r in caplog.records if r.name == 'foxglove.recaptcha'
    ]
    assert logs == ['recaptcha success']
示例#6
0
def test_bad_token(client: Client, settings, dummy_server: DummyServer,
                   caplog):
    caplog.set_level(logging.INFO)
    settings.recaptcha_url = f'{dummy_server.server_name}/recaptcha_url/'
    assert client.get_json('/') == {'app': 'foxglove-demo'}
    assert client.post_json('/captcha-check/', {'recaptcha_token': 'bad'},
                            status=400) == {
                                'message': 'Invalid recaptcha value'
                            }
    assert dummy_server.log == ['POST /recaptcha_url/ > 200 (recaptcha bad)']
    logs = [
        r.message for r in caplog.records if r.name == 'foxglove.recaptcha'
    ]
    assert len(logs) == 1
    assert logs[0] == (
        'recaptcha failure, path=/captcha-check/ request_host=testserver ip=testclient '
        'response={"success": false, "hostname": "testserver"}')
示例#7
0
def test_post_index(client: Client):
    client.get_json('/')
    assert client.post_json('/', status=None)
    assert client.last_request.status_code == 405
示例#8
0
def test_index(client: Client):
    assert client.last_request is None
    assert client.get_json('/') == {'app': 'foxglove-demo'}
    assert client.last_request.status_code == 200
示例#9
0
def test_create_user(client: Client):
    client.get_json('/')
    assert client.post_json('/create-user/', {'first_name': 'Samuel', 'last_name': 'Colvin'}, status=201) == {
        'id': 123,
        'v': 16,
    }