def test_block_action(self): body = { "type": "block_actions", "actions": [{ "type": "button", "action_id": "valid_action_id", "block_id": "b", "action_ts": "111.222", "value": "v", }], } raw_body = f"payload={quote(json.dumps(body))}" headers = {"Content-Type": "application/x-www-form-urlencoded"} req = BoltRequest(body=raw_body, headers=headers) resp = BoltResponse(status=404) assert block_action("valid_action_id").matches(req, resp) is True assert block_action("invalid_action_id").matches(req, resp) is False assert block_action(re.compile("valid_.+")).matches(req, resp) is True assert block_action(re.compile("invalid_.+")).matches(req, resp) is False assert action("valid_action_id").matches(req, resp) is True assert action("invalid_action_id").matches(req, resp) is False assert action(re.compile("valid_.+")).matches(req, resp) is True assert action(re.compile("invalid_.+")).matches(req, resp) is False assert action({ "action_id": "valid_action_id" }).matches(req, resp) is True assert action({ "action_id": "invalid_action_id" }).matches(req, resp) is False assert action({ "action_id": re.compile("valid_.+") }).matches(req, resp) is True assert (action({ "action_id": re.compile("invalid_.+") }).matches(req, resp) is False) # block_id + action_id assert (action({ "action_id": "valid_action_id", "block_id": "b" }).matches(req, resp) is True) assert (action({ "action_id": "invalid_action_id", "block_id": "b" }).matches(req, resp) is False) assert (action({ "action_id": re.compile("valid_.+"), "block_id": "b" }).matches(req, resp) is True) assert (action({ "action_id": re.compile("invalid_.+"), "block_id": "b" }).matches(req, resp) is False) assert (action({ "action_id": "valid_action_id", "block_id": "bbb" }).matches(req, resp) is False) assert (action({ "action_id": "invalid_action_id", "block_id": "bbb" }).matches(req, resp) is False) assert (action({ "action_id": re.compile("valid_.+"), "block_id": "bbb" }).matches(req, resp) is False) assert (action({ "action_id": re.compile("invalid_.+"), "block_id": "bbb" }).matches(req, resp) is False) # with type assert (action({ "action_id": "valid_action_id", "type": "block_actions" }).matches(req, resp) is True) assert (action({ "callback_id": "valid_action_id", "type": "interactive_message" }).matches(req, resp) is False) assert (action({ "callback_id": "valid_action_id", "type": "workflow_step_edit" }).matches(req, resp) is False)
def __call__(*args, **kwargs): functions = self._to_listener_functions( kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.action(constraints, True) return self._register_listener(list(functions), primary_matcher, matchers, middleware)
def __call__(func): primary_matcher = builtin_matchers.action(constraints, True) return self._register_listener(func, primary_matcher, matchers, middleware)