Ejemplo n.º 1
0
def test_remove_category_as_normal_user_returns_400(
        client: TestClient, test_itemtype, normal_user_token_headers: dict,
        db: Session) -> None:
    category = create_random_category(db, test_itemtype)

    response = client.delete(BASE_URL + f"{category.id}",
                             headers=normal_user_token_headers)
    _assert_error(response, 400, "Not enough permissions")
Ejemplo n.º 2
0
def test_read_category(client: TestClient, test_itemtype,
                       superuser_token_headers: dict, db: Session) -> None:
    category = create_random_category(db, test_itemtype)
    response = client.get(BASE_URL + f"{category.id}",
                          headers=superuser_token_headers)
    assert response.status_code == 200
    content = response.json()
    assert content["title_en"] == category.title_en
    assert content["id"] == category.id
Ejemplo n.º 3
0
def test_update_category(client: TestClient, test_itemtype,
                         superuser_token_headers: dict, db: Session) -> None:
    category = create_random_category(db, test_itemtype)

    update_data = {"title_en": random_string(length=25)}
    response = client.put(BASE_URL + f"{category.id}",
                          headers=superuser_token_headers,
                          json=update_data)
    assert response.status_code == 200
    content = response.json()
    assert content["title_en"] == update_data["title_en"]
Ejemplo n.º 4
0
def test_update_category_with_too_short_name_returns_422(
        client: TestClient, test_itemtype, superuser_token_headers: dict,
        db: Session) -> None:
    category = create_random_category(db, test_itemtype)

    update_data = {"title_en": random_string(length=2)}
    response = client.put(BASE_URL + f"{category.id}",
                          headers=superuser_token_headers,
                          json=update_data)
    assert response.status_code == 422
    content = response.json()
    assert "at least 3 characters" in content["detail"][0]["msg"]
Ejemplo n.º 5
0
def test_category(db, test_itemtype):
    yield create_random_category(db=db, itemtype=test_itemtype)