Пример #1
0
def test_get_customer_details(access_token):
    customer_id = api.create_customer_returning_id('Eve', '*****@*****.**',
                                                   access_token)

    product_id = '1bf0f365-fbdd-4e21-9786-da459d78dd1f'
    other_product_id = '6a512e6c-6627-d286-5d18-583558359ab6'

    api.add_product_to_wishlist(customer_id, product_id, access_token)
    api.add_product_to_wishlist(customer_id, other_product_id, access_token)

    expected_response = {
        'id':
        customer_id,
        'name':
        'Eve',
        'email':
        '*****@*****.**',
        'wishlist': [
            '1bf0f365-fbdd-4e21-9786-da459d78dd1f',
            '6a512e6c-6627-d286-5d18-583558359ab6',
        ],
    }

    response = api.get_customer(customer_id, access_token)

    assert response.status_code == 200
    assert response.json() == expected_response
Пример #2
0
def test_delete_customer(access_token):
    customer_id = api.create_customer_returning_id('Bob', '*****@*****.**',
                                                   access_token)

    response = api.delete_customer(customer_id, access_token)

    assert response.status_code == 204
    assert response.text == ''
Пример #3
0
def test_update_customer_with_email_of_another_customer(access_token):
    email = '*****@*****.**'
    customer_id = api.create_customer_returning_id('Dana', '*****@*****.**',
                                                   access_token)
    api.create_customer_returning_id('Paula', email, access_token)

    response = api.update_customer(customer_id, {
        'name': 'Dana',
        'email': '*****@*****.**'
    }, access_token)

    expected_response = {
        'code': 'CUSTOMER_ALREADY_REGISTERED',
        'message': f'Already exists a customer registered with email {email}',
    }

    assert response.status_code == 422
    assert response.json() == expected_response
Пример #4
0
def test_delete_inexistent_customer(access_token):
    customer_id = api.create_customer_returning_id('Eric', '*****@*****.**',
                                                   access_token)

    api.delete_customer(customer_id, access_token)
    response = api.delete_customer(customer_id, access_token)

    assert response.status_code == 404
    expected_response = {
        'code': 'CUSTOMER_NOT_FOUND',
        'message': f'Customer with id {customer_id} not found',
    }
    assert response.json() == expected_response
Пример #5
0
def test_list_customers_returns_ok(access_token):
    customer_id = api.create_customer_returning_id('Marta', '*****@*****.**',
                                                   access_token)

    response = api.list_customers(access_token)
    expec_customer_in_list = {
        'id': customer_id,
        'name': 'Marta',
        'email': '*****@*****.**',
    }

    assert response.status_code == 200
    assert expec_customer_in_list in response.json()
Пример #6
0
def test_add_product_to_wishlist_returns_created(access_token):
    customer_id = api.create_customer_returning_id('John', '*****@*****.**',
                                                   access_token)

    product_id = '1bf0f365-fbdd-4e21-9786-da459d78dd1f'
    other_product_id = '6a512e6c-6627-d286-5d18-583558359ab6'

    api.add_product_to_wishlist(customer_id, product_id, access_token)
    response = api.add_product_to_wishlist(customer_id, other_product_id,
                                           access_token)

    assert response.status_code == 201
    assert product_id in response.json()['wishlist']
    assert other_product_id in response.json()['wishlist']
Пример #7
0
def test_remove_product_to_wishlist_returns_no_content(access_token):
    customer_id = api.create_customer_returning_id('Ana', '*****@*****.**',
                                                   access_token)

    product_id = '1bf0f365-fbdd-4e21-9786-da459d78dd1f'
    other_product_id = '6a512e6c-6627-d286-5d18-583558359ab6'

    api.add_product_to_wishlist(customer_id, product_id, access_token)
    api.add_product_to_wishlist(customer_id, other_product_id, access_token)
    response = api.remove_product_from_wishlist(customer_id, product_id,
                                                access_token)

    assert response.status_code == 200
    assert product_id not in response.json()['wishlist']
    assert other_product_id in response.json()['wishlist']
Пример #8
0
def test_update_customer_inexistent(access_token):
    customer_id = api.create_customer_returning_id('Cris', '*****@*****.**',
                                                   access_token)
    api.delete_customer(customer_id, access_token)
    response = api.update_customer(customer_id, {
        'name': 'Cristine',
        'email': '*****@*****.**'
    }, access_token)

    expected_response = {
        'code': 'CUSTOMER_NOT_FOUND',
        'message': f'Customer with id {customer_id} not found',
    }

    assert response.status_code == 404
    assert response.json() == expected_response
Пример #9
0
def test_update_customer_with_success(access_token):
    customer_id = api.create_customer_returning_id('Harry', '*****@*****.**',
                                                   access_token)
    response = api.update_customer(customer_id, {
        'name': 'Harry C',
        'email': '*****@*****.**'
    }, access_token)

    expected_response = {
        'id': customer_id,
        'name': 'Harry C',
        'email': '*****@*****.**',
    }

    assert response.status_code == 200
    assert response.json() == expected_response
Пример #10
0
def test_get_details_from_inexistent_customer(access_token):
    customer_id = api.create_customer_returning_id('Martin',
                                                   '*****@*****.**',
                                                   access_token)

    api.delete_customer(customer_id, access_token)

    expected_response = {
        'code': 'CUSTOMER_NOT_FOUND',
        'message': f'Customer with id {customer_id} not found',
    }

    response = api.get_customer(customer_id, access_token)

    assert response.status_code == 404
    assert response.json() == expected_response
Пример #11
0
def test_cannot_add_inexistent_product_to_wishlist(access_token):
    customer_id = api.create_customer_returning_id('Joe', '*****@*****.**',
                                                   access_token)

    product_id = '5ddbc2b9-1186-4c38-b65e-ce8949ee91b5'

    api.add_product_to_wishlist(customer_id, product_id, access_token)
    response = api.add_product_to_wishlist(customer_id, product_id,
                                           access_token)

    expected_response = {
        'code': 'PRODUCT_NOT_FOUND',
        'message': f'Product with id {product_id} not found',
    }

    assert response.status_code == 404
    assert response.json() == expected_response
Пример #12
0
def test_same_product_cannot_added_twice_to_wishlist(access_token):
    customer_id = api.create_customer_returning_id('Mary', '*****@*****.**',
                                                   access_token)

    product_id = '1bf0f365-fbdd-4e21-9786-da459d78dd1f'

    api.add_product_to_wishlist(customer_id, product_id, access_token)
    response = api.add_product_to_wishlist(customer_id, product_id,
                                           access_token)

    expected_response = {
        'code': 'PRODUCT_ALREADY_ADDED',
        'message': f'Product with id {product_id} already added to wishlist',
    }

    assert response.status_code == 422
    assert response.json() == expected_response
Пример #13
0
def test_update_customer_with_invalid_input(access_token):
    customer_id = api.create_customer_returning_id('Lucas', '*****@*****.**',
                                                   access_token)

    response = api.update_customer(customer_id, {
        'name': 'Dana',
        'email': 'paula@gmailcom'
    }, access_token)

    response_json = response.json()

    expected_response = {
        'code': 'VALIDATION_ERROR',
        'errors': {
            'email': ['Not a valid email address.']
        },
        'message': 'Validation error',
    }

    assert response_json == expected_response
    assert response.status_code == 422