コード例 #1
0
def test_delete_item(db: Session) -> None:
    user = create_random_user(db)
    collection = create_random_collection(user)
    item = create_random_item(user, collection)
    services.item.delete_item(InternalUserDTO(**user.dict()), item.uuid)
    with pytest.raises(ModelNotFoundError):
        services.item.get_item(InternalUserDTO(**user.dict()), item.uuid)
コード例 #2
0
def test_read_item(superuser_token_headers):
    item = create_random_item()
    server_api = get_server_api()
    response = requests.get(
        f"{server_api}{config.API_V1_STR}/items/{item.id}",
        headers=superuser_token_headers,
    )
    content = response.json()
    assert content["title"] == item.title
    assert content["description"] == item.description
    assert content["id"] == item.id
    assert content["owner_username"] == item.owner_username
コード例 #3
0
def test_get_item(db: Session) -> None:
    user = create_random_user(db)
    collection = create_random_collection(user)
    item = create_random_item(user, collection)

    stored_item = Item.from_dto(
        services.item.get_item(InternalUserDTO(**user.dict()), item.uuid))
    assert stored_item
    assert item.uuid == stored_item.uuid
    assert item.geometry == stored_item.geometry
    assert item.properties == stored_item.properties
    assert item.collection_uuid == stored_item.collection_uuid
コード例 #4
0
def test_read_item(
    client: TestClient, superuser_token_headers: dict, db: Session
) -> None:
    item = create_random_item(db)
    response = client.get(
        f"{settings.API_V1_STR}/items/{item.id}", headers=superuser_token_headers,
    )
    assert response.status_code == 200
    content = response.json()
    assert content["title"] == item.title
    assert content["description"] == item.description
    assert content["id"] == item.id
    assert content["owner_id"] == item.owner_id
コード例 #5
0
def test_read_item(client: TestClient, superuser_token_headers: dict,
                   db: Session, test_itemtype, test_category,
                   test_payment) -> None:
    item = create_random_item(db, test_itemtype.id, test_category.id,
                              test_payment.id)
    response = client.get(
        f"{settings.API_V1_STR}/items/{item.id}",
        headers=superuser_token_headers,
    )
    assert response.status_code == 200
    content = response.json()
    assert content["description"] == item.description
    assert content["amount"] == item.amount
    assert content["category_id"] == test_category.id
    assert content["payment_id"] == test_payment.id
    assert content["id"] == item.id
    assert content["owner_id"] == item.owner_id
コード例 #6
0
def test_update_item(db: Session) -> None:
    user = create_random_user(db)
    collection = create_random_collection(user)
    item = create_random_item(user, collection)
    properties = {"name": random_lower_string()}
    item_update = ItemUpdate(uuid=item.uuid,
                             geometry=item.geometry,
                             properties=properties)
    item2 = Item.from_dto(
        services.item.update_item(InternalUserDTO(**user.dict()), item.uuid,
                                  item_update.to_dto()))
    stored_item = Item.from_dto(
        services.item.get_item(InternalUserDTO(**user.dict()), item.uuid))
    assert item.uuid == item2.uuid == stored_item.uuid
    assert item.geometry == item2.geometry == stored_item.geometry
    assert item2.properties == properties == stored_item.properties
    assert item.collection_uuid == item2.collection_uuid == stored_item.collection_uuid
コード例 #7
0
def test_read_specific_item_by_owner(
    client: TestClient,
    normal_user_token_headers: Dict[str, str],
    normal_user: User,
    db: Session,
) -> None:
    new_item = create_random_item(db, owner_id=normal_user.id)
    response = client.get(
        f"{settings.API_V1_STR}/items/{new_item.id}",
        headers=normal_user_token_headers,
    )
    response.raise_for_status()
    content = response.json()
    assert content["title"] == new_item.title
    assert content["description"] == new_item.description
    assert content["id"] == new_item.id
    assert content["owner_id"] == new_item.owner_id
コード例 #8
0
def test_read_items_by_payment(client: TestClient,
                               superuser_token_headers: dict, db: Session,
                               test_itemtype, test_category,
                               test_payment) -> None:
    item = create_random_item(db, test_itemtype.id, test_category.id,
                              test_payment.id)
    get_payload = {'payment': test_payment.id}
    response = client.get(
        f"{settings.API_V1_STR}/items",
        headers=superuser_token_headers,
        params=get_payload,
    )
    assert response.status_code == 200
    content = response.json()
    assert len(content) >= 1
    for c in content:
        assert c[
            'payment_id'] == test_payment.id, f"Invalid payment_id for dataset={c}"
コード例 #9
0
def test_read_all_items_of_specific_user_by_superuser(
    client: TestClient,
    superuser_token_headers: Dict[str, str],
    new_user: User,
    new_item: Item,
    db: Session,
) -> None:
    second_item = create_random_item(db, owner_id=new_user.id)
    response = client.get(
        f"{settings.API_V1_STR}/admin/items/",
        headers=superuser_token_headers,
        params={"owner_id": new_user.id},
    )
    response.raise_for_status()
    all_items = response.json()
    assert len(all_items) == 2
    assert all_items[0]["owner_id"] == new_user.id
    assert all_items[1]["owner_id"] == new_user.id
コード例 #10
0
def new_item(db: Session, new_user: User) -> Item:
    return create_random_item(db, owner_id=new_user.id)