Skip to content

add database tests for albums and faces (#1238)#1342

Open
Mansi2007275 wants to merge 2 commits into
AOSSIE-Org:mainfrom
Mansi2007275:add-database-tests-albums-faces
Open

add database tests for albums and faces (#1238)#1342
Mansi2007275 wants to merge 2 commits into
AOSSIE-Org:mainfrom
Mansi2007275:add-database-tests-albums-faces

Conversation

@Mansi2007275

@Mansi2007275 Mansi2007275 commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Closes #1238

Adds unit tests for the database layer for:

  • backend/app/database/albums.py
  • backend/app/database/faces.py

Test files added

  • backend/tests/test_albums_db.py — 18 tests
  • backend/tests/test_faces_db.py — 14 tests

What is covered

  • Table creation functions
  • Insert, update, delete operations
  • Password hashing and verification
  • Edge cases: empty results, missing records, None values
  • Batch operations
  • Cluster mean embedding calculations

Notes

  • All tests use unittest.mock to avoid real DB calls
  • Follows existing project test style from test_albums.py
  • One-line comments above each test describing the scenario

Summary by CodeRabbit

  • Tests
    • Added comprehensive database test coverage for album and face data layers.
    • Verified create, read, update, delete, and batch operations, including missing-record handling and empty-result edge cases.
    • Confirmed sensitive values are securely stored (no plaintext password persistence) and correctly validated.
    • Checked robustness features like proper error handling, connection cleanup, and expected SQL execution behavior.
    • Covered face embedding insertion/retrieval, clustering/mean embedding computation, and metadata serialization.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a1e75425-70bf-46e1-ae7c-694a4654e57b

📥 Commits

Reviewing files that changed from the base of the PR and between 7d47615 and 152f7d4.

📒 Files selected for processing (2)
  • backend/tests/test_albums_db.py
  • backend/tests/test_faces_db.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/tests/test_faces_db.py
  • backend/tests/test_albums_db.py

Walkthrough

Adds unit tests for album and face database helpers, covering table creation, album query and write paths, password verification, image batch deletion, face embedding insertion, cluster queries and updates, and cluster mean calculations.

Changes

Database helper tests

Layer / File(s) Summary
Album table setup
backend/tests/test_albums_db.py
Covers album table creation, including success paths and connection closure on SQL errors.
Album read helpers
backend/tests/test_albums_db.py
Covers album listing, lookup by name and id, and album image retrieval for present and empty results.
Album write and auth helpers
backend/tests/test_albums_db.py
Covers album insert and update paths with password hashing checks, album deletion SQL, batch image removal, and password verification.
Face table setup and inserts
backend/tests/test_faces_db.py
Covers face table creation and face embedding insertion, including metadata serialization and connection closure.
Face read and cluster helpers
backend/tests/test_faces_db.py
Covers unassigned-face retrieval, face listing with cluster names, batch cluster updates, and cluster mean embedding calculation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Suggested labels

Python

Poem

A bunny taps the database floor,
New tests hop in and ask for more.
Albums, faces, hashes, and arrays—
All checked by moonlit pytest plays.
Thump-thump, the burrow’s bright once more.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding database tests for albums and faces.
Linked Issues check ✅ Passed [#1238] The new albums and faces database tests directly address the request to add database-layer coverage.
Out of Scope Changes check ✅ Passed The changes stay focused on database-layer test coverage and do not introduce unrelated code paths.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
backend/tests/test_albums_db.py (2)

21-293: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove redundant test comments that restate method names.

Most inline comments just repeat what the test names already say, adding noise without extra clarity.

As per path instructions, “Point out redundant obvious comments that do not add clarity.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/tests/test_albums_db.py` around lines 21 - 293, Remove the redundant
inline test comments in the album DB tests that only restate the surrounding
method names, and keep only comments that add extra context or intent. Update
the tests around db_create_albums_table, db_get_all_albums,
db_get_album_by_name, db_get_album, db_insert_album, db_update_album,
db_delete_album, db_get_album_images, db_remove_images_from_album, and
verify_album_password so the file is less noisy and the useful assertions remain
easy to scan.

Source: Path instructions


23-301: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Refactor repeated mock setup into fixtures/helpers.

The same connect/conn/cursor setup is duplicated across many tests. A shared fixture (e.g., returning (mock_connect, mock_conn, mock_cursor)) would reduce repetition and make intent clearer.

As per path instructions, “Look for code duplication.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/tests/test_albums_db.py` around lines 23 - 301, The album database
tests repeat the same sqlite3 connect/conn/cursor mocking setup across many
methods, so refactor the duplicated arrangement into a shared pytest fixture or
small helper that returns the mocked connect, connection, and cursor. Update the
tests in TestDbCreateAlbumsTable, TestDbGetAllAlbums, TestDbGetAlbumByName,
TestDbGetAlbum, TestDbInsertAlbum, TestDbUpdateAlbum, TestDbGetAlbumImages,
TestDbRemoveImagesFromAlbum, and TestVerifyAlbumPassword to use that shared
setup while keeping each assertion focused on the behavior under test.

Source: Path instructions

backend/tests/test_faces_db.py (1)

19-219: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared sqlite mock setup into pytest fixtures to remove duplication.

The repeated connect patch + conn/cursor wiring appears in most tests; a fixture will make tests shorter and easier to maintain.

As per path instructions, “Look for code duplication.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/tests/test_faces_db.py` around lines 19 - 219, The tests in
TestDbCreateFacesTable, TestDbInsertFaceEmbeddings,
TestDbGetFacesUnassignedClusters, TestDbGetAllFacesWithClusterNames,
TestDbUpdateFaceClusterIdsBatch, and TestDbGetClusterMeanEmbeddings repeat the
same sqlite3.connect patch and mock connection/cursor wiring. Extract that
shared setup into a pytest fixture (or helper fixture pair) that yields the mock
connect/conn/cursor objects, then update each test to reuse it and keep only the
scenario-specific assertions and side effects.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/tests/test_albums_db.py`:
- Around line 41-50: The TestDbCreateAlbumImagesTable class is missing the
failure-path coverage for db_create_album_images_table()’s finally-close
behavior. Add a test that patches app.database.albums.sqlite3.connect, makes
mock_conn.cursor().execute raise an exception, and asserts that mock_conn.close
is still called even when the insert/create logic fails. Reuse the same style as
the existing success test, and target the db_create_album_images_table function
so the resource cleanup contract is verified.

In `@backend/tests/test_faces_db.py`:
- Around line 86-220: Add connection cleanup assertions to the remaining
database helper tests so the DB helper contract is fully covered. In the test
classes for db_get_faces_unassigned_clusters,
db_get_all_faces_with_cluster_names, db_update_face_cluster_ids_batch, and
db_get_cluster_mean_embeddings, verify the mocked connection’s close method is
called after each helper runs, matching the cleanup coverage already present for
table creation/insert. Use the existing sqlite3.connect patch setup and the
helper function names to place the assertions without changing the production
logic.

---

Nitpick comments:
In `@backend/tests/test_albums_db.py`:
- Around line 21-293: Remove the redundant inline test comments in the album DB
tests that only restate the surrounding method names, and keep only comments
that add extra context or intent. Update the tests around
db_create_albums_table, db_get_all_albums, db_get_album_by_name, db_get_album,
db_insert_album, db_update_album, db_delete_album, db_get_album_images,
db_remove_images_from_album, and verify_album_password so the file is less noisy
and the useful assertions remain easy to scan.
- Around line 23-301: The album database tests repeat the same sqlite3
connect/conn/cursor mocking setup across many methods, so refactor the
duplicated arrangement into a shared pytest fixture or small helper that returns
the mocked connect, connection, and cursor. Update the tests in
TestDbCreateAlbumsTable, TestDbGetAllAlbums, TestDbGetAlbumByName,
TestDbGetAlbum, TestDbInsertAlbum, TestDbUpdateAlbum, TestDbGetAlbumImages,
TestDbRemoveImagesFromAlbum, and TestVerifyAlbumPassword to use that shared
setup while keeping each assertion focused on the behavior under test.

In `@backend/tests/test_faces_db.py`:
- Around line 19-219: The tests in TestDbCreateFacesTable,
TestDbInsertFaceEmbeddings, TestDbGetFacesUnassignedClusters,
TestDbGetAllFacesWithClusterNames, TestDbUpdateFaceClusterIdsBatch, and
TestDbGetClusterMeanEmbeddings repeat the same sqlite3.connect patch and mock
connection/cursor wiring. Extract that shared setup into a pytest fixture (or
helper fixture pair) that yields the mock connect/conn/cursor objects, then
update each test to reuse it and keep only the scenario-specific assertions and
side effects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0e87f89e-bef4-4dd5-90ef-b11a2d576c95

📥 Commits

Reviewing files that changed from the base of the PR and between b3eee2c and 7d47615.

📒 Files selected for processing (2)
  • backend/tests/test_albums_db.py
  • backend/tests/test_faces_db.py

Comment thread backend/tests/test_albums_db.py Outdated
Comment thread backend/tests/test_faces_db.py Outdated
Signed-off-by: Mansi2007275 <mansi@example.com>
@Mansi2007275

Copy link
Copy Markdown
Author

@rohan-pandeyy please review my PR.....if its okay then merged it ....

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.

Feat: Add test for database

1 participant