-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow both
int
and str
for limit and offset
Update the `validate_input` function in `utils.py` to allow for both `int` and `str` types for the `limit` and `offset` parameters in the `search`.
- Loading branch information
Showing
3 changed files
with
81 additions
and
42 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
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 |
---|---|---|
@@ -1,24 +1,55 @@ | ||
import pytest | ||
|
||
from pyradios.utils import types | ||
from pyradios.utils import bool_to_string | ||
from pyradios.utils import validate_input | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"inp, expected", | ||
[(True, "true"), (False, "false")] | ||
) | ||
@pytest.mark.parametrize('inp, expected', [(True, 'true'), (False, 'false')]) | ||
def test_bool_to_string(inp, expected): | ||
assert bool_to_string(inp) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"inp, expected", | ||
'inp, expected', | ||
[ | ||
("a", pytest.raises(TypeError)), | ||
('a', pytest.raises(TypeError)), | ||
(1, pytest.raises(TypeError)), | ||
], | ||
) | ||
def test_bool_to_string_value_error(inp, expected): | ||
with expected as exc_info: | ||
bool_to_string(inp) | ||
assert "Value must be True or False." == str(exc_info.value) | ||
assert 'Value must be True or False.' == str(exc_info.value) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'input_data', | ||
[{'limit': 10, 'offset': 0}, {'limit': '10', 'offset': '0'}], | ||
) | ||
def test_validate_input(input_data): | ||
""" | ||
Allow `str` and `int` for limit and offset | ||
""" | ||
validate_input(types['search'], input_data) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'input_data, expected', | ||
[ | ||
({'limit': 10, 'offset': 'a'}, ('offset', '`int` or `str`', 'str')), | ||
({'limit': 10.1}, ('limit', '`int` or `str`', 'float')), | ||
( | ||
{'offset': True, 'limit': None}, | ||
('offset', '`int` or `str`', 'bool'), | ||
), | ||
({'limit': None}, ('limit', '`int` or `str`', 'NoneType')), | ||
], | ||
) | ||
def test_validate_input_with_invalid_limit_and_offset(input_data, expected): | ||
with pytest.raises(TypeError) as exc: | ||
validate_input(types['search'], input_data) | ||
|
||
assert str(exc.value) == 'Argument {!r} must be {}, not {}'.format( | ||
*expected | ||
) |