コード例 #1
0
ファイル: test_events.py プロジェクト: ksuykry/bolt-python
    async def test_uninstallation_and_revokes(self):
        app = AsyncApp(client=self.web_client,
                       signing_secret=self.signing_secret)
        app._client = AsyncWebClient(token="uninstalled-revoked",
                                     base_url=self.mock_api_server_base_url)

        @app.event("app_uninstalled")
        async def handler1(say: AsyncSay):
            await say(channel="C111", text="What's up?")

        @app.event("tokens_revoked")
        async def handler2(say: AsyncSay):
            await say(channel="C111", text="What's up?")

        app_uninstalled_body = {
            "token": "verification_token",
            "team_id": "T111",
            "enterprise_id": "E111",
            "api_app_id": "A111",
            "event": {
                "type": "app_uninstalled"
            },
            "type": "event_callback",
            "event_id": "Ev111",
            "event_time": 1599616881,
        }

        timestamp, body = str(int(time())), json.dumps(app_uninstalled_body)
        request: AsyncBoltRequest = AsyncBoltRequest(
            body=body, headers=self.build_headers(timestamp, body))
        response = await app.async_dispatch(request)
        assert response.status == 200

        tokens_revoked_body = {
            "token": "verification_token",
            "team_id": "T111",
            "enterprise_id": "E111",
            "api_app_id": "A111",
            "event": {
                "type": "tokens_revoked",
                "tokens": {
                    "oauth": ["UXXXXXXXX"],
                    "bot": ["UXXXXXXXX"]
                },
            },
            "type": "event_callback",
            "event_id": "Ev111",
            "event_time": 1599616881,
        }

        timestamp, body = str(int(time())), json.dumps(tokens_revoked_body)
        request: AsyncBoltRequest = AsyncBoltRequest(
            body=body, headers=self.build_headers(timestamp, body))
        response = await app.async_dispatch(request)
        assert response.status == 200

        # AsyncApp doesn't call auth.test when booting
        assert self.mock_received_requests.get("/auth.test") is None
        await asyncio.sleep(1)  # wait a bit after auto ack()
        assert self.mock_received_requests["/chat.postMessage"] == 2
コード例 #2
0
ファイル: test_events.py プロジェクト: ksuykry/bolt-python
    async def test_message_subtypes_3(self):
        app = AsyncApp(client=self.web_client,
                       signing_secret=self.signing_secret)
        app._client = AsyncWebClient(token="uninstalled-revoked",
                                     base_url=self.mock_api_server_base_url)

        @app.event("message")
        async def handler1(event):
            assert event["subtype"] == "file_share"

        timestamp, body = str(int(time())), json.dumps(
            self.message_file_share_body)
        request: AsyncBoltRequest = AsyncBoltRequest(
            body=body, headers=self.build_headers(timestamp, body))
        response = await app.async_dispatch(request)
        assert response.status == 200