-
Notifications
You must be signed in to change notification settings - Fork 178
Add api tests stateless #1242
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
Add api tests stateless #1242
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
23753e7
Add api tests stateless
fege 28d329f
Fix github action failures, lint and nox
fege e81a14a
Add too_slow and remove code to force the model version id
fege f67b1a8
Add filter_too_much
fege 25ef85b
add hook to avoid Unsatisfiable
fege 7043310
remove variable
fege 631168d
Merge branch 'main' of github.com:fege/model-registry-kubeflow into R…
fege 09d24f9
add artifact_states
fege 1059bf7
Merge branch 'main' of github.com:fege/model-registry-kubeflow into R…
fege e9ec8e3
Add example to schema
fege d8210c4
Add example in src
fege 9ff33ce
register strategy for string of int64
fege b785fcf
sort imports
fege 325f26f
Merge branch 'main' of github.com:fege/model-registry-kubeflow into R…
fege b686d7b
modify case for problematic endpoints
fege 79e9e21
add more examples
fege 3b8becc
Merge branch 'main' of github.com:fege/model-registry-kubeflow into R…
fege f9ad748
pin urllib
fege 7374841
Merge branch 'main' of github.com:fege/model-registry-kubeflow into R…
fege f40a007
exclude problematic endpoints and test with valid data
fege ed65e4b
Add gha to run the test and mark them with fuzz
fege 29c759f
revert change in Makefile pushed by error
fege 7ca6053
skip test not marked with e2e or fuzz, trigger the fuzz on pr comment
fege 0fa6cdf
trigger with label
fege d69c88d
correct the label name
fege 063fa94
add types and semplify the if
fege 57d7ecf
do not run e2e if test-fuzz label is added
fege 7abe73c
unpin urllib
fege 47d67ea
modify lock
fege 3454603
fix: remove proc on label
Al-Pragliola 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ | |
| __pycache__/ | ||
| venv/ | ||
| .port-forwards.pid | ||
| .hypothesis/ | ||
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| base-url = "${API_HOST}" | ||
|
|
||
| [generation] | ||
| # Don't shrink failing examples to save time | ||
| no-shrink = true |
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ARTIFACT_STATES = [ | ||
| "LIVE", | ||
| "PENDING", | ||
| "MARKED_FOR_DELETION", | ||
| "DELETED", | ||
| "ABANDONED", | ||
| "REFERENCE", | ||
| "UNKNOWN", | ||
| ] | ||
| ARTIFACT_TYPE_PARAMS = [ | ||
| ("model-artifact", "s3://test-bucket/models/"), | ||
| ("doc-artifact", "https://docs.example.com/docs/"), | ||
| ] | ||
| DEFAULT_API_TIMEOUT = 5.0 | ||
|
|
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 |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import secrets | ||
| from typing import Callable | ||
|
|
||
| import pytest | ||
| import requests | ||
| import schemathesis | ||
| from hypothesis import HealthCheck, settings | ||
|
|
||
| from .conftest import REGISTRY_URL | ||
| from .constants import ARTIFACT_STATES, ARTIFACT_TYPE_PARAMS, DEFAULT_API_TIMEOUT | ||
|
|
||
| schema = schemathesis.pytest.from_fixture("generated_schema") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def auth_headers(setup_env_user_token): | ||
| """Provides authorization headers for API requests.""" | ||
| return { | ||
| "Content-Type": "application/json", | ||
| "Authorization": f"Bearer {setup_env_user_token}" | ||
| } | ||
|
|
||
| schema = ( | ||
| schema | ||
| .exclude( | ||
| path="/api/model_registry/v1alpha3/artifacts/{id}", | ||
| method="PATCH" | ||
| ) | ||
| .exclude( | ||
| path="/api/model_registry/v1alpha3/model_versions/{modelversionId}/artifacts", | ||
| method="POST" | ||
| ) | ||
| ) | ||
| @schema.parametrize() | ||
| @settings( | ||
| max_examples=100, | ||
| deadline=None, | ||
| suppress_health_check=[ | ||
| HealthCheck.filter_too_much, | ||
| HealthCheck.too_slow, | ||
| HealthCheck.data_too_large, | ||
| ], | ||
| ) | ||
| @pytest.mark.fuzz | ||
| def test_mr_api_stateless(auth_headers: dict, case: schemathesis.Case): | ||
| """Test the Model Registry API endpoints. | ||
|
|
||
| This test uses schemathesis to generate and validate API requests | ||
| """ | ||
|
|
||
| case.call_and_validate(headers=auth_headers) | ||
|
|
||
| @pytest.mark.fuzz | ||
| @pytest.mark.parametrize(("artifact_type", "uri_prefix"), ARTIFACT_TYPE_PARAMS) | ||
| @pytest.mark.parametrize("state", ARTIFACT_STATES) | ||
| def test_post_model_version_artifacts(auth_headers: dict, artifact_type: str, uri_prefix: str, state: str, cleanup_artifacts: Callable): | ||
| """ | ||
| Direct test for POST /api/model_registry/v1alpha3/model_versions/{modelversionId}/artifacts. | ||
| """ | ||
| model_version_id = str(secrets.randbelow(2000000000 - 100000 + 1) + 100000) | ||
|
|
||
| endpoint = f"{REGISTRY_URL}/api/model_registry/v1alpha3/model_versions/{model_version_id}/artifacts" | ||
|
|
||
| payload = { | ||
| "artifactType": artifact_type, | ||
| "name": "my-test-model-artifact-post", | ||
| "uri": f"{uri_prefix}my-test-model.pkl", | ||
| "state": state, | ||
| "description": "A test model artifact created via direct POST test.", | ||
| "externalId": str(secrets.randbelow(2000000000 - 100000 + 1) + 100000) | ||
| } | ||
|
|
||
| response = requests.post(endpoint, headers=auth_headers, json=payload, timeout=DEFAULT_API_TIMEOUT) | ||
| artifact_id = response.json()["id"] | ||
| cleanup_artifacts(artifact_id) | ||
|
|
||
| assert response.status_code in {200, 201}, f"Expected 200 or 201, got {response.status_code}: {response.text}" | ||
| response_json = response.json() | ||
| assert response_json.get("id"), "Response body should contain 'id'" | ||
| assert response_json.get("name") == payload["name"], "Response name should match payload name" | ||
| assert response_json.get("artifactType") == payload["artifactType"], "Response artifactType should match payload" | ||
|
|
||
|
|
||
| @pytest.mark.fuzz | ||
| @pytest.mark.parametrize(("artifact_type", "uri_prefix"), ARTIFACT_TYPE_PARAMS) | ||
| def test_patch_artifact(auth_headers: dict, artifact_resource: Callable, artifact_type: str, uri_prefix: str): | ||
| """ | ||
| Direct test for PATCH /api/model_registry/v1alpha3/artifacts/{id}. | ||
| """ | ||
| initial_state = "PENDING" | ||
| target_state = "LIVE" | ||
|
|
||
| create_payload = { | ||
| "artifactType": artifact_type, | ||
| "name": "test-create-for-patch", | ||
| "uri": "s3://my-test-bucket/models/initial-model.pkl", | ||
| "state": initial_state, | ||
| } | ||
| if artifact_type == "model-artifact": | ||
| create_payload["modelFormatName"] = "tensorflow" | ||
| create_payload["modelFormatVersion"] = "1.0" | ||
|
|
||
|
|
||
| with artifact_resource(auth_headers, create_payload) as artifact_id: | ||
| patch_endpoint = f"{REGISTRY_URL}/api/model_registry/v1alpha3/artifacts/{artifact_id}" | ||
| patch_payload = { | ||
| "artifactType": artifact_type, | ||
| "description": f"Updated description for {artifact_type} ({target_state})", | ||
| "state": target_state, | ||
| } | ||
| patch_response = requests.patch(patch_endpoint, headers=auth_headers, json=patch_payload, timeout=DEFAULT_API_TIMEOUT) | ||
| assert patch_response.status_code == 200 | ||
| patch_response_json = patch_response.json() | ||
| assert patch_response_json.get("id") == artifact_id | ||
| assert patch_response_json.get("description") == patch_payload["description"] | ||
| assert patch_response_json.get("state") == patch_payload["state"] | ||
| assert patch_response_json.get("artifactType") == artifact_type |
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.