def test_post_response(client, redis_conn): response = {'user_id': 1, 'response': 'accepted'} with patch.object(redis_conn, 'hmset') as redis_hmset: r = client.post('/messages/' + _DUMMY_CLIENT_ID, json=response, headers=with_auth()) assert r.status == '200 OK' redis_hmset.assert_called_with(f'response:{_DUMMY_CLIENT_ID}:1', {'response': 'accepted', 'public_id': 'hashof1'})
def test_post_location_validates_arg_presence(client, redis_map, redis_conn): r = client.post(f'/locations/123', json={'foo': 'bar', 'nick': 'Abe'}, headers=with_auth()) json = r.get_json() assert r.status == '400 BAD REQUEST' assert json['error'] assert json['message'].startswith('invalid longitude')
def test_post_location_updates_existing(client, redis_map, map_with_data): original = redis_map.get_locations_named(24, 60)[0] assert original.coordinate.longitude == 24.93545 assert original.nick == "Abe" data = { 'latitude': 60.16952, 'longitude': 30.00000, 'nick': 'Changed' } r = client.post(f'/locations/1', json=data, headers=with_auth()) new = redis_map.get_locations_named(24, 60)[0] assert new.coordinate.longitude == 30.00000 assert new.nick == "Changed"
def test_post_location(client, redis_map, redis_conn): user_id = 123 data = { 'latitude': 60.16952, 'longitude': 24.93545, 'nick': 'Changed' } r = client.post(f'/locations/{user_id}', json=data, headers=with_auth()) assert len(redis_conn.data['loc']) == 1 location = redis_conn.data['loc']['hashof123'] assert location[0] == 24.93545 assert location[1] == 60.16952 assert redis_conn.get('nick:hashof123') == 'Changed'
def test_post_location_validates_coordnates(client, redis_map, redis_conn): # Valid coordinates r = client.post(f'/locations/123', json={'longitude': 24.93545, 'latitude': 60.16952, 'nick': 'Abe'}, headers=with_auth()) assert r.status == '200 OK' # Invalid longitude r = client.post(f'/locations/123', json={'longitude': 181.0000, 'latitude': 60.16952, 'nick': 'Abe'}, headers=with_auth()) json = r.get_json() assert r.status == '400 BAD REQUEST' assert json['error'] assert json['message'].startswith('invalid longitude') # Invalid latitude r = client.post(f'/locations/123', json={'longitude': 24.93545, 'latitude': 91.000000, 'nick': 'Abe'}, headers=with_auth()) json = r.get_json() assert r.status == '400 BAD REQUEST' assert json['message'].startswith('invalid latitude')
def test_get_response_is_json(client): r = client.get('/locations', headers=with_auth()) assert r.headers["Content-Type"] == "application/json"
def test_post_authentication_works(client): r = client.post(f'/locations/123?latitude=60.0&longitude=24.0&nick=B%20A', headers=with_auth()) assert r.status == '200 OK'
def test_remove_location(client, redis_map, redis_conn, map_with_data): assert len(redis_conn.data['loc']) == 2 r = client.delete(f'/locations/1', headers=with_auth()) assert len(redis_conn.data['loc']) == 1