NO TICKET: Make local tests pass#205
Conversation
Codecov Report❌ Patch coverage is
|
There was a problem hiding this comment.
Pull Request Overview
This PR fixes timezone-related test failures when running tests against the local filesystem instead of Docker by standardizing datetime serialization to UTC format with 'Z' suffix and ensuring proper database cleanup between test runs.
Key changes:
- Introduced
UTCAwareDatetimecustom type to handle consistent UTC datetime serialization across all response models - Added database cleanup logic in test initialization to ensure clean state between runs
- Updated database connection to default to current OS user when
POSTGRES_USERis not set
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/init.py | Added timezone configuration, dotenv loading, and database cleanup logic to ensure test isolation |
| schemas/init.py | Implemented UTCAwareDatetime custom type for consistent UTC datetime serialization |
| schemas/sample.py | Updated sample_date field to use UTCAwareDatetime |
| schemas/observation.py | Updated observation_datetime field to use UTCAwareDatetime |
| schemas/lexicon.py | Updated created_at field to use UTCAwareDatetime |
| db/engine.py | Modified database user resolution to default to OS username when POSTGRES_USER is empty |
| tests/test_thing.py | Updated datetime assertions to use explicit UTC conversion and removed redundant datetime formatting code |
| tests/test_sensor.py | Updated datetime assertions to use explicit UTC conversion |
| tests/test_sample.py | Updated datetime assertions to use explicit UTC conversion with inline timezone import |
| tests/test_observation.py | Updated datetime assertions to use explicit UTC conversion with inline timezone import |
| tests/test_location.py | Updated datetime assertions to use explicit UTC conversion |
| tests/test_lexicon.py | Updated datetime assertions to use explicit UTC conversion |
| tests/test_group.py | Updated datetime assertions to use explicit UTC conversion |
| tests/test_contact.py | Updated datetime assertions to use explicit UTC conversion |
| tests/test_asset.py | Updated datetime assertions to use explicit UTC conversion |
| .github/workflows/tests.yml | Added explicit POSTGRES_USER environment variable for CI workflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
jacob-a-brown
left a comment
There was a problem hiding this comment.
I like that all datetime objects are serialized as UTC with UTCAwareDatetime. Our intention is to store all datetime records in the database as UTC. Should UTCAwareDatetime be used in all Create... schemas and return UTC objects so that both storage and serialization are guaranteed to be UTC? Or, do you think that should always be handled by a field_validator in all of the appropriate Pydantic schemas?
|
Definitely the former. The latter couldn't hurt as well, or at least test for it? |
|
I created an issue for UTC enforcement |
Why
This PR addresses the following problem / context:
How
Implementation summary - the following was changed / added / removed:
Notes
Any special considerations, workarounds, or follow-up work to note?