-
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.
Apply optional value and tests for Request
- Loading branch information
1 parent
d2ff8dc
commit 0bc1122
Showing
2 changed files
with
63 additions
and
19 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,59 @@ | ||
import pytest | ||
from tol_lab_share import error_codes | ||
from tol_lab_share.messages.properties.complex.request import Request | ||
from tol_lab_share.messages.properties.simple.dict_value import Value | ||
|
||
|
||
@pytest.fixture | ||
def valid_request(request): | ||
return Value( | ||
{ | ||
"costCode": "CostCode789", | ||
"libraryType": "LibraryType123", | ||
"studyUuid": b"12345678-1234-1234-1234-1234567890ab", | ||
**request.param, | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def invalid_request(): | ||
return Value( | ||
{ | ||
"costCode": 1234, | ||
"studyUuid": "12345678-1234-1234-1234-1234567890ab", | ||
} | ||
) | ||
|
||
|
||
def check_error_is_present(sample, error_code, field): | ||
assert any( | ||
[((x.type_id == error_code.type_id) and (x.field == field)) for x in sample.errors] | ||
), f"Error type '{error_code.type_id}' for field '{field}' not found among {sample.errors}" | ||
|
||
|
||
class TestBioscanPoolXpSample: | ||
@pytest.mark.parametrize( | ||
"valid_request", [{}, {"genomeSize": ""}, {"genomeSize": "1,234,567,890 bp"}], indirect=True | ||
) | ||
def test_validators_when_request_is_valid(self, valid_request): | ||
print(valid_request.value) | ||
instance = Request(valid_request) | ||
assert instance.validate() is True | ||
assert len(instance.errors) == 0 | ||
|
||
def test_validators_when_request_incomplete(self): | ||
instance = Request(Value({})) | ||
assert instance.validate() is False | ||
assert len(instance.errors) > 0 | ||
|
||
def test_validators_when_request_is_invalid(self, invalid_request): | ||
instance = Request(invalid_request) | ||
assert instance.validate() is False | ||
|
||
check_error_is_present(instance, error_codes.ERROR_2_NOT_STRING, "cost_code") | ||
check_error_is_present(instance, error_codes.ERROR_9_INVALID_INPUT, "library_type") | ||
check_error_is_present(instance, error_codes.ERROR_1_UUID_NOT_BINARY, "study_uuid") | ||
check_error_is_present(instance, error_codes.ERROR_2_UUID_NOT_RIGHT_FORMAT, "study_uuid") | ||
|
||
assert len(instance.errors) == 4 |
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