async def test_instance_methods_uncommon_name(self):
     app = AsyncApp(client=self.web_client,
                    signing_secret=self.signing_secret)
     awesome = AwesomeClass("Slackbot")
     app.use(awesome.instance_middleware)
     app.shortcut("test-shortcut")(awesome.instance_method2)
     await self.run_app_and_verify(app)
Example #2
0
    async def test_success_global(self):
        app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
        app.shortcut("test-shortcut")(simple_listener)

        request = self.build_valid_request(global_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 200
        assert self.mock_received_requests["/auth.test"] == 1
Example #3
0
    async def test_no_next_call(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
        )
        app.use(no_next)
        app.shortcut("test-shortcut")(just_ack)

        response = await app.async_dispatch(self.build_request())
        assert response.status == 404
        assert self.mock_received_requests["/auth.test"] == 1
Example #4
0
    async def test_no_next_call(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
        )
        app.use(no_next)
        app.shortcut("test-shortcut")(just_ack)

        response = await app.async_dispatch(self.build_request())
        assert response.status == 404
        await assert_auth_test_count_async(self, 1)
Example #5
0
    async def test_failure(self):
        app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
        request = self.build_valid_request(global_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 404
        assert self.mock_received_requests["/auth.test"] == 1

        app.shortcut("another-one")(simple_listener)
        response = await app.async_dispatch(request)
        assert response.status == 404
        assert self.mock_received_requests["/auth.test"] == 1
Example #6
0
    async def test_process_before_response_global(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
            process_before_response=True,
        )
        app.shortcut("test-shortcut")(simple_listener)

        request = self.build_valid_request(global_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 200
        await assert_auth_test_count_async(self, 1)
Example #7
0
    def test_shortcuts(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
        )

        async def shortcut_handler(ack):
            await ack()

        app.shortcut("test-shortcut")(shortcut_handler)

        input = {
            "type": "shortcut",
            "token": "verification_token",
            "action_ts": "111.111",
            "team": {
                "id": "T111",
                "domain": "workspace-domain",
                "enterprise_id": "E111",
                "enterprise_name": "Org Name",
            },
            "user": {
                "id": "W111",
                "username": "******",
                "team_id": "T111"
            },
            "callback_id": "test-shortcut",
            "trigger_id": "111.111.xxxxxx",
        }

        timestamp, body = str(int(
            time())), f"payload={quote(json.dumps(input))}"

        async def endpoint(req: Request):
            return await app_handler.handle(req)

        api = Starlette(
            debug=True,
            routes=[
                Route("/slack/events", endpoint=endpoint, methods=["POST"])
            ],
        )
        app_handler = AsyncSlackRequestHandler(app)

        client = TestClient(api)
        response = client.post(
            "/slack/events",
            data=body,
            headers=self.build_headers(timestamp, body),
        )
        assert response.status_code == 200
        assert self.mock_received_requests["/auth.test"] == 1
Example #8
0
    async def test_failure(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
        )
        request = self.build_valid_request(global_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 404
        await assert_auth_test_count_async(self, 1)

        app.shortcut("another-one")(simple_listener)
        response = await app.async_dispatch(request)
        assert response.status == 404
        await assert_auth_test_count_async(self, 1)
Example #9
0
    async def test_success_message(self):
        app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret,)
        app.shortcut({"type": "message_action", "callback_id": "test-shortcut"})(
            simple_listener
        )

        request = self.build_valid_request(message_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 200
        assert self.mock_received_requests["/auth.test"] == 1

        request = self.build_valid_request(global_shortcut_raw_body)
        response = await app.async_dispatch(request)
        assert response.status == 404
        assert self.mock_received_requests["/auth.test"] == 1
Example #10
0
    async def test_shortcuts(self):
        app = AsyncApp(
            client=self.web_client,
            signing_secret=self.signing_secret,
        )

        async def shortcut_handler(ack):
            await ack()

        app.shortcut("test-shortcut")(shortcut_handler)

        input = {
            "type": "shortcut",
            "token": "verification_token",
            "action_ts": "111.111",
            "team": {
                "id": "T111",
                "domain": "workspace-domain",
                "enterprise_id": "E111",
                "enterprise_name": "Org Name",
            },
            "user": {"id": "W111", "username": "******", "team_id": "T111"},
            "callback_id": "test-shortcut",
            "trigger_id": "111.111.xxxxxx",
        }

        timestamp, body = str(int(time())), f"payload={quote(json.dumps(input))}"

        api = Sanic(name=self.unique_sanic_app_name())
        app_handler = AsyncSlackRequestHandler(app)

        @api.post("/slack/events")
        async def endpoint(req: Request):
            return await app_handler.handle(req)

        _, response = await api.asgi_client.post(
            url="/slack/events",
            data=body,
            headers=self.build_headers(timestamp, body),
        )
        assert response.status_code == 200
        assert_auth_test_count(self, 1)
Example #11
0
 async def test_invalid_arg_in_func(self):
     app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret)
     app.shortcut("test-shortcut")(top_level_function)
     await self.run_app_and_verify(app)
Example #12
0
 async def test_static_methods(self):
     app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret)
     app.use(AwesomeClass.static_middleware)
     app.shortcut("test-shortcut")(AwesomeClass.static_method)
     await self.run_app_and_verify(app)
Example #13
0
 async def test_class_methods_uncommon_name(self):
     app = AsyncApp(client=self.web_client, signing_secret=self.signing_secret)
     app.use(AwesomeClass.class_middleware)
     app.shortcut("test-shortcut")(AwesomeClass.class_method2)
     await self.run_app_and_verify(app)
Example #14
0
                    "element": {
                        "type": "external_select",
                        "action_id": "favorite-animal",
                        "min_query_length": 0,
                        "placeholder": {
                            "type": "plain_text",
                            "text": "Select your favorites",
                        },
                    },
                },
            ],
        },
    )


app.shortcut("socket-mode")(ack=ack_shortcut, lazy=[open_modal])


all_options = [
    {
        "text": {"type": "plain_text", "text": ":cat: Cat"},
        "value": "cat",
    },
    {
        "text": {"type": "plain_text", "text": ":dog: Dog"},
        "value": "dog",
    },
    {
        "text": {"type": "plain_text", "text": ":bear: Bear"},
        "value": "bear",
    },