make validator abstract, unit tests for bool and str validator
This commit is contained in:
parent
6215496c10
commit
84db8d20be
5 changed files with 42 additions and 1 deletions
0
tests/unit/validators/__init__.py
Normal file
0
tests/unit/validators/__init__.py
Normal file
0
tests/unit/validators/conftest.py
Normal file
0
tests/unit/validators/conftest.py
Normal file
20
tests/unit/validators/test_bool_validator.py
Normal file
20
tests/unit/validators/test_bool_validator.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import pytest
|
||||
|
||||
from ytdl_subscribe.validators.base.validators import BoolValidator
|
||||
from ytdl_subscribe.validators.exceptions import ValidationException
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [True, False])
|
||||
def test_bool_validator(value):
|
||||
bool_validator = BoolValidator(name="good_bool_validator", value=value)
|
||||
assert bool_validator._name == "good_bool_validator"
|
||||
assert bool_validator._value == value
|
||||
assert bool_validator.value == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [None, {}, "True", 0])
|
||||
def test_bool_validator_fails_bad_value(value):
|
||||
with pytest.raises(
|
||||
ValidationException, match="Validation error in fail: should be of type bool"
|
||||
):
|
||||
_ = BoolValidator(name="fail", value=value)
|
||||
20
tests/unit/validators/test_string_validator.py
Normal file
20
tests/unit/validators/test_string_validator.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import pytest
|
||||
|
||||
from ytdl_subscribe.validators.base.validators import StringValidator
|
||||
from ytdl_subscribe.validators.exceptions import ValidationException
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ["a", "unicode 💩", ""])
|
||||
def test_string_validator(value):
|
||||
bool_validator = StringValidator(name="good_str_validator", value=value)
|
||||
assert bool_validator._name == "good_str_validator"
|
||||
assert bool_validator._value == value
|
||||
assert bool_validator.value == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [None, {}, True, 0])
|
||||
def test_bool_validator_fails_bad_value(value):
|
||||
with pytest.raises(
|
||||
ValidationException, match="Validation error in fail: should be of type string"
|
||||
):
|
||||
_ = StringValidator(name="fail", value=value)
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from abc import ABC
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
|
@ -8,7 +9,7 @@ from typing import TypeVar
|
|||
from ytdl_subscribe.validators.exceptions import ValidationException
|
||||
|
||||
|
||||
class Validator:
|
||||
class Validator(ABC):
|
||||
"""
|
||||
Used to validate the value of a python object. This is the 'base' class that will first
|
||||
check that the value's type matches the expected type. Validators that inherit from this should
|
||||
|
|
|
|||
Loading…
Reference in a new issue