Skip to content

Commit

Permalink
Consistent Pytest marks
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Tisnovsky <[email protected]>
  • Loading branch information
tisnik committed Dec 4, 2024
1 parent e784f8b commit 4534d5a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions tests/e2e/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def postgres_connection():
return retrieve_connection()


@pytest.mark.smoketest()
@pytest.mark.smoketest
@retry(max_attempts=3, wait_between_runs=10)
def test_readiness():
"""Test handler for /readiness REST API endpoint."""
Expand All @@ -110,7 +110,7 @@ def test_readiness():
assert response.json() == {"ready": True, "reason": "service is ready"}


@pytest.mark.smoketest()
@pytest.mark.smoketest
def test_liveness():
"""Test handler for /liveness REST API endpoint."""
endpoint = "/liveness"
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_one_default_model_provider():
), "one model and provider should be selected as default"


@pytest.mark.cluster()
@pytest.mark.cluster
def test_improper_token():
"""Test accessing /v1/query endpoint using improper auth. token."""
response = client.post(
Expand All @@ -181,7 +181,7 @@ def test_improper_token():
assert response.status_code == requests.codes.forbidden


@pytest.mark.cluster()
@pytest.mark.cluster
def test_forbidden_user():
"""Test scenarios where we expect an unauthorized response.
Expand All @@ -198,7 +198,7 @@ def test_forbidden_user():
assert response.status_code == requests.codes.forbidden


@pytest.mark.cluster()
@pytest.mark.cluster
def test_transcripts_storing_cluster():
"""Test if the transcripts are stored properly."""
transcripts_path = OLS_USER_DATA_PATH + "/transcripts"
Expand Down Expand Up @@ -364,7 +364,7 @@ def test_conversation_in_postgres_cache(postgres_connection) -> None:
assert "OpenShift" in deserialized[3].content


@pytest.mark.cluster()
@pytest.mark.cluster
def test_user_data_collection():
"""Test user data collection.
Expand Down Expand Up @@ -475,7 +475,7 @@ def get_last_log_line(logs: str) -> str:
cluster_utils.create_file(pod_name, OLS_COLLECTOR_DISABLING_FILE, "")


@pytest.mark.cluster()
@pytest.mark.cluster
def test_http_header_redaction():
"""Test that sensitive HTTP headers are redacted from the logs."""
for header in HTTP_REQUEST_HEADERS_TO_REDACT:
Expand All @@ -499,7 +499,7 @@ def test_http_header_redaction():
assert f'"{header}":"some_value"' not in container_log


@pytest.mark.response_evaluation()
@pytest.mark.response_evaluation
def test_model_response(request) -> None:
"""Evaluate model response."""
args = Namespace(**vars(request.config.option))
Expand All @@ -514,14 +514,14 @@ def test_model_response(request) -> None:
assert val_success_flag


@pytest.mark.model_evaluation()
@pytest.mark.model_evaluation
def test_model_evaluation(request) -> None:
"""Evaluate model."""
# TODO: Use this to assert.
ResponseEvaluation(request.config.option, client).evaluate_models()


@pytest.mark.azure_entra_id()
@pytest.mark.azure_entra_id
def test_azure_entra_id():
"""Test single question via Azure Entra ID credentials."""
response = client.post(
Expand Down
10 changes: 5 additions & 5 deletions tests/e2e/test_query_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def test_too_long_question() -> None:
assert json_response["detail"]["response"] == "Prompt is too long"


@pytest.mark.smoketest()
@pytest.mark.rag()
@pytest.mark.smoketest
@pytest.mark.rag
def test_valid_question() -> None:
"""Check the REST API /v1/query with POST HTTP method for valid question and no yaml."""
endpoint = "/v1/query"
Expand Down Expand Up @@ -228,7 +228,7 @@ def test_valid_question() -> None:
)


@pytest.mark.rag()
@pytest.mark.rag
def test_ocp_docs_version_same_as_cluster_version() -> None:
"""Check that the version of OCP docs matches the cluster we're on."""
endpoint = "/v1/query"
Expand Down Expand Up @@ -354,7 +354,7 @@ def test_token_counters_for_query_call_with_improper_payload() -> None:
response_utils.check_content_type(response, "application/json")


@pytest.mark.rag()
@pytest.mark.rag
@retry(max_attempts=3, wait_between_runs=10)
def test_rag_question() -> None:
"""Ensure responses include rag references."""
Expand Down Expand Up @@ -382,7 +382,7 @@ def test_rag_question() -> None:
assert len(doc_urls_list) == len(set(doc_urls_list))


@pytest.mark.cluster()
@pytest.mark.cluster
def test_query_filter() -> None:
"""Ensure responses does not include filtered words and redacted words are not logged."""
endpoint = "/v1/query"
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/test_user_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import test_api


@pytest.mark.cluster()
@pytest.mark.cluster
def test_feedback_can_post_with_wrong_token():
"""Test posting feedback with improper auth. token."""
response = test_api.client.post(
Expand All @@ -26,7 +26,7 @@ def test_feedback_can_post_with_wrong_token():
assert response.status_code == requests.codes.forbidden


@pytest.mark.cluster()
@pytest.mark.cluster
def test_feedback_storing_cluster():
"""Test if the feedbacks are stored properly."""
feedbacks_path = test_api.OLS_USER_DATA_PATH + "/feedback"
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/test_ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def validate_question(_conversation_id, query):
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
)
@pytest.mark.attachment()
@pytest.mark.attachment
def test_post_question_with_empty_list_of_attachments(_setup) -> None:
"""Check the REST API /v1/query with POST HTTP method with empty list of attachments."""
answer = constants.SUBJECT_ALLOWED
Expand Down Expand Up @@ -527,7 +527,7 @@ def validate_question(_conversation_id, query):
assert query_passed == "test query"


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -584,7 +584,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -650,7 +650,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -736,7 +736,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -800,7 +800,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -866,7 +866,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
@patch(
"ols.app.endpoints.ols.config.ols_config.query_validation_method",
constants.QueryValidationMethod.LLM,
Expand Down Expand Up @@ -932,7 +932,7 @@ def validate_question(_conversation_id, query):
assert query_passed == expected


@pytest.mark.attachment()
@pytest.mark.attachment
def test_post_question_with_large_attachment(_setup) -> None:
"""Check the REST API /v1/query with POST HTTP method with large attachment."""
answer = constants.SUBJECT_ALLOWED
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
redis_cache: RedisCache


@pytest.mark.redis()
@pytest.mark.redis
def setup():
"""Setups the Redis client."""
global redis_cache
Expand All @@ -32,7 +32,7 @@ def setup():
redis_cache = RedisCache(redis_config)


@pytest.mark.redis()
@pytest.mark.redis
def test_conversation_in_redis():
"""Check the elementary GET operation and insert_or_append operation."""
# make sure the cache is empty
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/auth/test_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_singleton_pattern():


@pytest.mark.usefixtures("_setup")
@pytest.mark.asyncio()
@pytest.mark.asyncio
@patch("ols.src.auth.k8s.K8sClientSingleton.get_authn_api")
@patch("ols.src.auth.k8s.K8sClientSingleton.get_authz_api")
async def test_auth_dependency_valid_token(mock_authz_api, mock_authn_api):
Expand All @@ -68,7 +68,7 @@ async def test_auth_dependency_valid_token(mock_authz_api, mock_authn_api):


@pytest.mark.usefixtures("_setup")
@pytest.mark.asyncio()
@pytest.mark.asyncio
@patch("ols.src.auth.k8s.K8sClientSingleton.get_authn_api")
@patch("ols.src.auth.k8s.K8sClientSingleton.get_authz_api")
async def test_auth_dependency_invalid_token(mock_authz_api, mock_authn_api):
Expand All @@ -95,7 +95,7 @@ async def test_auth_dependency_invalid_token(mock_authz_api, mock_authn_api):


@pytest.mark.usefixtures("_setup")
@pytest.mark.asyncio()
@pytest.mark.asyncio
@patch("ols.src.auth.k8s.K8sClientSingleton.get_authz_api")
async def test_cluster_id_is_used_for_kube_admin(mock_authz_api):
"""Test the cluster id is used as user_id when user is kube:admin."""
Expand Down

0 comments on commit 4534d5a

Please sign in to comment.