Skip to content

Migrate vault tests to mock_http fixture#23557

Draft
mwdd146980 wants to merge 1 commit intomwdd146980/httpx-migration-basefrom
mwdd146980/step5-vault
Draft

Migrate vault tests to mock_http fixture#23557
mwdd146980 wants to merge 1 commit intomwdd146980/httpx-migration-basefrom
mwdd146980/step5-vault

Conversation

@mwdd146980
Copy link
Copy Markdown
Contributor

Motivation

Step 5.3 of the httpx migration: remove the last mock.patch('requests.Session.*') patches from vault/tests/test_vault.py so the suite no longer depends on the requests transport layer.

Approach

All 17 sites in vault/tests/test_vault.py route through the mock_http / mock_openmetrics_http fixtures plus MockHTTPResponse:

  • 15 Pattern B sites — with mock.patch('requests.Session.get', side_effect=fn, autospec=True): becomes mock_http.get.side_effect = fn after stripping the autospec-injected session arg from each mock_requests_get.
  • 1 Pattern A site (test_service_check_500_fail) — mock.patch(..., return_value=...) becomes mock_http.get.return_value = MockHTTPResponse(status_code=500).
  • 1 wrapper-config site (test_x_vault_request_header_is_set) — rewritten to assert mock_openmetrics_http.options['headers']['X-Vault-Request'] == 'true' rather than peeking at outbound transport headers= kwargs. This is the right layer: vault attaches X-Vault-Request to its HTTP wrapper; wrapper→transport propagation is unit-tested upstream in datadog_checks_base/tests/base/utils/http/test_headers.py. Sets the precedent for Step 6/7 wrapper-header tests.

The stateful getattr(fn, 'first_health_call', True) toggle in test_replication_dr_mode_changed is preserved as-is — unittest.mock side_effect callables relay calls verbatim, function attributes are unaffected.

OM-v1 and OM-v2 X-Vault-Request header sites: OM-v2 sets the header in __init__ (covered automatically); OM-v1 sets it in parse_config (called explicitly in the test).

Verification

  • ddev test -fs vault — clean
  • ddev --no-interactive test vault — 64 passed, 14 skipped (auth-only)
  • rg "requests\.Session" vault/tests/test_vault.py — zero matches

Test plan

  • Format passes
  • Unit + integration tests pass
  • No requests.Session patches remain
  • Both use_openmetrics parametrize variants of test_x_vault_request_header_is_set pass

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (mwdd146980/httpx-migration-base@faddc6c). Learn more about missing BASE report.

Additional details and impacted files
🚀 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.

@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 30, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 95.48% (+8.20%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 99d05c1 | Docs | Datadog PR Page | Give us feedback!

@mwdd146980 mwdd146980 self-assigned this Apr 30, 2026
Base automatically changed from mwdd146980/step4-conftest-session-patches to mwdd146980/httpx-migration-base May 1, 2026 15:59
@mwdd146980 mwdd146980 force-pushed the mwdd146980/step5-vault branch from e048f71 to e49be69 Compare May 1, 2026 17:08
@mwdd146980 mwdd146980 force-pushed the mwdd146980/step5-vault branch from e49be69 to 99d05c1 Compare May 1, 2026 20:54
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 1, 2026

Validation Report

All 20 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and Codecov settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

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.

1 participant