Exemplo n.º 1
0
 async def publish(self, obj: Any, **kwargs):
     """
     Publishes given event.
     :param obj: event object
     :param kwargs: event extra arguments
     """
     await self._scheduler.schedule(
         ActionSubject(subject=obj, inject=kwargs))
Exemplo n.º 2
0
 async def execute(self, obj: Any, **kwargs):
     """
     Executes given request.
     :param obj: request object
     :param kwargs: request extra arguments
     :raises LookupHandlerStoreError:
     when there is no matching handler to process given request
     :return: request processing result
     """
     result = await self._executor(ActionSubject(subject=obj,
                                                 inject=kwargs))
     assert isinstance(
         result, ActionResult
     ), "modifier or handler should provide `ActionResult` type object"
     return result.result
Exemplo n.º 3
0
async def test_direct_handler_create_successful(
    obj,
    sig,
    name: Optional[str],
    arg_map: Dict[str, str],
    expected_result,
):
    get_details = CallableObjDetails()
    arg_get = HandlerSubjectArgGet(name=name)
    handler_create = CallableHandlerCreate(
        subject_as_keyword=name is not None,
        arg_map=arg_map,
        arg_strict=True,
    )

    details = get_details(sig)
    arg = arg_get(details)
    details.obj = obj
    handler = handler_create(details, arg, obj)

    result = await handler(ActionSubject(subject="test", inject={"x": 1, "y": 2}))
    assert isinstance(result, ActionResult)
    assert result.result == expected_result
Exemplo n.º 4
0
async def _check_handler_works(handler: Handler):
    result = await handler(ActionSubject(subject="test", inject={}))
    assert result.result == "test"
Exemplo n.º 5
0
def action():
    return ActionSubject(subject="test", inject={"a": 10, "b": 20})
Exemplo n.º 6
0
 def create_action():
     return ActionSubject("test", inject={})
Exemplo n.º 7
0
def action():
    return ActionSubject(subject="test", inject={})
Exemplo n.º 8
0
 async def _op(action: ActionSubject):
     if "seq" not in action.inject:
         action.inject["seq"] = []
     seq = action.inject["seq"]
     seq.append(seq_item)
     return await call(action)
Exemplo n.º 9
0
async def _check_handler(handler: Handler):
    action = ActionSubject(subject="test", inject={"x": 1, "y": 2})
    result: ActionResult = await handler(action)
    assert result.result == ("test", 1, 2)