-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PY-544][external] Item query & Item ID query sorting functionality +…
… some linting (#764) * Item query * Item ID query sorting functionality + some linting * Typing * Fixed typing issue
- Loading branch information
Showing
8 changed files
with
161 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from typing import Literal, Optional | ||
|
||
from pydantic import BaseModel, Field, root_validator | ||
|
||
|
||
class SortingMethods(BaseModel): | ||
accuracy: Optional[Literal["asc", "desc"]] = Field(None) | ||
byte_size: Optional[Literal["asc", "desc"]] = Field(None) | ||
id: Optional[Literal["asc", "desc"]] = Field(None) | ||
map: Optional[Literal["asc", "desc"]] = Field(None) | ||
name: Optional[Literal["asc", "desc"]] = Field(None) | ||
priority: Optional[Literal["asc", "desc"]] = Field(None) | ||
updated_at: Optional[Literal["asc", "desc"]] = Field(None) | ||
|
||
@root_validator(pre=True) | ||
def check_at_least_one_field(cls, values): | ||
assert any(value is not None for value in values.values()) | ||
return values |
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,25 @@ | ||
import pytest | ||
from pydantic import ValidationError | ||
|
||
from darwin.future.data_objects.sorting import SortingMethods | ||
|
||
|
||
def test_sorting_methods_all_fields_none(): | ||
with pytest.raises(ValidationError): | ||
SortingMethods() | ||
|
||
|
||
def test_sorting_methods_one_field_set(): | ||
sorting = SortingMethods(accuracy="asc") | ||
assert sorting.accuracy == "asc" | ||
|
||
|
||
def test_sorting_methods_multiple_fields_set(): | ||
sorting = SortingMethods(accuracy="asc", byte_size="desc") | ||
assert sorting.accuracy == "asc" | ||
assert sorting.byte_size == "desc" | ||
|
||
|
||
def test_sorting_methods_invalid_value(): | ||
with pytest.raises(ValidationError): | ||
SortingMethods(accuracy="invalid") |
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