abderbejaoui commented on code in PR #38490:
URL: https://github.com/apache/superset/pull/38490#discussion_r3553227274
##########
tests/unit_tests/databases/schema_tests.py:
##########
@@ -347,6 +347,277 @@ def test_import_schema_rejects_masked_fields_for_new_db(
assert "$.credentials_info.private_key" in error_messages
+def test_extra_validator_rejects_negative_schema_cache_timeout() -> None:
+ """
+ Test that extra_validator rejects negative schema_cache_timeout values.
+ """
+ from superset.databases.schemas import DatabasePostSchema
+
+ schema = DatabasePostSchema()
+ payload = {
+ "database_name": "test_db",
+ "extra": json.dumps({"metadata_cache_timeout":
{"schema_cache_timeout": -1}}),
+ }
+ with pytest.raises(ValidationError) as exc_info:
+ schema.load(payload)
+ assert "non-negative integer" in str(exc_info.value)
+
+
+def test_extra_validator_rejects_negative_table_cache_timeout() -> None:
+ """
+ Test that extra_validator rejects negative table_cache_timeout values.
+ """
+ from superset.databases.schemas import DatabasePostSchema
+
+ schema = DatabasePostSchema()
+ payload = {
+ "database_name": "test_db",
+ "extra": json.dumps({"metadata_cache_timeout": {"table_cache_timeout":
-5}}),
+ }
+ with pytest.raises(ValidationError) as exc_info:
+ schema.load(payload)
+ assert "non-negative integer" in str(exc_info.value)
+
+
+def test_extra_validator_accepts_zero_cache_timeout() -> None:
+ """
+ Test that extra_validator accepts zero as a valid cache timeout.
+ """
+ from superset.databases.schemas import DatabasePostSchema
+
+ schema = DatabasePostSchema()
+ payload = {
+ "database_name": "test_db",
+ "extra": json.dumps(
+ {
+ "metadata_cache_timeout": {
+ "schema_cache_timeout": 0,
+ "table_cache_timeout": 0,
+ }
+ }
+ ),
+ }
+ result = schema.load(payload)
+ extra = json.loads(result["extra"])
+ assert extra["metadata_cache_timeout"]["schema_cache_timeout"] == 0
+ assert extra["metadata_cache_timeout"]["table_cache_timeout"] == 0
+
+
+def test_extra_validator_accepts_positive_cache_timeout() -> None:
+ """
+ Test that extra_validator accepts positive cache timeout values.
+ """
+ from superset.databases.schemas import DatabasePostSchema
+
+ schema = DatabasePostSchema()
+ payload = {
+ "database_name": "test_db",
+ "extra": json.dumps(
+ {
+ "metadata_cache_timeout": {
+ "schema_cache_timeout": 600,
+ "table_cache_timeout": 1200,
+ }
+ }
+ ),
+ }
+ result = schema.load(payload)
+ extra = json.loads(result["extra"])
Review Comment:
Leaving as-is for consistency. Local variables like
`schema`/`payload`/`result`/`extra` aren't annotated anywhere in this test file
— the whole suite relies on mypy's inference — so annotating only these would
be inconsistent with the surrounding tests without adding type safety.
Resolving.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]