Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add tests #25

Merged
merged 6 commits into from
Nov 16, 2023
Merged

build: add tests #25

merged 6 commits into from
Nov 16, 2023

Conversation

raphodn
Copy link
Member

@raphodn raphodn commented Nov 13, 2023

What

  • install pytest, pytest-cov & httpx
  • write basic tests on routes

@raphodn raphodn self-assigned this Nov 13, 2023
@raphodn raphodn marked this pull request as draft November 13, 2023 18:00
@raphodn raphodn force-pushed the raphodn/price-create-endpoint branch from 4a7d16f to 660e2a8 Compare November 13, 2023 18:30
@raphodn raphodn force-pushed the raphodn/price-create-endpoint branch from 118a132 to f62ee3e Compare November 15, 2023 14:00
Base automatically changed from raphodn/price-create-endpoint to main November 15, 2023 14:06
@raphodn raphodn force-pushed the raphodn/add-tests branch 3 times, most recently from 06f22eb to 83e4e63 Compare November 15, 2023 18:15
@raphodn raphodn marked this pull request as ready for review November 15, 2023 23:13
pyproject.toml Outdated Show resolved Hide resolved
)
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base.metadata.create_all(bind=engine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to do DB initialization in a global (autouse=True, scope=session) fixture? So that we can take care of removing it after

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly don't know, this is more or less a copy-paste of the fastapi tutorials
https://fastapi.tiangolo.com/advanced/testing-database/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge, but these tests will need improvement for sure !

app/api.py Outdated
@@ -162,7 +161,7 @@ async def create_price(
status_code=status.HTTP_403_FORBIDDEN,
detail="Proof does not belong to current user",
)
db_price = crud.create_price(db, price=price, user=current_user)
db_price = crud.create_price(db, price=price.model_dump(), user=current_user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Price is supposed to be a PriceCreate, no?

Copy link
Member Author

@raphodn raphodn Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the crud side we have Price(**price, owner=user.user_id) so I need to check if it works without the model_dump

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the model_dump, I get the following error

TypeError: app.models.Price() argument after ** must be a mapping, not PriceCreate

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved back the model_dump inside the crud file 👍

@raphodn raphodn merged commit e43726d into main Nov 16, 2023
3 checks passed
@raphodn raphodn deleted the raphodn/add-tests branch November 16, 2023 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants