diff --git a/src/crud.py b/src/crud.py index cd44338..a863df4 100755 --- a/src/crud.py +++ b/src/crud.py @@ -153,7 +153,7 @@ def get_all_spendings_by_group_id(db: Session, group_id: int): # UNIQUE SPENDINGS ################################################ -def create_unique_spending(db: Session, spending: schemas.SpendingCreate, user_id: int): +def create_unique_spending(db: Session, spending: schemas.UniqueSpendingCreate, user_id: int): db_spending = models.UniqueSpending(owner_id=user_id, **dict(spending)) db.add(db_spending) db.commit() diff --git a/src/main.py b/src/main.py index a14fd68..bb27bef 100755 --- a/src/main.py +++ b/src/main.py @@ -313,7 +313,7 @@ def list_group_unique_spendings(db: DbDependency, user: UserDependency, group_id @app.post("/unique-spending", status_code=HTTPStatus.CREATED) def create_unique_spending( - spending: schemas.SpendingCreate, db: DbDependency, user: UserDependency + spending: schemas.UniqueSpendingCreate, db: DbDependency, user: UserDependency ): group = crud.get_group_by_id(db, spending.group_id) diff --git a/src/schemas.py b/src/schemas.py index 4f83e8f..0882950 100755 --- a/src/schemas.py +++ b/src/schemas.py @@ -95,11 +95,11 @@ class UniqueSpendingBase(BaseModel): category_id: int -class SpendingCreate(UniqueSpendingBase): +class UniqueSpendingCreate(UniqueSpendingBase): pass -class Spending(UniqueSpendingBase): +class UniqueSpending(UniqueSpendingBase): id: int owner_id: int diff --git a/src/test_main.py b/src/test_main.py index 84336a0..7a5feb8 100755 --- a/src/test_main.py +++ b/src/test_main.py @@ -386,7 +386,7 @@ def some_spending( some_category: schemas.Category, ): response = client.post( - url="/spending", + url="/unique-spending", json={ "amount": 500, "description": "bought some féca", @@ -403,10 +403,10 @@ def some_spending( assert response_body["group_id"] == some_group.id assert response_body["category_id"] == some_category.id assert response_body - return schemas.Spending(**response_body) + return schemas.UniqueSpending(**response_body) -def test_create_new_spending(client: TestClient, some_spending: schemas.Spending): +def test_create_new_spending(client: TestClient, some_spending: schemas.UniqueSpending): # NOTE: test is inside fixture pass @@ -418,7 +418,7 @@ def test_create_new_spending_with_default_date( some_category: schemas.Category, ): response = client.post( - url="/spending", + url="/unique-spending", json={ "amount": 500, "description": "bought some féca", @@ -441,7 +441,7 @@ def test_create_new_spending_with_non_existant_category( some_group: schemas.Group, ): response = client.post( - url="/spending", + url="/unique-spending", json={ "amount": 500, "description": "bought some féca", @@ -456,16 +456,15 @@ def test_create_new_spending_with_non_existant_category( def test_get_spendings( client: TestClient, some_credentials: schemas.UserCredentials, - some_spending: schemas.Spending, + some_spending: schemas.UniqueSpending, ): response = client.get( - url="/spending", - params={"group_id": some_spending.group_id}, + url=f"/group/{some_spending.group_id}/spending", headers={"x-user": some_credentials.jwt}, ) assert response.status_code == HTTPStatus.OK assert len(response.json()) == 1 - assert schemas.Spending(**response.json()[0]) == some_spending + assert schemas.UniqueSpending(**response.json()[0]) == some_spending def test_create_spending_on_archived_group( @@ -481,7 +480,7 @@ def test_create_spending_on_archived_group( assert response.status_code == HTTPStatus.OK response = client.post( - url="/spending", + url="/unique-spending", json={ "amount": 500, "description": "bought some féca", @@ -896,7 +895,7 @@ def test_try_join_already_member( def test_balance_single_group_member( client: TestClient, some_credentials: schemas.UserCredentials, - some_spending: schemas.Spending, + some_spending: schemas.UniqueSpending, ): response = client.get( url=f"/group/{some_spending.group_id}/balance", @@ -917,7 +916,7 @@ def test_balance_single_group_member( def test_balance_multiple_members( client: TestClient, some_group_members: list[schemas.UserCredentials], - some_spending: schemas.Spending, + some_spending: schemas.UniqueSpending, ): response = client.get( url=f"/group/{some_spending.group_id}/balance",