def get_category(client, category_id): response = client.get( '/categories/{}'.format(category_id), headers=create_request_headers(), ) json_response = load_decoded_response(response) return response, json_response
def test_fail_to_delete_item_missing_token(client): response = client.delete('/categories/{}/items/{}'.format(1, 1), headers=create_request_headers(access_token=None)) json_response = load_decoded_response(response) assert response.status_code == 400 assert json_response['message'] == 'Missing Token'
def add_items(client, authentication=None, category_id=None, data=None): access_token = get_access_token(client, authentication) response = client.post( '/categories/{}/items'.format(category_id), headers=create_request_headers(access_token=access_token), data=json.dumps(data)) json_response = load_decoded_response(response) return response, json_response
def test_get_categories_successfully(client): response = client.get( '/categories', headers=create_request_headers(), ) json_response = load_decoded_response(response) assert response.status_code == 200 for category in json_response: assert all(key in category for key in ['id', 'name', 'description', 'created']) is True
def test_fail_to_add_items_missing_token(client): response = client.post('/categories/{}/items'.format(1), headers=create_request_headers(access_token=None), data=json.dumps({ 'name': 'Matrix 2', 'description': '1998' })) json_response = load_decoded_response(response) assert response.status_code == 400 assert json_response['message'] == 'Missing Token'
def test_fail_to_put_item_invalid_token(client): response = client.put('/categories/{}/items/{}'.format(1, 1), headers=create_request_headers(access_token='a' * 140), data=json.dumps({ 'name': 'Kong', 'description': '2005' })) json_response = load_decoded_response(response) assert response.status_code == 400 assert json_response['message'] == 'Invalid Token'
def register_user(client, information): """ Send request to register user :param information :param client """ response = client.post('/users', headers=create_request_headers(), data=json.dumps(information)) json_response = load_decoded_response(response) return response, json_response
def authorize_user(client, authentication): """ Send request to log in user :param authentication :param client """ response = client.post('/auth', headers=create_request_headers(), data=json.dumps(authentication)) json_response = load_decoded_response(response) return response, json_response
def delete_item(client, authentication=None, category_id=None, item_id=None): access_token = get_access_token(client, authentication) response = client.delete( '/categories/{}/items/{}'.format(category_id, item_id), headers=create_request_headers(access_token=access_token)) return response
def add_categories(client, data): response = client.post('/categories', headers=create_request_headers(), data=json.dumps(data)) json_response = load_decoded_response(response) return response, json_response