2021-01-24 19:53:51 +00:00
|
|
|
from unittest import TestCase
|
2021-01-24 20:25:26 +00:00
|
|
|
from owrx.property.validators import Validator, NumberValidator, LambdaValidator, StringValidator
|
2021-01-24 19:53:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ValidatorTest(TestCase):
|
|
|
|
|
|
|
|
def testReturnsValidator(self):
|
|
|
|
validator = NumberValidator()
|
|
|
|
self.assertIs(validator, Validator.of(validator))
|
|
|
|
|
|
|
|
def testTransformsLambda(self):
|
|
|
|
def my_callable(v):
|
|
|
|
return True
|
|
|
|
validator = Validator.of(my_callable)
|
|
|
|
self.assertIsInstance(validator, LambdaValidator)
|
|
|
|
self.assertTrue(validator.isValid("test"))
|
2021-01-24 20:25:26 +00:00
|
|
|
|
|
|
|
def testGetsValidatorByKey(self):
|
|
|
|
validator = Validator.of("str")
|
|
|
|
self.assertIsInstance(validator, StringValidator)
|