Beispiel #1
0
    def test_raise_validate_input_decorator_dict(self):
        real_decorator = validate_input(dict, ["a", "b", "c"])
        wrapper = real_decorator(lambda *args, **kwargs: 911)

        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [])
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), {})
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), {"a": 1})
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), {"a": 1, "b": 1})
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), {"a": 1, "b": 1, "d": 1})

        self.assertEqual(wrapper(Mock(), {"a": 1, "b": 1, "c": 1}), 911)
Beispiel #2
0
    def test_raise_validate_input_decorator_list(self):
        real_decorator = validate_input(list, ["p", "q"])
        wrapper = real_decorator(lambda *args, **kwargs: 911)

        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), dict)
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [{}])
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [{"p"}])
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [{"p": 1, "q": 1}, []])
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [{"p": 1, "q": 1}, {}])
        self.assertRaises(UbidotsInvalidInputError, wrapper, Mock(), [{"p": 1, "q": 1}, {"p": 2}])

        self.assertEqual(wrapper(Mock(), [{"p": 1, "q": 1}]), 911)
        self.assertEqual(wrapper(Mock(), [{"p": 1, "q": 1}, {"p": 2, "q": 2}]), 911)