-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/* PR_START p--sq-order-by-limit 03 */ Add validation for the limit i…
…n a saved query.
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,76 @@ | ||
import copy | ||
|
||
from dbt_semantic_interfaces.implementations.saved_query import ( | ||
PydanticSavedQuery, | ||
PydanticSavedQueryQueryParams, | ||
) | ||
from dbt_semantic_interfaces.implementations.semantic_manifest import ( | ||
PydanticSemanticManifest, | ||
) | ||
from dbt_semantic_interfaces.validations.saved_query import SavedQueryRule | ||
from dbt_semantic_interfaces.validations.semantic_manifest_validator import ( | ||
SemanticManifestValidator, | ||
) | ||
from tests.validations.test_saved_query import check_only_one_error_with_message | ||
|
||
|
||
def test_invalid_limit( # noqa: D | ||
simple_semantic_manifest__with_primary_transforms: PydanticSemanticManifest, | ||
) -> None: | ||
manifest = copy.deepcopy(simple_semantic_manifest__with_primary_transforms) | ||
manifest.saved_queries = [ | ||
PydanticSavedQuery( | ||
name="Example Saved Query", | ||
description="Example description.", | ||
query_params=PydanticSavedQueryQueryParams( | ||
metrics=["listings"], | ||
limit=-1, | ||
), | ||
), | ||
] | ||
|
||
manifest_validator = SemanticManifestValidator[PydanticSemanticManifest]([SavedQueryRule()]) | ||
check_only_one_error_with_message( | ||
manifest_validator.validate_semantic_manifest(manifest), | ||
"Invalid limit value", | ||
) | ||
|
||
|
||
def test_valid_limit( # noqa: D | ||
simple_semantic_manifest__with_primary_transforms: PydanticSemanticManifest, | ||
) -> None: | ||
manifest = copy.deepcopy(simple_semantic_manifest__with_primary_transforms) | ||
manifest.saved_queries = [ | ||
PydanticSavedQuery( | ||
name="Example Saved Query", | ||
description="Example description.", | ||
query_params=PydanticSavedQueryQueryParams( | ||
metrics=["listings"], | ||
limit=1, | ||
), | ||
), | ||
] | ||
|
||
manifest_validator = SemanticManifestValidator[PydanticSemanticManifest]([SavedQueryRule()]) | ||
results = manifest_validator.validate_semantic_manifest(manifest) | ||
assert results.all_issues == () | ||
|
||
|
||
def test_zero_limit( # noqa: D | ||
simple_semantic_manifest__with_primary_transforms: PydanticSemanticManifest, | ||
) -> None: | ||
manifest = copy.deepcopy(simple_semantic_manifest__with_primary_transforms) | ||
manifest.saved_queries = [ | ||
PydanticSavedQuery( | ||
name="Example Saved Query", | ||
description="Example description.", | ||
query_params=PydanticSavedQueryQueryParams( | ||
metrics=["listings"], | ||
limit=0, | ||
), | ||
), | ||
] | ||
|
||
manifest_validator = SemanticManifestValidator[PydanticSemanticManifest]([SavedQueryRule()]) | ||
results = manifest_validator.validate_semantic_manifest(manifest) | ||
assert results.all_issues == () |