Skip to content

Commit

Permalink
fix: update tests with new spending-related endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaRedHand committed Jun 12, 2024
1 parent 2584531 commit 0ba4662
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 11 additions & 12 deletions src/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 0ba4662

Please sign in to comment.