Example #1
0
def test_post_product():

    client = app.test_client()

    token = login(client)

    product_data = {
        "product_name": "Nike running shoe",
        "brand": "Nike",
        "category": "Shoes",
        "condition": "Used",
        "description": "Black running shoe",
        "gender": "Unisex",
        "in_stock": True,
        "price": 15.99,
        "size": "8",
        "product_image": "Shoe image"
    }
    request_headers = {"Authorization": f"Bearer {token}"}
    product_response = client.post(
        "/api/products",
        data=json.dumps(product_data),
        content_type="application/json",
        headers=request_headers,
    )

    assert product_response.json["category"] == "Shoes"
Example #2
0
def test_delete_product():
    client = app.test_client()

    token = login(client)

    product_data = {
        "product_name": "Nike running shoe",
        "brand": "Nike",
        "category": "Shoes",
        "condition": "Used",
        "description": "Black running shoe",
        "gender": "Unisex",
        "in_stock": True,
        "price": 15.99,
        "size": "8",
        "product_image": "Shoe image"
    }
    request_headers = {"Authorization": f"Bearer {token}"}
    product_response = client.delete(
        "/api/products/15",
        data=json.dumps(product_data),
        content_type="application/json",
        headers=request_headers,
    )
    print(product_response.json)

    assert product_response.json['message'] == 'Product deleted successfully'
    assert product_response.status_code == 200
Example #3
0
def test_get_profile():
    client = app.test_client()
    token = login(client)
    response = client.get(
        "/api/profile",
        headers= {"Authorization": f"Bearer {token}"},
    )
    assert response.json["username"] == "admin"
Example #4
0
def test_remove_comment():
    client = app.test_client()
    token = login(client)
    request_headers = {"Authorization": f"Bearer {token}"}
    delete_comment_response = client.delete(
        "/api/photos/1/comments/1",
        headers=request_headers,
    )
    assert delete_comment_response.json["id"] == 1
Example #5
0
def test_get_wishlist():
    client = app.test_client()
    token = login(client)
    request_headers = {"Authorization": f"Bearer {token}"}
    wishlist_response = client.get(
        "/api/wishlist/2",
        content_type="application/json",
        headers=request_headers,
    )
    assert len(wishlist_response.json) == 2
    assert wishlist_response.status_code == 200
Example #6
0
def test_create_comment():
    client = app.test_client()
    token = login(client)
    comment_data = {"content": "testing create comment"}
    request_headers = {"Authorization": f"Bearer {token}"}
    comment_response = client.post(
        "/api/photos/1/comments",
        data=json.dumps(comment_data),
        content_type="application/json",
        headers=request_headers,
    )
    assert comment_response.json["content"] == "testing create comment"
Example #7
0
def test_get_all_order_history():

    client = app.test_client()
    token = login(client)
    request_headers = {"Authorization": f"Bearer {token}"}
    response = client.get(
        "/api/users/2/order-history",
        headers=request_headers,
    )

    assert len(response.json) == 2
    assert response.status_code == 200
    assert response.json[0]["product"].get("brand") == "Puma"
Example #8
0
def test_update_comment():
    client = app.test_client()
    token = login(client)
    comment_data = {"content": "I've changed the comment"}
    request_headers = {"Authorization": f"Bearer {token}"}
    update_comment_response = client.put(
        "/api/photos/1/comments/2",
        data=json.dumps(comment_data),
        content_type="application/json",
        headers=request_headers,
    )
    assert update_comment_response.json["comments"][1][
        "content"] == "I've changed the comment"
Example #9
0
def test_delete_wishlist():
    client = app.test_client()
    token = login(client)
    wishlist_data = {"user_id": 2, "product_id": 1}
    request_headers = {"Authorization": f"Bearer {token}"}
    wishlist_response = client.delete(
        "/api/users/2/wishlist/1",
        data=json.dumps(wishlist_data),
        content_type="application/json",
        headers=request_headers,
    )
    assert wishlist_response.json[
        'message'] == 'Wishlist item deleted successfully'
    assert wishlist_response.status_code == 200
Example #10
0
def test_add_wishlist():
    client = app.test_client()
    token = login(client)
    wishlist_data = {"user_id": 2, "product_id": 1}
    request_headers = {"Authorization": f"Bearer {token}"}
    wishlist_response = client.post(
        "/api/users/2/wishlist/1",
        data=json.dumps(wishlist_data),
        content_type="application/json",
        headers=request_headers,
    )
    assert wishlist_response.status_code == 201
    assert wishlist_response.json['user_id'] == 2
    assert wishlist_response.json['product_id'] == 1
Example #11
0
def test_update_user():

    client = app.test_client()

    token = login(client)

    update_request = {"location": "Sydney"}
    request_headers = {"Authorization": f"Bearer {token}"}
    user_response = client.put(
        "/api/users/2",
        data=json.dumps(update_request),
        content_type="application/json",
        headers=request_headers,
    )

    assert user_response.json["location"] == "Sydney"
    assert user_response.status_code == 200
Example #12
0
def test_update_product():

    client = app.test_client()

    token = login(client)

    update_request = {"brand": "Ted Baker"}
    request_headers = {"Authorization": f"Bearer {token}"}
    product_response = client.put(
        "/api/products/5",
        data=json.dumps(update_request),
        content_type="application/json",
        headers=request_headers,
    )

    assert product_response.json["brand"] == "Ted Baker"
    assert product_response.status_code == 200
Example #13
0
def test_upload_photo():

    client = app.test_client()
    token = login(client)

    photo_data = {
        "url": "https://photo.com",
        "caption": "Great photo",
        "rating": 4
    }
    request_headers = {"Authorization": f"Bearer {token}"}
    photo_response = client.post(
        "/api/photos",
        data=json.dumps(photo_data),
        content_type="application/json",
        headers=request_headers,
    )

    assert photo_response.json["caption"] == "Great photo"
Example #14
0
def test_post_item():
    client = app.test_client()
    token = login(client)
    header = {'Authorization': f'Bearer {token}'}
    item_data = {
        "name": "Tissue",
        "typeof": "goods",
        "category": "misc",
        "private": True,
        "available": True
    }
    response = client.post("/api/items",
                           data=json.dumps(item_data),
                           content_type="application/json",
                           headers=header)
    assert response.status_code == 200
    assert response.json['name'] == 'Tissue'
    assert response.json['category'] == 'misc'
    item_id = response.json['id']

    def test_get_items_middle():
        client = app.test_client()
        response = client.get("/api/items")
        assert len(response.json) == 5
        assert response.status_code == 200

    def test_delete_item(item_id, header):
        client = app.test_client()
        header = {'Authorization': f'Bearer {token}'}
        response = client.delete(f"/api/items/{item_id}", headers=header)
        assert response.status_code == 200

    def test_get_items_after():
        client = app.test_client()
        response = client.get("/api/items")
        assert len(response.json) == 6
        assert response.status_code == 200