Exemplo n.º 1
0
class TestFuncKeyValidator(unittest.TestCase):
    def setUp(self):
        self.builder = Mock(DestinationBuilder)
        self.validator = FuncKeyValidator({"foobar": self.builder})

    def test_given_required_fields_missing_when_creating_then_raises_error(self):
        body = {}

        assert_that(calling(self.validator.validate).with_args(body, action="create"), raises(InputError))

    def test_given_destination_has_wrong_type_when_creating_then_raises_error(self):
        body = {"destination": "invalid"}

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

    def test_given_destination_has_no_type_when_creating_then_raises_error(self):
        body = {"destination": {}}

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

    def test_given_unknown_destination_type_when_creating_then_raises_error(self):
        body = {"destination": {"type": "invalid"}}

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

    def test_given_destination_when_validating_then_calls_destination_validator(self):
        destination = {"type": "foobar"}
        body = {"destination": destination}

        self.validator.validate(body)

        self.builder.validate.assert_called_once_with(destination)
Exemplo n.º 2
0
 def setUp(self):
     self.builder = Mock(DestinationBuilder)
     self.validator = FuncKeyValidator({"foobar": self.builder})