Skip to content

[SPD-48307]: add DB repo test infrastructure + PacketDBRepository filter - #3

Open
AdiDev0 wants to merge 1 commit into
spd-48239-setup-postgres-db-modelsfrom
spd-48307-setup-test-db-and-basic-db-repo
Open

[SPD-48307]: add DB repo test infrastructure + PacketDBRepository filter#3
AdiDev0 wants to merge 1 commit into
spd-48239-setup-postgres-db-modelsfrom
spd-48307-setup-test-db-and-basic-db-repo

Conversation

@AdiDev0

@AdiDev0 AdiDev0 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

User description

What

Sets up the database repository testing infrastructure for tars and delivers
the first concrete example: PacketDBRepository.filter with full test coverage.

This PR is intentionally narrow — it exists to give every developer on the team
a working reference for how DB repo code and tests should be structured in tars,
mirroring the pattern used in django-rest-api.


Changes

app/db/postgres.pySoftDeleteMixin query entry points

Added two classmethods to SoftDeleteMixin, available on every model that
composes it (Packet, Agreement, LegalHub, etc.):

Packet.objects()                   # SELECT … WHERE is_deleted = false  (default)
Packet.objects_including_deleted() # SELECT … (all rows)

---

# Generated description

Below is a concise technical summary of the changes proposed in this PR:
Establish SoftDeleteMixin query helpers and <code>PacketDBRepository.filter</code> so workspace-scoped packet retrieval respects soft deletes, optional ID constraints, and emits structured logs. Provide the pytest fixtures, base test case, factories, and concrete tests for <code>PacketDBRepository.filter</code>, mirroring django-rest-api conventions to document DB repo structure adoption.
<table><tr><th>Topic</th><th>Details</th><tr><td><a href=https://baz.co/changes/SpotDraft/tars/3?tool=ast&topic=Packet+filtering>Packet filtering</a>
        </td><td>Implement <code>PacketDBRepository.filter</code> plus SoftDeleteMixin helpers so packet retrieval honors workspace isolation, optional ID lists, soft-delete opt-in, and logging while exposing domain models for validation.<details><summary>Modified files (3)</summary><ul><li>app/clickwrap/data/postgres/db_repo.py</li>
<li>app/clickwrap/domain/domain_models.py</li>
<li>app/db/postgres.py</li></ul></details><details><summary>Latest Contributors(1)</summary><table><tr><th>User</th><th>Commit</th><th>Date</th></tr><tr><td>aditya.raj@spotdraft.com</td><td>[]: add DB repo test i...</td><td>July 08, 2026</td></tr></table></details></td></tr>
<tr><td><a href=https://baz.co/changes/SpotDraft/tars/3?tool=ast&topic=DB+repo+tests>DB repo tests</a>
        </td><td>Document the DB repo testing pattern via BaseDBRepoTestCase, pytest engine/session fixtures, Packet factories, and integration tests (with package init) that cover workspace boundaries, ID filtering, and soft delete behavior.<details><summary>Modified files (5)</summary><ul><li>tests/base_db_repo_test.py</li>
<li>tests/clickwrap/data/__init__.py</li>
<li>tests/clickwrap/data/test_packet_db_repo.py</li>
<li>tests/conftest.py</li>
<li>tests/factories.py</li></ul></details><details><summary>Latest Contributors(1)</summary><table><tr><th>User</th><th>Commit</th><th>Date</th></tr><tr><td>aditya.raj@spotdraft.com</td><td>[]: add DB repo test i...</td><td>July 08, 2026</td></tr></table></details></td></tr></table>
<sub><a href="https://baz.co/changes/SpotDraft/tars/3?tool=ast">Review this PR on Baz</a> | <a href="https://baz.co/agents/baz">Customize your next review</a></sub>

@baz-reviewer

baz-reviewer Bot commented Jul 8, 2026

Copy link
Copy Markdown

Spec Reviewer Report

✅ 2 met requirements:

1. Test database configured for microservice testing Pytest fixtures now set up a dedicated async test database with derived URL, schema creation, and session rollback support.

Evidence:

  • tests/conftest.py:18-25 derive TEST_DATABASE_URL from TEST_DATABASE_URL env or settings
  • tests/conftest.py:33-45 test_engine fixture creates async engine against test DB, installs pg_trgm, creates/drops metadata each session
  • tests/conftest.py:53-62 db_session fixture yields per-test AsyncSession with rollback cleanup

2. Basic database repositories provided for microservice PacketDBRepository.filter now encapsulates workspace-scoped querying, optional ID filtering, and soft-delete opt-in so the microservice has a functioning repository layer.

Evidence:

  • app/clickwrap/data/postgres/db_repo.py:15-64 (PacketDBRepository.filter implements workspace isolation, ID filtering, soft-delete options, and logs results)
  • app/clickwrap/domain/domain_models.py:7-38 (domain models define the request/response contracts used by the repository)
  • tests/clickwrap/data/test_packet_db_repo.py:1-93 (integration tests covering workspace isolation, packet ID filtering, and soft-delete handling)


Used resources:
Hash: f60bea0 | Ticket: [BE] Setup test db and basic db repos in microservice | Checkout in Baz

To rerun the Spec Reviewer, comment "baz rerun spec review".

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.

1 participant