Skip to content

Conversation

@naasanov
Copy link
Collaborator

@naasanov naasanov commented Jan 2, 2026

Fixed tests to use Postgres instead of sqlite

Changes:

  • Instead of using in memory sqlite, create a separate db for testing in the existing postgres container
    • Modified test_session conftest fixture
    • Added a new script to make this test_db and put this into the postcreate script
    • Updated CI tests to use postgres
  • Made DB validate PID as 9 digits now that this works with tests
  • Fixed issues unearthed by tests using postgres
    • Timezone stuff in complaint entity and party router

Extras:

  • Added a check in create_db.py to see if the db already exists, so that expected behavior doesn't look like an error
  • Made get_parties_nearby and get_parties_csv validate date format at middleware level with regex
    • Added tests for this as well
  • Edited backend-tests action to run on PR for any branch instead of just main

Closes #143

Comment on lines +8 to +9
asyncio_default_fixture_loop_scope = session
asyncio_default_test_loop_scope = session
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Necessary for async session fixture shenanigans

Comment on lines +65 to +73
# Clean up: truncate all tables and reset sequences
async with test_engine.begin() as conn:
tables = [table.name for table in EntityBase.metadata.sorted_tables]
if tables:
# Disable foreign key checks, truncate, and reset sequences
await conn.execute(text("SET session_replication_role = 'replica';"))
for table in tables:
await conn.execute(text(f"TRUNCATE TABLE {table} RESTART IDENTITY CASCADE;"))
await conn.execute(text("SET session_replication_role = 'origin';"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Truncate instead of drop all tables so that tests don't take a million years

@naasanov naasanov changed the base branch from test-refactor to main January 5, 2026 22:21
@naasanov naasanov closed this Jan 6, 2026
@naasanov naasanov reopened this Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Test Results Summary

302 tests  +16   302 ✅ +16   12s ⏱️ +4s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit 041b637. ± Comparison against base commit e23a979.

This pull request removes 1 and adds 17 tests. Note that renamed tests count towards both.
test.modules.party.party_router_test.TestPartyNearbyRouter ‑ test_get_parties_nearby_validation_errors
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params0]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params1]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params2]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params3]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params4]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params5]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params6]
test.modules.party.party_router_test.TestPartyCSVRouter ‑ test_get_parties_csv_validation_errors[params7]
test.modules.party.party_router_test.TestPartyNearbyRouter ‑ test_get_parties_nearby_validation_errors[params0]
test.modules.party.party_router_test.TestPartyNearbyRouter ‑ test_get_parties_nearby_validation_errors[params1]
…

♻️ This comment has been updated with latest results.

@naasanov naasanov merged commit b5f336b into main Jan 7, 2026
2 checks passed
@naasanov naasanov deleted the postgres-tests branch January 7, 2026 18:32
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.

Postgres Instead of Sqlite For Tests

2 participants