Skip to content

Conversation

@jonpspri
Copy link
Contributor

@jonpspri jonpspri commented Oct 26, 2025

Summary

Resolves warnings in tests/e2e/test_main_apis.py caused by improper mock patching and fixes e2e test failures caused by multi-tenancy implementation.

Changes

Multi-Tenancy Test Fixes

  • Added "teams": [] to JWT token payloads in test_admin_apis.py and test_main_apis.py to allow access to public resources and own private resources
  • Set "visibility": "public" for test servers, prompts, and resources to ensure proper access with public-only tokens
  • Fixed string escaping in resource data test (test_main_apis.py:979)

Test Fixes (tests/e2e/test_main_apis.py and tests/e2e/test_admin_apis.py)

  • Fixed improper mock patching that caused warnings during test execution
  • Corrected mock_settings fixture to use MagicMock(wraps=) instead of nested patch context
  • Simplified settings mock in test_admin_apis.py (replaced patch with MagicMock)
  • Cleaned up logging setup in test_admin_apis.py
  • Removed duplicate UTF-8 encoding pragmas
  • Simplified JWT generation logic

Dependencies

  • Added missing pytest-timeout>=2.4.0 package to dev dependencies to ensure timeout decorations are properly honored during test execution

Test Plan

  • All tests in tests/e2e/test_main_apis.py and tests/e2e/test_admin_apis.py execute without warnings
  • Multi-tenancy (team) tests pass with proper visibility and token configuration
  • Test coverage maintained
  • All existing tests continue to pass

Fixes warnings in test execution and multi-tenancy test failures that were causing noise in test output and CI logs.

Signed-off-by: Jonathan Springer [email protected]

Copilot AI review requested due to automatic review settings October 26, 2025 11:24
Copy link
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

This PR fixes test warnings caused by improper mock patching in the E2E test suite. The main issue was that the mock_settings fixture used nested patch contexts incorrectly, which has been resolved by using MagicMock(wraps=) instead. Additionally, the PR includes code cleanup: removing duplicate UTF-8 encoding pragmas, consolidating duplicate JWT generation functions, adding type ignore comments for pyrefly, and applying consistent code formatting.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


resource_data = {
"resource": urllib.parse.quote_plus('{"uri":"config/formtest","name":"form_test","description":"Form resource","mimeType":"application/json","content":"{\"key\":\"value\"}"}'),
"resource": urllib.parse.quote_plus('{"uri":"config/formtest","name":"form_test","description":"Form resource","mimeType":"application/json","content":"{"key":"value"}"}'),
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

The JSON string contains unescaped double quotes inside the 'content' field, which will cause a syntax error. The inner JSON object's quotes need to be escaped: \"content\":\"{\\\"key\\\":\\\"value\\\"}\"

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Corrected using a python raw string and backslashes.

@jonpspri jonpspri marked this pull request as draft October 27, 2025 07:21
@jonpspri
Copy link
Contributor Author

Holding behind PR #1331

@jonpspri jonpspri marked this pull request as ready for review October 28, 2025 15:51
Fixed issues in e2e tests caused by multi-tenancy (team) implementation:

- Added "teams": [] to JWT token payloads in test_admin_apis.py and test_main_apis.py to allow access to public resources and own private resources
- Set "visibility": "public" for test servers, prompts, and resources to ensure proper access with public-only tokens
- Simplified settings mock in test_admin_apis.py (replaced patch with MagicMock)
- Fixed string escaping in resource data test (test_main_apis.py:979)
- Cleaned up logging setup in test_admin_apis.py

Added missing pytest-timeout>=2.4.0 package to dev dependencies to ensure timeout decorations are properly honored during test execution.

Signed-off-by: Jonathan Springer <[email protected]>
@crivetimihai crivetimihai merged commit 28454be into IBM:main Oct 28, 2025
44 checks passed
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