Skip to content

test: replace broken test suite with 52 passing tests#209

Open
utkarshqz wants to merge 1 commit intofireform-core:mainfrom
utkarshqz:test/replace-broken-test-suite
Open

test: replace broken test suite with 52 passing tests#209
utkarshqz wants to merge 1 commit intofireform-core:mainfrom
utkarshqz:test/replace-broken-test-suite

Conversation

@utkarshqz
Copy link

Description

Replaces the broken test suite with 52 fully passing tests covering the LLM class, template endpoints, and form endpoints.

The existing test infrastructure had two critical problems:

  1. test_templates.py sent JSON to a multipart/form-data endpoint → always 422
  2. test_forms.py was entirely commented out → zero coverage
  3. conftest.py used session-scoped DB → tests leaked data into each other

This PR fixes all three and adds comprehensive tests for the new functionality introduced alongside it.

Fixes #163
Fixes #182
Fixes #183
Closes #186

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

python -m pytest tests/ -v

Output:

52 passed, 14 warnings in 0.58s

All 52 tests pass on Windows 11, Python 3.11, in a clean virtual environment.

Test breakdown:

tests/test_llm.py — 15 tests (new file, Closes #186)

  • TestTypeCheckAll — validates input types correctly
  • TestBuildBatchPrompt — confirms human labels appear in prompt
  • TestBuildPrompt — role-based guidance for officer/victim/location fields
  • TestHandlePluralValues — semicolon splitting, whitespace stripping
  • TestAddResponseToJson — stores values, ignores -1, handles plurals
  • TestMainLoop — mocked Ollama, asserts exactly 1 API call (O(1) batch)

tests/test_templates.py — 10 tests (replaces broken version)

  • Upload valid PDF → 200
  • Upload without file → 422
  • Upload non-PDF → 400
  • List templates → 200, returns list, empty on fresh DB
  • Get by ID → 200 with correct data
  • Get non-existent → 404
  • Get invalid ID type → 422

tests/test_forms.py — 7 tests (replaces commented-out version)

  • Fill with missing template → 404
  • Fill with missing fields → 422
  • Fill with Ollama down → 503
  • Get submission not found → 404
  • Get submission invalid ID → 422
  • Download not found → 404
  • Download with missing file on disk → 404

tests/conftest.py — fixed DB isolation

  • Changed from session-scoped to function-scoped (autouse=True)

  • Each test gets a fresh empty DB — no data leakage between tests

  • Added db_session fixture for direct DB access in test setup

  • Test A — python -m pytest tests/ -v → 52 passed

  • Test B — ran twice consecutively, same result (no order dependency)

Test Configuration:

  • OS: Windows 11
  • Python: 3.11.9
  • pytest: 9.0.2

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant