Skip to content

BDMS 22+: implement sample model | some pytest cleanup | pre-commit hooks#49

Merged
jirhiker merged 48 commits into
pre-productionfrom
dev-jab
Aug 1, 2025
Merged

BDMS 22+: implement sample model | some pytest cleanup | pre-commit hooks#49
jirhiker merged 48 commits into
pre-productionfrom
dev-jab

Conversation

@jacob-a-brown

Copy link
Copy Markdown
Contributor

Why

This PR addresses the following problem / context:

  • It implements the current version of the sample model, with some anticipated changes coming down the road
  • Updates pytest session fixtures to be in tests/conftest.py for repeated use and retrieval throughout the testing suite.
  • Configures pre-commit hooks

How

Implementation summary - the following was changed / added / removed:

  • get, post, and patch endpoints were made for the /sample router
  • tests were made for all endpoints, as well as retrieving a single sample by its id
  • pytest fixtures were moved to tests/conftest.py for use throughout the testing suites
  • pre-commit hooks were configured in .pre-commit-config.yaml

Notes

Any special considerations, workarounds, or follow-up work to note?

  • The sample model is still being developed, but the work done here is applicable to future development so I wanted to get it into pre-production (the fixtures in particular)
  • Notes about alembic migrations were taken in the initial migration script for when alembic and its migrations are adopted
  • refactoring notes were taken and are found by searching for REFACTOR NOTE/TODO for future ideas/work
  • Some work was done to make tests independent of each other, but that should be a task for another PR. It was only implemented a bit here.

jacob-a-brown and others added 30 commits July 24, 2025 15:13
This commit drops the `idx_location_point` index from the `location` table.
The index was causing issues with the database schema because it is
automatically created by SQLAlchemy when the `location` table is defined.
configure_mappers() to ensure all models are registered
and ready for migration.
This is to be used by all endpoints where a resource is not found
when an id is given as part of a path parameter
The id changes because of autoincrement in the database, so use
the fixture's sample id instead of a hardcoded value.
@jacob-a-brown jacob-a-brown requested a review from jirhiker July 31, 2025 23:00
@jirhiker

Copy link
Copy Markdown
Member

Alembic migrations do not need to be used for the tests. This seems to be a continuing source of complexity and is not necessary. These unit tests are not for testing database migrations, they are for testing that the API functions correctly.

@jacob-a-brown

Copy link
Copy Markdown
Contributor Author

That makes sense that these are API tests. Would we have a database testing suite, though, to ensure that it's all built and working as expected?

@jirhiker jirhiker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sample api looks good and the use of fixtures in the tests is an improvement

But I do not like the use of alembic in the tests. It seems unnecessary and adds complexity that is a distraction from the true purpose of the tests

Comment thread api/sample.py
These tests are for the API, not for the database, so no need to use
Alembic migrations
@jacob-a-brown

Copy link
Copy Markdown
Contributor Author

I'm now using Base.metadata.drop_all(engine) and Base.metadata.create_all(engine) for the tests since these are just API, not database, tests.

Use this instead of session: Depends(get_db_session) in POST
/sample endpoint to keep a consistent style.
@jirhiker jirhiker merged commit d7225d7 into pre-production Aug 1, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants