Ejemplo n.º 1
0
def test_read_brand(client: TestClient, db: Session) -> None:
    brand = create_random_brand(db)
    response = client.get(f"{settings.API_V1_STR}/brands/{brand.id}", )
    assert response.status_code == 200
    content = response.json()
    assert content["name"] == brand.name
    assert content["id"] == brand.id
Ejemplo n.º 2
0
def test_create_product(db: Session) -> None:
    name = random_lower_string()
    category = create_random_product_category(db)
    brand = create_random_brand(db)

    product_in = ProductCreate(name=name, category_id=category.id, brand_id=brand.id)
    product = crud.product.create(db=db, obj_in=product_in)

    assert product.name == name
Ejemplo n.º 3
0
def test_delete_brand(client: TestClient, db: Session) -> None:
    brand = create_random_brand(db)
    response = client.delete(f"{settings.API_V1_STR}/brands/{brand.id}", )
    assert response.status_code == 200
    content = response.json()
    assert content["name"] == brand.name
    assert content["id"] == brand.id

    brand2 = crud.brand.get(db=db, id=brand.id)
    assert not brand2
Ejemplo n.º 4
0
def test_fail_on_create_duplicate_brand(client: TestClient,
                                        db: Session) -> None:
    brand = create_random_brand(db)
    data = {"name": brand.name}
    response = client.post(
        f"{settings.API_V1_STR}/brands/",
        json=data,
    )

    assert response.status_code == 400
Ejemplo n.º 5
0
def test_delete_product(db: Session) -> None:
    name = random_lower_string()
    category = create_random_product_category(db)
    brand = create_random_brand(db)

    product_in = ProductCreate(name=name, category_id=category.id, brand_id=brand.id)
    product = crud.product.create(db=db, obj_in=product_in)
    product2 = crud.product.remove(db=db, id=product.id)
    product3 = crud.product.get(db=db, id=product.id)

    assert product3 is None
    assert product2.id == product.id
    assert product2.name == name
Ejemplo n.º 6
0
def test_create_product(client: TestClient, db: Session) -> None:
    name = random_lower_string()
    category = create_random_product_category(db)
    brand = create_random_brand(db)

    data = {"name": name, "category_id": category.id, "brand_id": brand.id}
    response = client.post(
        f"{settings.API_V1_STR}/products/",
        json=data,
    )
    assert response.status_code == 200
    content = response.json()
    assert content["name"] == data["name"]
    assert "id" in content
Ejemplo n.º 7
0
def test_update_product(db: Session) -> None:
    name = random_lower_string()
    category = create_random_product_category(db)
    brand = create_random_brand(db)

    product_in = ProductCreate(name=name, category_id=category.id, brand_id=brand.id)
    product = crud.product.create(db=db, obj_in=product_in)

    name2 = random_lower_string()
    product_update = ProductUpdate(name=name2)
    product2 = crud.product.update(db=db, db_obj=product, obj_in=product_update)

    assert product.id == product2.id
    assert product.name == product2.name
    assert product2.name == name2
Ejemplo n.º 8
0
def test_read_brands(client: TestClient, db: Session) -> None:
    brand = create_random_brand(db)
    # this will fail if the test-database is never cleaned up
    limit = int(1e6)
    response = client.get(f"{settings.API_V1_STR}/brands?limit={limit}", )
    assert response.status_code == 200
    content = response.json()

    found_brand = None
    for brand_in_result in content:
        if brand.id == brand_in_result["id"]:
            found_brand = brand_in_result
            break

    assert found_brand
    assert found_brand["name"] == brand.name
Ejemplo n.º 9
0
def test_fail_on_create_duplicate_product(client: TestClient,
                                          db: Session) -> None:
    product = create_random_product(db)
    category = create_random_product_category(db)
    brand = create_random_brand(db)

    data = {
        "name": product.name,
        "category_id": category.id,
        "brand_id": brand.id
    }
    response = client.post(
        f"{settings.API_V1_STR}/products/",
        json=data,
    )

    assert response.status_code == 400