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 == []
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']
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"}')
def test_post_index(client: Client): client.get_json('/') assert client.post_json('/', status=None) assert client.last_request.status_code == 405
def test_no_session_id(client: Client): assert client.post_json('/create-user/', {'first_name': 'Samuel', 'last_name': 'Colvin'}, status=403) == { 'message': 'Permission Denied, no session set, updates not permitted' }
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, }
def test_request_error(client: Client, mocker): fail_mock = mocker.patch('foxglove.testing.pytest.fail') client.post_json('/') fail_mock.called_once()
def test_index(client: Client): assert client.post_json('/no-csrf/') is None assert client.last_request.status_code == 200