Skip to content

test: cover the HTML text extractor and the regulation indicators report - #676

Merged
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-fft7pv
Sep 7, 2026
Merged

test: cover the HTML text extractor and the regulation indicators report#676
marceloarocha merged 1 commit into
developfrom
claude/magical-wozniak-fft7pv

Conversation

@marceloarocha

Copy link
Copy Markdown
Collaborator

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_runs 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. It was only reached incidentally through the digital-signature tests, so none of its rules were actually asserted.

51 tests pin:

  • Emphasis<b>/<strong>, headings, <th>, inline font-weight (bold/bolder/600-900 vs. normal/400/500), inheritance into nested elements and the fact that emphasis does not leak past its element.
  • Line breaks<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.
  • Annotation close buttons — the close-btn anchor's "X" is dropped (including when it carries other classes), while regular links keep their text.
  • Malformed markup — unclosed elements, closing an outer element while an inner one is still open, a stray closing tag, unknown tags.
  • normalize_runs used 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) and repository/reports/reports_regulation_repository (10% covered) serve three endpoints with no tests:

  • /reports/regulation/indicators-panel
  • /reports/regulation/indicators-panel-csv
  • /reports/regulation/indicators-summary

79 tests cover:

  • Payload mapping — every column of rel_painel_juntos under 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 than len().
  • HIDE_NAMES masking — the identifying fields become *** while the clinical columns stay readable.
  • CSV download — the header contract, header/row alignment, the three rendered indicator states (Sim / Não / Não se aplica), empty cells for null dates, and the fixed 10000-row cap that overrides the requested limit.
  • Query building — the current-version filter, the target-group filter and the has_indicator filter for each of the eight indicators, the case-insensitive contains searches, the exact and range filters, filter combination, paging, and the ordering rules (including that birthdate is sorted by age, so its direction is inverted, and that a non-whitelisted sort field is ignored). Asserted through the compiled SQL.
  • Weighted summary — schema scoping, the empty view, the five indicators and their weights, rounding, and a null score reported as zero.
  • Permission gate — all three endpoints reject a role without READ_REPORTS.

A guard test also fails if a new value is added to RegulationIndicatorReportEnum without making it filterable in the report.

Why unit tests

The regulation tables live in a separate DDL file that neither CI nor make test-setup loads, so these follow the approach already used by tests/unit/test_regulation_solicitation.py: db is 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

module before after
utils/htmlutils.py 89% 100%
services/reports/reports_regulation_service.py 44% 100%
repository/reports/reports_regulation_repository.py 10% 100%

Tests 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

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

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@marceloarocha
marceloarocha merged commit f006f41 into develop Sep 7, 2026
10 checks passed
@marceloarocha
marceloarocha deleted the claude/magical-wozniak-fft7pv branch September 7, 2026 12:18
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.

2 participants