예제 #1
0
def test_restaurant_delete(client):
    token = get_valid_token(client)
    restaurant1 = add_restaurant(client, "restaurant 1", "*****@*****.**")
    restId = restaurant1.id
    response = client.delete(f"/api/v1/restaurant/{restaurant1.id}",
                             headers=token_headers(token),
                             content_type="application/json")
    assert_json_status(response, 204)

    # following request for same restaurant should return 404
    url = f"/api/v1/restaurant/{restId}"
    response = client.get(
        url,
        headers=token_headers(token),
        content_type="application/json",
    )
    assert_json_status(response, 404)

    # count of stored restaurant should be 0

    response = client.get(
        "/api/v1/restaurant",
        headers=token_headers(token),
        content_type="application/json",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert len(data) == 0
예제 #2
0
def test_signup_success(client):
    response = signup_user(
        client=client,
        username="******",
        email="*****@*****.**",
        password="******",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert data["success"] == True
예제 #3
0
def test_access_protected_endpoint_with_valid_token(client):
    token = get_valid_token(client)
    response = client.get(
        "/protected",
        headers=dict(Authorization="Bearer " + token),
        content_type="application/json",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert data["message"] == "Protected message"
예제 #4
0
def test_vote_list(client):
    token = get_valid_token(client)
    response = client.get(
        "/api/v1/vote",
        headers=token_headers(token),
        content_type="application/json",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert not data
예제 #5
0
def test_restaurant_list(client):
    token = get_valid_token(client)
    response = client.get(
        "/api/v1/restaurant",
        headers=dict(Authorization="Bearer " + token),
        content_type="application/json",
    )
    assert_success_200(response)
    data = json.loads(response.data)
    assert data == []
예제 #6
0
def test_login_success(client):
    username = "******"
    email = "*****@*****.**"
    password = "******"
    signup_user(client=client,
                username=username,
                email=email,
                password=password)
    response = login_user(client=client, username=username, password=password)
    assert_success_200(response)
    data = json.loads(response.data)
    assert data["token"]
예제 #7
0
def test_logout(client):
    token = get_valid_token(client)
    response = client.post(
        "/api/v1/auth/logout",
        headers=dict(Authorization="Bearer " + token),
        content_type="application/json",
    )
    assert_success_200(response)
    response_protected = client.get(
        "/protected",
        headers=dict(Authorization="Bearer " + token),
        content_type="application/json",
    )
    assert_error_token_expired(response_protected)
예제 #8
0
def test_ping(client):
    response = client.get("/ping")
    data = json.loads(response.data)
    assert_success_200(response)
    assert data["status"] == "running"