make validator abstract, unit tests for bool and str validator

This commit is contained in:
jbannon 2022-04-05 07:00:45 +00:00
parent 6215496c10
commit 84db8d20be
5 changed files with 42 additions and 1 deletions

View file

View file

View 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)

View 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)

View file

@ -1,3 +1,4 @@
from abc import ABC
from typing import Any from typing import Any
from typing import Dict from typing import Dict
from typing import List from typing import List
@ -8,7 +9,7 @@ from typing import TypeVar
from ytdl_subscribe.validators.exceptions import ValidationException 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 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 check that the value's type matches the expected type. Validators that inherit from this should