-
Notifications
You must be signed in to change notification settings - Fork 68
test(maas): add subscription enforcement tests for TinyLlama #1163
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
sheltoncyril
merged 5 commits into
opendatahub-io:main
from
SB159:feature/maas_subscription_test2
Mar 3, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6856b63
test(maas): add subscription enforcement tests for TinyLlama
SB159 112932b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0334ae5
test(maas): address coderabit review comments
SB159 e8237de
test(maas): remove redundant LOGGER.info per review
SB159 6eeb4c9
Merge branch 'main' into feature/maas_subscription_test2
sheltoncyril 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
95 changes: 95 additions & 0 deletions
95
tests/model_serving/model_server/maas_billing/maas_subscription/test_maas_sub_enforcement.py
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,95 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| import requests | ||
| from simple_logger.logger import get_logger | ||
|
|
||
| from tests.model_serving.model_server.maas_billing.maas_subscription.utils import chat_payload_for_url | ||
| from tests.model_serving.model_server.maas_billing.utils import build_maas_headers | ||
|
|
||
| LOGGER = get_logger(name=__name__) | ||
|
|
||
| MAAS_SUBSCRIPTION_HEADER = "x-maas-subscription" | ||
| INVALID_SUBSCRIPTION = "does-not-exist" | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures( | ||
| "maas_unprivileged_model_namespace", | ||
| "maas_controller_enabled_latest", | ||
| "maas_gateway_api", | ||
| "maas_api_gateway_reachable", | ||
| "maas_inference_service_tinyllama_premium", | ||
| "maas_model_tinyllama_premium", | ||
| "maas_auth_policy_tinyllama_premium", | ||
| "maas_subscription_tinyllama_premium", | ||
| ) | ||
| class TestSubscriptionEnforcementTinyLlama: | ||
| """Tests that MaaSSubscription correctly enforces subscription selection & limits.""" | ||
|
|
||
| @pytest.mark.sanity | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "premium"}], indirect=True) | ||
| def test_subscribed_user_gets_200( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| ocp_token_for_actor: str, | ||
| ) -> None: | ||
| resp = request_session_http.post( | ||
| url=model_url_tinyllama_premium, | ||
| headers=build_maas_headers(token=ocp_token_for_actor), | ||
| json=chat_payload_for_url(model_url=model_url_tinyllama_premium), | ||
| timeout=60, | ||
| ) | ||
| LOGGER.info(f"test_subscribed_user_gets_200 -> {resp.status_code}") | ||
| assert resp.status_code == 200, f"Expected 200, got {resp.status_code}: {resp.text[:200]}" | ||
|
|
||
| @pytest.mark.sanity | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "premium"}], indirect=True) | ||
| def test_explicit_subscription_header_works( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| ocp_token_for_actor: str, | ||
| maas_subscription_tinyllama_premium, | ||
| ) -> None: | ||
| """ | ||
| - Send valid x-maas-subscription | ||
| - Expect 200 | ||
| """ | ||
| headers = build_maas_headers(token=ocp_token_for_actor) | ||
| headers[MAAS_SUBSCRIPTION_HEADER] = maas_subscription_tinyllama_premium.name | ||
|
|
||
| resp = request_session_http.post( | ||
| url=model_url_tinyllama_premium, | ||
| headers=headers, | ||
| json=chat_payload_for_url(model_url=model_url_tinyllama_premium), | ||
| timeout=60, | ||
| ) | ||
| LOGGER.info(f"test_explicit_subscription_header_works -> {resp.status_code}") | ||
|
|
||
| assert resp.status_code == 200, f"Expected 200, got {resp.status_code}: {resp.text[:200]}" | ||
|
|
||
| @pytest.mark.sanity | ||
| @pytest.mark.parametrize("ocp_token_for_actor", [{"type": "premium"}], indirect=True) | ||
| def test_invalid_subscription_header_gets_429( | ||
| self, | ||
| request_session_http: requests.Session, | ||
| model_url_tinyllama_premium: str, | ||
| ocp_token_for_actor: str, | ||
| ) -> None: | ||
| """ | ||
| - Send invalid x-maas-subscription | ||
| - Expect 429 or 403 | ||
| """ | ||
| headers = build_maas_headers(token=ocp_token_for_actor) | ||
| headers[MAAS_SUBSCRIPTION_HEADER] = INVALID_SUBSCRIPTION | ||
|
|
||
| resp = request_session_http.post( | ||
| url=model_url_tinyllama_premium, | ||
| headers=headers, | ||
| json=chat_payload_for_url(model_url=model_url_tinyllama_premium), | ||
| timeout=60, | ||
| ) | ||
| LOGGER.info(f"test_invalid_subscription_header_gets_429 -> {resp.status_code}") | ||
|
|
||
| assert resp.status_code in (429, 403), f"Expected 429 or 403, got {resp.status_code}: {resp.text[:200]}" | ||
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.