test: cover the HTML text extractor and the regulation indicators report - #676
Conversation
Two features had no tests of their own. utils/htmlutils turns the HTML stored by the rich text editors into (text, bold) runs, which is what keeps the clinical note PDF looking like what the user typed. The new tests pin the emphasis rules (tags, headings, table headers and inline font-weight), the line breaks, the annotation close-button stripping and the whitespace normalization, plus the malformed-markup behaviour. The regulation indicators panel report (services/reports/ reports_regulation_service and repository/reports/ reports_regulation_repository) served three endpoints with almost no coverage. The new tests cover the payload mapping, the HIDE_NAMES masking, the CSV download (header contract, the three indicator states and the fixed 10000 row cap), the weighted summary and every filter and ordering branch of the query — asserted through the compiled SQL. The regulation DDL is not loaded by CI, so these are unit tests with a recording session double, following tests/unit/test_regulation_solicitation.py. Both modules and the repository now report 100% line coverage. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFdmF6YmEHRdLZwgkuKPwc
There was a problem hiding this comment.
This PR successfully adds comprehensive test coverage for two previously under-tested features: the HTML text extractor and the regulation indicators report. The tests are well-structured, use appropriate mocking strategies, and achieve 100% coverage for the targeted modules.
Tests-only PR - No production code changes
Both test files demonstrate strong testing practices with clear test names, comprehensive edge case coverage, and proper use of pytest features. The approach of using recording sessions and mocks for database-dependent code is appropriate for these unit tests.
No blocking issues found. The PR is ready to merge.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
Increases coverage on two features that had no tests of their own.
1.
utils/htmlutils— HTML to styled text runs (tests/unit/test_htmlutils.py)html_to_runsturns the HTML stored by the rich text editors into(text, bold)runs, which is what keeps the clinical note PDF looking like what the user typed. It was only reached incidentally through the digital-signature tests, so none of its rules were actually asserted.51 tests pin:
<b>/<strong>, headings,<th>, inlinefont-weight(bold/bolder/600-900 vs. normal/400/500), inheritance into nested elements and the fact that emphasis does not leak past its element.<br>, every block tag, void tags that must not break, the one-blank-line cap, whitespace trimmed before a break and around the whole fragment.close-btnanchor's "X" is dropped (including when it carries other classes), while regular links keep their text.normalize_runsused directly by the PDF service to assemble custom form answers.2. Regulation indicators panel report (
tests/unit/test_reports_regulation.py)services/reports/reports_regulation_service(44% covered) andrepository/reports/reports_regulation_repository(10% covered) serve three endpoints with no tests:/reports/regulation/indicators-panel/reports/regulation/indicators-panel-csv/reports/regulation/indicators-summary79 tests cover:
rel_painel_juntosunder its API name, ISO dates, the three-state indicator booleans left uncoerced, rows with no dates, and the count read from the window function rather thanlen().HIDE_NAMESmasking — the identifying fields become***while the clinical columns stay readable.Sim/Não/Não se aplica), empty cells for null dates, and the fixed 10000-row cap that overrides the requested limit.has_indicatorfilter for each of the eight indicators, the case-insensitive contains searches, the exact and range filters, filter combination, paging, and the ordering rules (including thatbirthdateis sorted by age, so its direction is inverted, and that a non-whitelisted sort field is ignored). Asserted through the compiled SQL.READ_REPORTS.A guard test also fails if a new value is added to
RegulationIndicatorReportEnumwithout making it filterable in the report.Why unit tests
The regulation tables live in a separate DDL file that neither CI nor
make test-setuploads, so these follow the approach already used bytests/unit/test_regulation_solicitation.py:dbis replaced with a recording session double and the repository is patched when testing the service. Real SQLAlchemy model instances and real query expressions are still used, so the column mapping and the filters are exercised for real.Result
utils/htmlutils.pyservices/reports/reports_regulation_service.pyrepository/reports/reports_regulation_repository.pyTests only — no production code changed. Full suite: 2507 passed.
ruff check .clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01EFdmF6YmEHRdLZwgkuKPwc
Generated by Claude Code