Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    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
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    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)
Exemplo n.º 18
0
    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
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
    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
Exemplo n.º 21
0
    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)
Exemplo n.º 22
0
    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"]
Exemplo n.º 23
0
    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)