Ejemplo n.º 1
0
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'
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def test_fail_to_delete_item_invalid_data(client, authentication, category_id,
                                          item_id, status_code, message):
    response = delete_item(client,
                           authentication=authentication,
                           category_id=category_id,
                           item_id=item_id)
    json_response = load_decoded_response(response)

    assert response.status_code == status_code
    assert json_response['message'] == message
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
Ejemplo n.º 6
0
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'
Ejemplo n.º 7
0
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'
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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 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