-
Notifications
You must be signed in to change notification settings - Fork 32
✅ [Maintenance] Fixes api-server/tests/unit/pact_broker testing
#8473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8c75e6
doc
pcrespov 93914ec
fixes test
pcrespov 245b26a
improve skip
pcrespov 71998c9
doc
pcrespov 0810667
note
pcrespov 21d809b
Update services/api-server/tests/unit/pact_broker/test_pact_checkout_…
pcrespov d3e6d9c
fixes
pcrespov feb6a7f
Merge branch 'master' into fix/pact-tests
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,32 @@ | ||
| # Contract testing (PACT) | ||
|
|
||
| Maintainer @matusdrobuliak66 | ||
| - Maintainer @matusdrobuliak66 | ||
|
|
||
| ## How to run this test as a provider? | ||
|
|
||
| ```bash | ||
| PACT_BROKER_URL=<fill-broker-url> PACT_BROKER_USERNAME=<fill-username> PACT_BROKER_PASSWORD=<fill-secret> make test-pacts | ||
| PACT_BROKER_URL=<fill-broker-url> PACT_BROKER_USERNAME=<fill-username> PACT_BROKER_PASSWORD=<fill-secret> | ||
|
|
||
| make test-pacts | ||
| ``` | ||
|
|
||
| ## Install and Publish new contract to Broker | ||
| ## How to run this test locally? | ||
|
|
||
| - Still not implemented | ||
| - The idea would be use local copies of the pacts (see services/api-server/tests/unit/pact_broker/pacts/*.json) instead of reaching the pact server for them. | ||
|
|
||
| ## How to install and Publish new contract to Broker? | ||
|
|
||
| Contracts are generated by Consumer (ex. Sim4Life) | ||
| TODO: add reference to Sim4life repo where they can be generated | ||
| #### Install | ||
|
|
||
| ### Install | ||
|
|
||
| ```bash | ||
| npm install @pact-foundation/pact-cli | ||
| ``` | ||
|
|
||
| #### Publish | ||
|
|
||
| ```bash | ||
| pact-broker publish ./pacts/05_licensed_items.json --tag licensed_items --consumer-app-version 8.2.1 --broker-base-url=<fill-broker-url> --broker-username=<fill-username> --broker-password=<fill-secret> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,10 +37,10 @@ def pytest_addoption(parser: pytest.Parser) -> None: | |
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| @pytest.fixture | ||
| def pact_broker_credentials( | ||
| request: pytest.FixtureRequest, | ||
| ): | ||
| ) -> tuple[str, str, str]: | ||
| # Get credentials from either CLI arguments or environment variables | ||
| broker_url = request.config.getoption("--broker-url", None) or os.getenv( | ||
| "PACT_BROKER_URL" | ||
|
|
@@ -64,18 +64,20 @@ def pact_broker_credentials( | |
| ] | ||
|
|
||
| if missing: | ||
| pytest.fail( | ||
| f"Missing Pact Broker credentials: {', '.join(missing)}. Set them as environment variables or pass them as CLI arguments." | ||
| pytest.skip( | ||
| reason="This test runs only if pact broker credentials are provided. " | ||
| f"Missing Pact Broker credentials: {', '.join(missing)}. " | ||
| "Set them as environment variables or pass them as CLI arguments. " | ||
| ) | ||
|
|
||
| return broker_url, broker_username, broker_password | ||
|
|
||
| assert broker_url | ||
| assert broker_username | ||
| assert broker_password | ||
|
|
||
| def mock_get_current_identity() -> Identity: | ||
| return Identity(user_id=1, product_name="osparc", email="[email protected]") | ||
| return broker_url, broker_username, broker_password | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| @pytest.fixture | ||
| def running_test_server_url( | ||
| app: FastAPI, | ||
| ): | ||
|
|
@@ -84,8 +86,12 @@ def running_test_server_url( | |
| The 'mocked_catalog_service' fixture ensures the function is already | ||
| patched by the time we start the server. | ||
| """ | ||
|
|
||
| # Override | ||
| app.dependency_overrides[get_current_identity] = mock_get_current_identity | ||
| def _mock_get_current_identity() -> Identity: | ||
| return Identity(user_id=1, product_name="osparc", email="[email protected]") | ||
|
|
||
| app.dependency_overrides[get_current_identity] = _mock_get_current_identity | ||
|
|
||
| port = unused_port() | ||
| base_url = f"http://localhost:{port}" | ||
|
|
@@ -106,5 +112,6 @@ def running_test_server_url( | |
|
|
||
| yield base_url # , before_server_start | ||
|
|
||
| app.dependency_overrides.pop(get_current_identity, None) | ||
| server.should_exit = True | ||
| thread.join() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.