Ejemplo n.º 1
0
    def test_call(self, message):
        _f = mock.MagicMock()

        def f(message: Message):
            _f(message)

        Callback(f).call(message)
        _f.assert_called_once_with(message)
Ejemplo n.º 2
0
    def validate_callback(self) -> None:
        from hedwig.callback import Callback

        try:
            self._callback = Callback.find_by_message(
                self.type, self.data_schema_version.version[0])
        except CallbackNotFound:
            raise ValidationError
Ejemplo n.º 3
0
 def test_str(self):
     assert str(Callback(self.f)) == 'Hedwig task: f'
Ejemplo n.º 4
0
 def test_find_by_name_fail(self):
     with pytest.raises(CallbackNotFound):
         Callback.find_by_message(MessageType.vehicle_created, 1)
Ejemplo n.º 5
0
 def test_find_by_message(self):
     assert Callback.find_by_message(MessageType.trip_created,
                                     1)._fn == trip_created_handler
Ejemplo n.º 6
0
 def test_constructor_unknown_param(self):
     with pytest.raises(ConfigurationError):
         Callback(TestCallback.f_unknown_param)
Ejemplo n.º 7
0
 def test_constructor_bad_annotation(self):
     with pytest.raises(ConfigurationError):
         Callback(TestCallback.f_invalid_annotation)
Ejemplo n.º 8
0
 def test_constructor_disallow_args(self):
     with pytest.raises(ConfigurationError):
         Callback(TestCallback.f_args)
Ejemplo n.º 9
0
 def test_constructor(self):
     task_obj = Callback(TestCallback.f)
     assert task_obj.fn is TestCallback.f