def test_update_product_not_found(client): location_id = 1 path = '/texada_gps/api/locations/{}'.format(location_id) non_existent_product_id = 10000 latitude = 90.52 longitude = 86.75 elevation = 550 location = _to_json(product_id=non_existent_product_id, latitude=latitude, longitude=longitude, elevation=elevation, visit_date=datetime.datetime.utcnow()) response = client.put(path, data=json.dumps(location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 404 expected = { 'errorMessage': 'No product with id {} was found.'.format(non_existent_product_id), 'errorCode': 404 } assert expected == json.loads(response.data)
def test_update_field_required(client, required_field_name): location_id = 1 path = '/texada_gps/api/locations/{}'.format(location_id) product_id = 1 latitude = 90.52 longitude = 86.75 elevation = 550 visit_date = datetime.datetime.utcnow() location = _to_json(product_id=product_id, latitude=latitude, longitude=longitude, elevation=elevation, visit_date=visit_date) # We are deleting the required field from this JSON object so as to test that a # bad request error will occur if this field were omitted in the JSON object # sent to the server. del location[required_field_name] response = client.put(path, data=json.dumps(location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) expected = { 'errorMessage': 'The {} field is required.'.format(required_field_name), 'errorCode': 400 } assert expected == json.loads(response.data)
def test_update(client): location_id = 1 path = '/texada_gps/api/locations/{}'.format(location_id) product_id = 1 latitude = 90.52 longitude = 86.75 elevation = 550 now = datetime.datetime.now() # We want to discard the part of the date after the microsecond to facilitate testing visit_date = datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second).astimezone(timezone('UTC')) location = _to_json(product_id=product_id, latitude=latitude, longitude=longitude, elevation=elevation, visit_date=visit_date) response = client.put(path, data=json.dumps(location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 200
def test_create_field_required(client, required_field_name): path = '/texada_gps/api/locations/' new_location = _construct_new_location() # We are deleting the required field from this JSON object so as to test that a # bad request error will occur if this field were omitted in the JSON object # sent to the server. del new_location[required_field_name] # No latitude has been included in the JSON sent to the server. Therefore, a bad request error will occur. response = client.post(path, data=json.dumps(new_location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 400 expected = { 'errorMessage': 'The {} field is required.'.format(required_field_name), 'errorCode': 400 } assert expected == json.loads(response.data)
def test_create(client): path = '/texada_gps/api/products/' response = client.post(path, data=json.dumps( dict(description='Hubble Space Telescope')), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 201
def test_create(client): path = '/texada_gps/api/locations/' new_location = _construct_new_location() response = client.post(path, data=json.dumps(new_location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 201
def test_delete(client): product_id = 1 path = '/texada_gps/api/products/{}'.format(product_id) response = client.delete(path, content_type='application/json', headers=get_authentication_header( 'admin', 'admin')) assert response.status_code == 200 assert json.loads(response.data) == {'result': True}
def test_update(client): product_id = 1 path = '/texada_gps/api/products/{}'.format(product_id) description = 'GOES-12' response = client.put(path, data=json.dumps(dict(description=description)), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 200
def test_delete_entity_not_found(client): product_id = 100000 path = '/texada_gps/api/products/{}'.format(product_id) response = client.delete(path, content_type='application/json', headers=get_authentication_header( 'admin', 'admin')) assert response.status_code == 404 expected = { 'errorMessage': 'No product with id {} was found.'.format(product_id), 'errorCode': 404 } assert expected == json.loads(response.data)
def test_create_description_required(client): path = '/texada_gps/api/products/' # No description has been included in the JSON sent to the server. Therefore, a bad request error will occur. response = client.post( path, data=json.dumps(dict({'sample_field_name': 'sample_field_value'})), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 400 expected = { 'errorMessage': 'The description field is required.', 'errorCode': 400 } assert expected == json.loads(response.data)
def test_update_entity_not_found(client): product_id = 100000 path = '/texada_gps/api/products/{}'.format(product_id) description = 'GOES-12' response = client.put(path, data=json.dumps(dict(description=description)), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 404 expected = { 'errorMessage': 'No product with id {} was found.'.format(product_id), 'errorCode': 404 } assert expected == json.loads(response.data)
def test_create_product_not_found(client): path = '/texada_gps/api/locations/' non_existent_product_id = 10000 new_location = _construct_new_location() new_location['product_id'] = non_existent_product_id response = client.post(path, data=json.dumps(new_location), content_type='application/json', headers=get_authentication_header('admin', 'admin')) assert response.status_code == 404 expected = { 'errorMessage': 'No product with id {} was found.'.format(non_existent_product_id), 'errorCode': 404 } assert expected == json.loads(response.data)