-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/add concept filters field validation (#128)
* Adding a pydantic validation and relating check to ensure that in browse mode concept filters are not set. * Updating validation check and tests. * Updating the version. * Resolving failing test. * updating the error message. --------- Co-authored-by: Mark <[email protected]>
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
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
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,47 @@ | ||
from typing import Optional | ||
|
||
import pytest | ||
from pydantic_core import ValidationError | ||
|
||
from cpr_sdk.models.search import SearchParameters | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"params,expect_error,error_message", | ||
[ | ||
({"query_string": "the"}, False, None), | ||
({"query_string": ""}, False, None), | ||
( | ||
{ | ||
"query_string": "", | ||
"documents_only": True, | ||
"all_results": True, | ||
"concept_filters": [{"name": "name", "value": "environment"}], | ||
}, | ||
True, | ||
"Cannot set concept_filters when only searching documents.", | ||
), | ||
( | ||
{ | ||
"query_string": "", | ||
"documents_only": False, | ||
"concept_filters": [{"name": "name", "value": "environment"}], | ||
}, | ||
False, | ||
None, | ||
), | ||
], | ||
) | ||
@pytest.mark.vespa | ||
def test_vespa_search_parameters( | ||
params: dict, expect_error: bool, error_message: Optional[str] | ||
) -> None: | ||
"""Test that we can correctly instantiate the SearchParameters object.""" | ||
if expect_error: | ||
with pytest.raises( | ||
ValidationError, | ||
match=error_message, | ||
): | ||
SearchParameters.model_validate(params) | ||
else: | ||
SearchParameters.model_validate(params) |