def test_lazy(self): def just_ack(ack): ack() def async1(say): time.sleep(0.3) say(text="lazy function 1") def async2(say): time.sleep(0.5) say(text="lazy function 2") app = App( client=self.web_client, signing_secret=self.signing_secret, ) app.action("a")( ack=just_ack, lazy=[async1, async2], ) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 time.sleep(1) # wait a bit assert self.mock_received_requests["/chat.postMessage"] == 2
def test_success_without_type(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) app.options("dialog-callback-id")(handle_suggestion) app.action("dialog-callback-id")(handle_submission_cancellation) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body != "" assert response.headers["content-type"][ 0] == "application/json;charset=utf-8" assert self.mock_received_requests["/auth.test"] == 1 request = self.build_valid_request(submission_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert self.mock_received_requests["/auth.test"] == 1 request = self.build_valid_request(cancellation_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert self.mock_received_requests["/auth.test"] == 1
def test_default_type_and_unmatched_block_id(self): app = App(client=self.web_client, signing_secret=self.signing_secret) app.action({"action_id": "a", "block_id": "bbb"})(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1
def test_default_type(self): app = App(client=self.web_client, signing_secret=self.signing_secret) app.action({"action_id": "a", "block_id": "b"})(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert_auth_test_count(self, 1)
def test_success_without_type(self): app = App(client=self.web_client, signing_secret=self.signing_secret,) app.action("pick_channel_for_fun")(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert self.mock_received_requests["/auth.test"] == 1
def test_success(self): app = App(client=self.web_client, signing_secret=self.signing_secret,) app.action( {"callback_id": "pick_channel_for_fun", "type": "interactive_message",} )(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert self.mock_received_requests["/auth.test"] == 1
def test_failure_without_type(self): app = App(client=self.web_client, signing_secret=self.signing_secret,) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1 app.action("unknown")(simple_listener) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1
def test_success(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) app.action("a")(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert_auth_test_count(self, 1)
def test_process_before_response(self): app = App( client=self.web_client, signing_secret=self.signing_secret, process_before_response=True, ) app.action("a")(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert self.mock_received_requests["/auth.test"] == 1
def test_failure(self): app = App(client=self.web_client, signing_secret=self.signing_secret,) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1 app.action({"callback_id": "unknown", "type": "interactive_message",})( simple_listener ) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1
def test_failure(self): app = App( client=self.web_client, authorize=error_authorize, signing_secret=self.signing_secret, ) app.action("a")(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert response.body == ":x: Please install this app into the workspace :bow:" assert self.mock_received_requests.get("/auth.test") == None
def test_success(self): app = App( client=self.web_client, authorize=authorize, signing_secret=self.signing_secret, ) app.action("a")(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert self.mock_received_requests["/auth.test"] == 1
def test_user_context_attributes(self): app = App( client=self.web_client, authorize=user_authorize, signing_secret=self.signing_secret, ) app.action("a")(assert_user_context_attributes) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert_auth_test_count(self, 1)
def test_default(self): def failing_listener(): raise Exception("Something wrong!") app = App( client=self.web_client, signing_secret=self.signing_secret, ) app.action("a")(failing_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 500
def test_bot_context_attributes(self): app = App( client=self.web_client, authorize=authorize, signing_secret=self.signing_secret, ) app.action("a")(assert_bot_context_attributes) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert self.mock_received_requests["/auth.test"] == 1
def test_failure_without_type(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1) app.action("unknown")(simple_listener) response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1)
def test_submission_failure_without_type(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1) app.action("dialog-callback-iddddd")(handle_submission) response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1)
def test_cancellation_failure_without_type(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1 app.action("dialog-callback-iddddd")(handle_cancellation) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1
def test_cancellation_failure_2(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1) app.action({ "type": "dialog_cancellation", "callback_id": "dialog-callback-iddddd" })(handle_cancellation) response = app.dispatch(request) assert response.status == 404 assert_auth_test_count(self, 1)
def test_submission_failure_2(self): app = App( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1 app.action({ "type": "dialog_submission", "callback_id": "dialog-callback-iddddd" })(handle_submission) response = app.dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 2
def test_process_before_response(self): app = App( client=self.web_client, signing_secret=self.signing_secret, process_before_response=True, ) app.action( { "callback_id": "pick_channel_for_fun", "type": "interactive_message", } )(simple_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 200 assert_auth_test_count(self, 1)
def test_custom(self): def error_handler(logger, payload, response): logger.info(payload) response.headers["x-test-result"] = ["1"] def failing_listener(): raise Exception("Something wrong!") app = App( client=self.web_client, signing_secret=self.signing_secret, ) app.error(error_handler) app.action("a")(failing_listener) request = self.build_valid_request() response = app.dispatch(request) assert response.status == 500 assert response.headers["x-test-result"] == ["1"]
def test_process_before_response(self): app = App( client=self.web_client, signing_secret=self.signing_secret, process_before_response=True, ) app.options({ "type": "dialog_suggestion", "callback_id": "dialog-callback-id" })(handle_suggestion) app.action({ "type": "dialog_submission", "callback_id": "dialog-callback-id" })(handle_submission) app.action({ "type": "dialog_cancellation", "callback_id": "dialog-callback-id" })(handle_cancellation) request = self.build_valid_request(suggestion_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body != "" assert response.headers["content-type"][ 0] == "application/json;charset=utf-8" assert_auth_test_count(self, 1) request = self.build_valid_request(submission_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert_auth_test_count(self, 1) request = self.build_valid_request(cancellation_raw_body) response = app.dispatch(request) assert response.status == 200 assert response.body == "" assert_auth_test_count(self, 1)