Skip to content

Cover privacy views and return 404 when the privacy doc is missing - #17383

Open
ABuljko wants to merge 3 commits into
mozilla:mainfrom
ABuljko:privacy-views-coverage
Open

ABuljko wants to merge 3 commits into
mozilla:mainfrom
ABuljko:privacy-views-coverage

Conversation

@ABuljko

@ABuljko ABuljko commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor
  • Adds tests for bedrock/privacy/views.py
  • Fixes privacy() returning a 500 when the privacy doc is missing from the database (now raises Http404, like the class-based views already did)

Linked to Issue #12978

@ABuljko
ABuljko requested a review from a team as a code owner September 16, 2026 23:39
@janriokrause
janriokrause requested review from janriokrause and a balanced review from Copilot September 18, 2026 16:16

Copilot AI 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.

🟢 Approval recommended

The focused error-handling change is correct and adequately covered by tests.

Pull request overview

Adds privacy-view coverage for Issue #12978 and returns HTTP 404 when the privacy document is unavailable.

Changes:

  • Handles missing privacy documents consistently with class-based legal views.
  • Tests document processing, locale handling, templates, and missing-document behavior.
  • Reviewed using the repository’s custom instructions and AGENTS.md; no material risks or follow-ups found.
File summaries
File Description
bedrock/privacy/views.py Raises Http404 for a missing privacy policy.
bedrock/privacy/tests/test_views.py Adds comprehensive privacy-view tests.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread bedrock/privacy/views.py
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.54%. Comparing base (8aa4b25) to head (b78facf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17383      +/-   ##
==========================================
+ Coverage   83.36%   83.54%   +0.17%     
==========================================
  Files         177      177              
  Lines        9318     9321       +3     
==========================================
+ Hits         7768     7787      +19     
+ Misses       1550     1534      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@janriokrause janriokrause 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.

Thanks for the fix and the coverage! Looks good! A few tiny suggestions to trim the tests and add one:

  • Drop TestPrivacyDocView.test_missing_doc_gives_404. The 404 lives in LegalDocView, which PrivacyDocView doesn't override, and it's already covered by test_missing_doc_is_404 in bedrock/legal_docs/tests/test_base.py. The test that matters for PrivacyDocView is test_missing_doc_is_passed_through, since it covers the None guard.
  • Merge test_active_locales_are_left_alone into test_content_is_processed. Both build the same doc, so one extra assert covers it.
  • Drop test_doc_is_loaded_for_the_request_locale. test_renders_processed_doc already asserts the load_legal_doc call, and switching the locale to de doesn't hit a different code path.
  • Slim down TestProcessLegalDoc:
    • Combine the http/https tests. They exercise the same regex (https?).
    • Drop test_external_links_are_untouched. It's covered by test_every_matching_link_is_rewritten.
    • Keep only one of test_returns_a_soup_object / test_doc_without_links_is_returned_unchanged. Both just check that the HTML parses.
    • Drop test_rewrite_is_not_limited_to_anchors. It locks in incidental behavior, and legal docs come from Markdown, so <link> tags won't show up.
  • Move the preview ?v=product test into TestFirefoxPrivacyNextViewBehaviour, so all the preview view tests live in one place.
  • Add an unmocked regression test for the actual bug. The existing 404 tests mock load_legal_doc, but this one goes through the real URL routing and lookup, and it returns a 500 on main:
def test_missing_doc_gives_404_end_to_end(self):
    # The test DB has no `LegalDoc` rows, so `load_legal_doc` returns `None` without mocking
    resp = self.client.get("/en-US/privacy/")
    assert resp.status_code == 404

@ABuljko

ABuljko commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

TY!! :)
I will look into it tomorrow or Sunday 🍀

@janriokrause

Copy link
Copy Markdown
Contributor

Sure, take your time. Please keep in mind that many of our developers have limited availability because of an engineering summit taking place all next week. I'll come back to your PRs after the summit 😊.

@ABuljko

ABuljko commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Ofc np :)
I hope that u enjoy the summit and have a nice time in general ✨️

This branch has not been deployed

No deployments
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.

3 participants