From fb9a461371ca51fdddec3dd4d00d795a412866fc Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Wed, 7 Jan 2026 09:10:43 +0100 Subject: [PATCH 1/4] Added docstrings into test_authentication_configuration.py --- .../test_authentication_configuration.py | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/tests/unit/models/config/test_authentication_configuration.py b/tests/unit/models/config/test_authentication_configuration.py index 7d89f7644..b50c88a80 100644 --- a/tests/unit/models/config/test_authentication_configuration.py +++ b/tests/unit/models/config/test_authentication_configuration.py @@ -137,7 +137,13 @@ def test_authentication_configuration_rh_identity_more_entitlements() -> None: def test_authentication_configuration_rh_identity_but_insufficient_config() -> None: - """Test the AuthenticationConfiguration with RH identity token.""" + """Test the AuthenticationConfiguration with RH identity token. + + Verify that selecting the RH Identity authentication module without + providing a RHIdentityConfiguration raises a validation error. + + Expects a ValidationError with the message "RH Identity configuration must be specified". + """ with pytest.raises( ValidationError, match="RH Identity configuration must be specified" @@ -171,7 +177,15 @@ def test_authentication_configuration_jwk_token() -> None: def test_authentication_configuration_jwk_token_but_insufficient_config() -> None: - """Test the AuthenticationConfiguration with JWK token.""" + """Test the AuthenticationConfiguration with JWK token. + + Verify that using the JWK token module with an insufficient + `JwkConfiguration` triggers validation. + + Attempts to construct an `AuthenticationConfiguration` with + `module=AUTH_MOD_JWK_TOKEN` and an empty `JwkConfiguration` must raise a + `ValidationError` containing the text "JwkConfiguration". + """ with pytest.raises(ValidationError, match="JwkConfiguration"): AuthenticationConfiguration( @@ -200,7 +214,15 @@ def test_authentication_configuration_jwk_token_but_not_config() -> None: def test_authentication_configuration_jwk_broken_config() -> None: - """Test the AuthenticationConfiguration with JWK set, but not configured.""" + """Test the AuthenticationConfiguration with JWK set, but not configured. + + Verify that accessing `jwk_configuration` raises a ValueError after the JWK + config is removed. + + Creates an AuthenticationConfiguration with a JWK configuration, clears its + `jwk_config`, and asserts that accessing `jwk_configuration` raises + ValueError with message "JWK configuration should not be None". + """ auth_config = AuthenticationConfiguration( module=AUTH_MOD_JWK_TOKEN, @@ -220,7 +242,13 @@ def test_authentication_configuration_jwk_broken_config() -> None: def test_authentication_configuration_supported() -> None: - """Test the AuthenticationConfiguration constructor.""" + """Test the AuthenticationConfiguration constructor. + + Verify AuthenticationConfiguration initializes correctly for the K8S authentication module. + + Asserts that the module is set to K8S, `skip_tls_verification` is False, + and both `k8s_ca_cert_path` and `k8s_cluster_api` are None. + """ auth_config = AuthenticationConfiguration( module=AUTH_MOD_K8S, skip_tls_verification=False, @@ -296,7 +324,18 @@ def test_authentication_configuration_in_config_k8s() -> None: def test_authentication_configuration_in_config_rh_identity() -> None: - """Test the authentication configuration in main config.""" + """Test the authentication configuration in main config. + + Verify that a Configuration with RH Identity authentication is constructed + with the expected authentication fields. + + Asserts that: + - authentication.module is set to RH Identity, + - skip_tls_verification is True, + - k8s_ca_cert_path is converted to a Path for the provided certificate file, + - k8s_cluster_api is None, + - an RHIdentityConfiguration is attached to the authentication. + """ # pylint: disable=no-member cfg = Configuration( name="test_name", From 666e349e7c58dbe4ef52d6b8d5ff28c2c1c8a8b6 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Wed, 7 Jan 2026 09:11:00 +0100 Subject: [PATCH 2/4] Added docstrings into test_conversation_history.py --- .../config/test_conversation_history.py | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/tests/unit/models/config/test_conversation_history.py b/tests/unit/models/config/test_conversation_history.py index 95958e6f8..f1d4f2c1a 100644 --- a/tests/unit/models/config/test_conversation_history.py +++ b/tests/unit/models/config/test_conversation_history.py @@ -17,13 +17,25 @@ def test_conversation_cache_no_type_specified() -> None: - """Check the test for type as optional attribute.""" + """Check the test for type as optional attribute. + + Verify that a ConversationHistoryConfiguration created with no arguments + has its type set to None. + """ c = ConversationHistoryConfiguration() assert c.type is None def test_conversation_cache_unknown_type() -> None: - """Check the test for cache type.""" + """Check the test for cache type. + + Verify that providing an invalid conversation cache type raises a + ValidationError with the expected message. + + The test constructs a ConversationHistoryConfiguration with an unsupported + type value and asserts that validation fails with the message: "Input + should be 'noop', 'memory', 'sqlite' or 'postgres'". + """ with pytest.raises( ValidationError, match="Input should be 'noop', 'memory', 'sqlite' or 'postgres'", @@ -32,7 +44,15 @@ def test_conversation_cache_unknown_type() -> None: def test_conversation_cache_correct_type_but_not_configured(subtests: SubTests) -> None: - """Check the test for cache type.""" + """Check the test for cache type. + + Verify that specifying a cache type without providing its corresponding + backend configuration raises a ValidationError with the expected message. + + Parameters: + subtests (SubTests): pytest_subtests SubTests object used to create + subtests for memory, sqlite, and postgres cases. + """ with subtests.test(msg="Memory cache"): with pytest.raises( ValidationError, match="Memory cache is selected, but not configured" @@ -53,7 +73,16 @@ def test_conversation_cache_correct_type_but_not_configured(subtests: SubTests) def test_conversation_cache_no_type_but_configured(subtests: SubTests) -> None: - """Check the test for cache type.""" + """Check the test for cache type. + + Verify that providing a backend configuration without specifying a + conversation cache type raises a ValidationError. + + This test asserts that constructing ConversationHistoryConfiguration with a + memory, sqlite, or postgres backend (but without setting the `type` field) + fails with a ValidationError whose message is "Conversation cache type must + be set when backend configuration is provided". + """ m = "Conversation cache type must be set when backend configuration is provided" with subtests.test(msg="Memory cache"): @@ -137,7 +166,17 @@ def test_conversation_type_memory() -> None: def test_conversation_type_memory_wrong_config() -> None: - """Test the memory conversation cache configuration.""" + """Test the memory conversation cache configuration. + + Verify that selecting the memory conversation cache raises validation + errors for missing or invalid memory configuration. + + Asserts: + - A missing `max_entries` field in the memory configuration raises a + ValidationError with "Field required". + - A `max_entries` value less than or equal to zero raises a ValidationError + with "Input should be greater than 0". + """ with pytest.raises(ValidationError, match="Field required"): _ = ConversationHistoryConfiguration( type=constants.CACHE_TYPE_MEMORY, @@ -165,7 +204,15 @@ def test_conversation_type_sqlite() -> None: def test_conversation_type_sqlite_wrong_config() -> None: - """Test the SQLite conversation cache configuration.""" + """Test the SQLite conversation cache configuration. + + Validate that selecting the SQLite conversation cache while supplying an + incorrect backend configuration raises a validation error. + + This test asserts that when `type` is set to the SQLite cache but a + `memory` configuration is provided instead of an `sqlite` configuration, + model validation fails with a "Field required" error. + """ with pytest.raises(ValidationError, match="Field required"): _ = ConversationHistoryConfiguration( type=constants.CACHE_TYPE_SQLITE, @@ -198,7 +245,13 @@ def test_conversation_type_postgres() -> None: def test_conversation_type_postgres_wrong_config() -> None: - """Test the SQLite conversation cache configuration.""" + """Test the SQLite conversation cache configuration. + + Ensure a ValidationError is raised when PostgreSQL configuration is missing required fields. + + This test provides an empty PostgreSQLDatabaseConfiguration and expects + validation to fail with a "Field required" message. + """ with pytest.raises(ValidationError, match="Field required"): _ = ConversationHistoryConfiguration( type=constants.CACHE_TYPE_POSTGRES, From f3759bb6fe7da76ccca01e8eed4a54c720891518 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Wed, 7 Jan 2026 09:11:16 +0100 Subject: [PATCH 3/4] Added docstrings into test_dump_configuration.py --- tests/unit/models/config/test_dump_configuration.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/models/config/test_dump_configuration.py b/tests/unit/models/config/test_dump_configuration.py index 456d38c52..1df46c4a5 100644 --- a/tests/unit/models/config/test_dump_configuration.py +++ b/tests/unit/models/config/test_dump_configuration.py @@ -32,6 +32,9 @@ def test_dump_configuration(tmp_path: Path) -> None: that the resulting file contains all expected sections and values. Please note that redaction process is not in place. + + Parameters: + tmp_path (Path): Directory where the test JSON file will be written. """ cfg = Configuration( name="test_name", From 1ac114a70046cb950b9786c0512b633943a36655 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Wed, 7 Jan 2026 09:11:30 +0100 Subject: [PATCH 4/4] Added docstrings into test_jwt_role_rule.py --- .../config/test_conversation_history.py | 2 +- .../unit/models/config/test_jwt_role_rule.py | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/unit/models/config/test_conversation_history.py b/tests/unit/models/config/test_conversation_history.py index f1d4f2c1a..48731cb6f 100644 --- a/tests/unit/models/config/test_conversation_history.py +++ b/tests/unit/models/config/test_conversation_history.py @@ -245,7 +245,7 @@ def test_conversation_type_postgres() -> None: def test_conversation_type_postgres_wrong_config() -> None: - """Test the SQLite conversation cache configuration. + """Test the PostgreSQL conversation cache configuration. Ensure a ValidationError is raised when PostgreSQL configuration is missing required fields. diff --git a/tests/unit/models/config/test_jwt_role_rule.py b/tests/unit/models/config/test_jwt_role_rule.py index 2422372c2..971167a91 100644 --- a/tests/unit/models/config/test_jwt_role_rule.py +++ b/tests/unit/models/config/test_jwt_role_rule.py @@ -8,13 +8,26 @@ def test_jwt_role_rule_missing_attributes() -> None: - """Check the JwtRoleRule config class.""" + """Check the JwtRoleRule config class. + + Ensure constructing JwtRoleRule without any attributes raises a ValidationError. + + Asserts that instantiating JwtRoleRule with no fields provided raises a + ValidationError whose message contains "validation errors". + """ with pytest.raises(ValidationError, match="validation errors"): _ = JwtRoleRule() def test_jwt_role_rule_correct_attributes() -> None: - """Check the JwtRoleRule config class.""" + """Check the JwtRoleRule config class. + + Verify that a JwtRoleRule instantiated with valid attributes is created and + does not compile a regex for non-MATCH operators. + + Asserts that an instance is returned and that `compiled_regex` is `None` + when the operator is not `JsonPathOperator.MATCH`. + """ r = JwtRoleRule( jsonpath="$.id", negate=False, @@ -28,7 +41,13 @@ def test_jwt_role_rule_correct_attributes() -> None: def test_jwt_role_rule_invalid_json_path() -> None: - """Check the JwtRoleRule config class.""" + """Check the JwtRoleRule config class. + + Verifies that constructing JwtRoleRule with an invalid JSONPath expression + raises a ValidationError. + + Asserts the raised ValidationError contains the message "Invalid JSONPath expression". + """ with pytest.raises(ValidationError, match="Invalid JSONPath expression"): _ = JwtRoleRule( jsonpath="this/is/not/valid", @@ -106,7 +125,20 @@ def test_jwt_role_rule_valid_regexp() -> None: def test_jwt_role_rule_invalid_regexp() -> None: - """Check the JwtRoleRule config class.""" + """Check the JwtRoleRule config class. + + Ensure creating a JwtRoleRule with an invalid regex pattern for the MATCH + operator raises a ValidationError. + + Attempts to construct JwtRoleRule with operator set to + JsonPathOperator.MATCH and a malformed regex value; the constructor must + raise a ValidationError with message "Invalid regex pattern for MATCH + operator". + + Raises: + ValidationError: if the provided regex pattern for MATCH is invalid + (message contains "Invalid regex pattern for MATCH operator"). + """ with pytest.raises( ValidationError, match="Invalid regex pattern for MATCH operator" ):