Ejemplo n.º 1
0
class TestTemplateValidator(unittest.TestCase):
    def setUp(self):
        self.funckey_validator = Mock(FuncKeyValidator)
        self.validator = TemplateValidator(self.funckey_validator)

    def test_given_unknown_fields_when_validating_then_raises_error(self):
        body = {"name": "foobar", "invalid": "invalid"}

        assert_that(calling(self.validator.validate).with_args(body), raises(InputError))

    def test_given_invalid_keys_mapping_when_validating_then_raises_error(self):
        body = {"name": "foobar", "keys": "spam"}

        assert_that(calling(self.validator.validate).with_args(body), raises(InputError))

    def test_given_keys_mapping_are_negative_when_validating_then_raises_error(self):
        body = {"name": "foobar", "keys": {-1: "spam"}}

        assert_that(calling(self.validator.validate).with_args(body), raises(InputError))

    def test_given_mapping_when_validating_then_validates_using_funckey_validator(self):
        funckey = {"type": "spam"}
        body = {"name": "foobar", "keys": {1: funckey}}

        self.validator.validate(body)
        self.funckey_validator.validate.assert_called_once_with(funckey)
Ejemplo n.º 2
0
 def setUp(self):
     self.funckey_validator = Mock(FuncKeyValidator)
     self.validator = TemplateValidator(self.funckey_validator)