Skip to content

PYTHON-5772 Increase _gcp_helpers.py coverage#2749

Merged
aclark4life merged 1 commit intomongodb:masterfrom
aclark4life:PYTHON-5772
Apr 14, 2026
Merged

PYTHON-5772 Increase _gcp_helpers.py coverage#2749
aclark4life merged 1 commit intomongodb:masterfrom
aclark4life:PYTHON-5772

Conversation

@aclark4life
Copy link
Copy Markdown
Contributor

@aclark4life aclark4life commented Apr 8, 2026

PYTHON-5772

Changes in this PR

Test Plan

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a focused unit test module to improve coverage of pymongo/_gcp_helpers.py, specifically around _get_gcp_response behavior and error handling.

Changes:

  • Introduces test/test_gcp_helpers.py with unit tests covering success, non-200 responses, exceptions, request construction, and timeout forwarding.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.82%. Comparing base (49e7a05) to head (dad7f22).

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2749       +/-   ##
===========================================
+ Coverage   75.32%   87.82%   +12.50%     
===========================================
  Files         140      141        +1     
  Lines       24167    24396      +229     
  Branches     4127     4172       +45     
===========================================
+ Hits        18204    21427     +3223     
+ Misses       4931     2068     -2863     
+ Partials     1032      901      -131     
Flag Coverage Δ
auth-aws-rhel8-test-auth-aws-rapid-web-identity-python3.14-cov 35.02% <ø> (?)
auth-aws-win64-test-auth-aws-rapid-web-identity-python3.14-cov 35.02% <ø> (?)
auth-enterprise-macos-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.77% <ø> (?)
auth-enterprise-rhel8-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.76% <ø> (?)
auth-enterprise-win64-test-standard-auth-latest-python3.11-auth-ssl-sharded-cluster-cov 43.78% <ø> (?)
auth-oidc-local-ubuntu-22-test-auth-oidc-default 48.61% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (?)
compression-snappy-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.72% <ø> (?)
compression-zlib-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (?)
compression-zlib-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (?)
compression-zlib-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (?)
compression-zlib-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (?)
compression-zstd-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (?)
compression-zstd-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.39% <ø> (?)
compression-zstd-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (?)
compression-zstd-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (?)
compression-zstd-ubuntu-22-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.72% <ø> (?)
coverage-report-coverage-report 87.80% <ø> (?)
disable-test-commands-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.08% <ø> (?)
disable-test-commands-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.40% <ø> (?)
disable-test-commands-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.53% <ø> (?)
disable-test-commands-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.73% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.49% <ø> (?)
encryption-crypt_shared-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.42% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.67% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.52% <ø> (?)
encryption-crypt_shared-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.52% <ø> (?)
encryption-macos-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.73% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 53.41% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 55.17% <ø> (?)
encryption-pyopenssl-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 55.13% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.73% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.49% <ø> (?)
encryption-rhel8-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.41% <ø> (?)
encryption-win64-test-non-standard-latest-python3.13-noauth-nossl-standalone-cov 52.67% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 54.53% <ø> (?)
encryption-win64-test-non-standard-latest-python3.14t-noauth-ssl-replica-set-cov 54.46% <ø> (?)
load-balancer-test-non-standard-latest-python3.14-auth-ssl-sharded-cluster-cov 48.39% <ø> (?)
mongodb-latest-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.94% <ø> (?)
mongodb-latest-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.11% <ø> (?)
mongodb-latest-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.29% <ø> (?)
mongodb-latest-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.40% <ø> (?)
mongodb-latest-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.29% <ø> (?)
mongodb-rapid-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.94% <ø> (?)
mongodb-rapid-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.11% <ø> (?)
mongodb-rapid-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.29% <ø> (?)
mongodb-rapid-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.40% <ø> (?)
mongodb-rapid-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.29% <ø> (?)
mongodb-v4.2-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 54.53% <ø> (?)
mongodb-v4.2-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.01% <ø> (?)
mongodb-v4.2-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 56.87% <ø> (?)
mongodb-v4.2-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 56.98% <ø> (?)
mongodb-v4.2-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 54.68% <ø> (?)
mongodb-v4.4-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.04% <ø> (?)
mongodb-v4.4-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.35% <ø> (?)
mongodb-v4.4-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.36% <ø> (?)
mongodb-v4.4-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.45% <ø> (?)
mongodb-v4.4-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 55.08% <ø> (?)
mongodb-v5.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.23% <ø> (?)
mongodb-v5.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.51% <ø> (?)
mongodb-v5.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.56% <ø> (?)
mongodb-v5.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.69% <ø> (?)
mongodb-v5.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 55.32% <ø> (?)
mongodb-v6.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.23% <ø> (?)
mongodb-v6.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.50% <ø> (?)
mongodb-v6.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.58% <ø> (?)
mongodb-v6.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.73% <ø> (?)
mongodb-v6.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.60% <ø> (?)
mongodb-v7.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 55.27% <ø> (?)
mongodb-v7.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 53.51% <ø> (?)
mongodb-v7.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 57.63% <ø> (?)
mongodb-v7.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 57.73% <ø> (?)
mongodb-v7.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 59.60% <ø> (?)
mongodb-v8.0-test-server-version-python3.10-async-auth-ssl-sharded-cluster-min-deps-cov 56.94% <ø> (?)
mongodb-v8.0-test-server-version-python3.10-async-noauth-nossl-standalone-min-deps-cov 55.10% <ø> (?)
mongodb-v8.0-test-server-version-python3.10-sync-auth-ssl-sharded-cluster-min-deps-cov 59.29% <ø> (?)
mongodb-v8.0-test-server-version-python3.10-sync-noauth-nossl-replica-set-min-deps-cov 59.40% <ø> (?)
mongodb-v8.0-test-server-version-python3.11-async-noauth-nossl-replica-set-cov 61.31% <ø> (?)
no-c-ext-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 56.29% <ø> (?)
no-c-ext-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 62.60% <ø> (?)
no-c-ext-rhel8-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 57.74% <ø> (?)
no-c-ext-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 55.94% <ø> (?)
ocsp-rhel8-test-ocsp-ecdsa-valid-cert-server-staples-latest-python3.14-cov 34.11% <ø> (?)
ocsp-rhel8-test-ocsp-rsa-valid-cert-server-staples-latest-python3.14-cov 34.08% <ø> (?)
pyopenssl-macos-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.64% <ø> (?)
pyopenssl-rhel8-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.64% <ø> (?)
pyopenssl-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.59% <ø> (?)
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.08% <ø> (?)
stable-api-accept-v2-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (?)
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.07% <ø> (?)
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.13-async-auth-ssl-sharded-cluster-cov 56.40% <ø> (?)
stable-api-require-v1-rhel8-auth-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.72% <ø> (?)
storage-inmemory-rhel8-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.09% <ø> (?)
storage-inmemory-rhel8-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.74% <ø> (?)
test-macos-arm64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.06% <ø> (?)
test-macos-arm64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.38% <ø> (?)
test-macos-arm64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.71% <ø> (?)
test-macos-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 55.06% <ø> (?)
test-macos-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.71% <ø> (?)
test-numpy-macos-arm64-test-numpy-python3.14-python3.14-cov 32.64% <ø> (?)
test-numpy-macos-test-numpy-python3.14-python3.14-cov 32.62% <ø> (?)
test-numpy-rhel8-test-numpy-python3.14-python3.14-cov 32.62% <ø> (?)
test-numpy-win32-test-numpy-python3.14-python3.14-cov 32.60% <ø> (?)
test-numpy-win64-test-numpy-python3.14-python3.14-cov 32.60% <ø> (?)
test-win32-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 54.93% <ø> (?)
test-win32-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.36% <ø> (?)
test-win32-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.58% <ø> (?)
test-win64-test-standard-latest-python3.11-async-noauth-nossl-standalone-cov 54.92% <ø> (?)
test-win64-test-standard-latest-python3.12-async-noauth-ssl-replica-set-cov 61.35% <ø> (?)
test-win64-test-standard-latest-python3.14-async-noauth-nossl-standalone-cov 54.58% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

_get_gcp_response("https://example.com")
self.assertIn("Failed to acquire IMDS access token", str(ctx.exception))

def test_urlopen_exception_raises_value_error(self):
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.

Is this test adding anything that the previous one doesn't? The previous test already contains self.assertRaises(ValueError).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, HTTP status errors != connection refused.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@aclark4life aclark4life merged commit f41dd5c into mongodb:master Apr 14, 2026
81 of 83 checks passed
@aclark4life aclark4life deleted the PYTHON-5772 branch April 14, 2026 20:53
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.

4 participants