def test_bad_login(client):
    assert client.post('/login', json={
        'username': '******',
        'password': '******'
    }).data == bytes(
        json.dumps(
            {'error': 'There is no user with this username and password.'}),
        'utf-8')
Exemplo n.º 2
0
def test_admin_create_recipe(client, admin_headers):
    '''Creating recipe with admin token'''
    recipe = {
        'name': 'Pizza',
        'procedure': 'Pizza making procedure',
        'time': 30
    }
    response = client.post('/recipes', json=recipe, headers=admin_headers)
    assert response.status_code == 200
Exemplo n.º 3
0
def test_readonly_create_recipe(client, readonly_headers):
    '''Creating a recipe with read only token is denied'''
    recipe = {
        'name': 'Pizza',
        'procedure': 'Pizza making procedure',
        'time': 30
    }
    response = client.post('/recipes', json=recipe, headers=readonly_headers)
    assert response.status_code == 401
def test_good_login(client):
    response = client.post('/login',
                           json={
                               'username': '******',
                               'password': '******'
                           }).data.decode('utf-8')
    assert response == json.dumps({
        'token':
        'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJwcm9maWxlIjp7InVzZXJuYW1lIjoiZ3JhbmRfbWFndXMiLCJmaXJzdE5hbWUiOiJSZWdpbmFsZCIsImxhc3ROYW1lIjoiTWNGYW5jeXBhbnRzIn0sInJvbGUiOiJhZG1pbmlzdHJhdG9yIn0.ly954u9VOb5ol9BUkUCabLCFWLSVp67AFw6PnZuMYv3PDVxVOxxUVSTxvUt6WI5BV4VEFfIRtduuSIfmrFaUfesypTvuZkXqdlakb8oed9rSLreWPYlMeH8AOXMhAPS5tO0kRQEffY4ef77lGop96RUFiB9csZ_toZmHB3ydRb0'
    })
Exemplo n.º 5
0
def test_trips_page_empty_post(client):
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
    )
    # Assumes that it will return a 500 response
    assert rv.status_code == 500
    # Assumes that it will return server error
    assert rv.json == {"error": "server error"}
Exemplo n.º 6
0
def test_trips_page_empty_trip_post(client):
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
        json={"cards": ""}
    )
    # Assumes that it will return a 200 response
    assert rv.status_code == 200
    # Assumes that it will return no trips planned
    assert rv.json['cards'] == ['No trips planned yet.', ]
Exemplo n.º 7
0
def test_trips_page_wrong_body_post(client):
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
        json={"cards": [{}]}
    )
    # Assumes that it will return a 400 response
    assert rv.status_code == 400
    # Assumes that it will return error invalid input
    assert rv.json == {"error": "invalid input",
                       "message": "Wrong parameters in JSON."}
Exemplo n.º 8
0
def test_trips_page_post_ok(client):
    body_ok = {"cards":
               [
                   {"transport_type": "airportbus",
                    "origin": "Barcelona",
                    "destination": "Girona Airport"},
                   {"transport_type": "plane",
                       "origin": "Girona Airport",
                       "destination": "Stockholm",
                       "transport_no": "SK455",
                       "seat": "3A",
                       "gate": "45B",
                       "baggage_drop": 344},
                   {"transport_type": "train",
                       "origin": "Madrid",
                       "destination": "Barcelona",
                       "seat": "45B",
                       "transport_no": "78A"},
                   {"transport_type": "plane",
                       "origin": "Stockholm",
                       "transport_no": "SK22",
                       "destination": "New York",
                       "seat": "7B",
                       "gate": "22"}
               ]
               }
    response_ok = {
        "cards": [
            "Take train 78A from Madrid to Barcelona. Sit in seat 45B.",
            "Take the airport bus from Barcelona to Girona Airport. No seat assignment.",
            "From Girona Airport, take flight SK455 to Stockholm. Gate 45B, seat 3A. Baggage drop at ticket counter 344.",
            "From Stockholm, take flight SK22 to New York. Gate 22, seat 7B. ",
            "You have arrived at your final destination."
        ]
    }
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
        json=body_ok
    )
    # Assumes that it will return a 200 response
    assert rv.status_code == 200
    # # Assumes that it will return valid response
    assert rv.json == response_ok
Exemplo n.º 9
0
def test_trips_page_unlinked_stages_post(client):
    body_unlinked_stages = {"cards":
                            [
                                {"transport_type": "airportbus",
                                 "origin": "Barcelona",
                                 "destination": "Girona Airport"},
                                {"transport_type": "airportbus",
                                 "origin": "Katowice",
                                 "destination": "Warsaw"},
                            ]
                            }
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
        json=body_unlinked_stages
    )
    # Assumes that it will return a 400 response
    assert rv.status_code == 400
    # Assumes that it will return error invalid input
    assert rv.json == {"error": "invalid input",
                       "message": "Broken chain between all the legs of the trip. Lack of one origin."}
Exemplo n.º 10
0
def test_trips_page_wrong_tranport_type_post(client):
    # uses wrong tranport_type 'nonexist'
    body_wrong_transport_type = {"cards":
                                 [
                                     {"transport_type": "nonexist",
                                      "origin": "Barcelona",
                                      "destination": "Girona Airport"},
                                     {"transport_type": "airportbus",
                                         "origin": "Barcelona",
                                         "destination": "Warsaw"},
                                 ]
                                 }
    # Assumses that it has a path of "/api/v1.0/trips/"
    test_url = url+'/api/v1.0/trips/'
    rv = client.post(
        test_url,
        content_type='application/json',
        json=body_wrong_transport_type
    )
    # Assumes that it will return a 400 response
    assert rv.status_code == 400
    # Assumes that it will return error invalid input
    assert rv.json == {"error": "invalid input",
                       "message": "Bad transport type 'nonexist'"}
Exemplo n.º 11
0
def test_chef_post_dish(client, chef_header, test_dish):
    res = client.post('/dish', json=test_dish, headers=chef_header)
    assert res.status_code == 200
Exemplo n.º 12
0
def test_manager_post_dish_unauthorized(client, manager_header, test_dish):
    res = client.post('/dish', json=test_dish, headers=manager_header)
    assert res.status_code == 401
Exemplo n.º 13
0
def test_public_post_dish_unauthorized(client, test_dish):
    res = client.post('/dish', json=test_dish)
    assert res.status_code == 401