async def test_success(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) app.command("/hello-world")(commander) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 200 await assert_auth_test_count_async(self, 1)
async def test_success(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) app.command("/hello-world")(commander) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 200 assert self.mock_received_requests["/auth.test"] == 1
async def test_failure(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 404 await assert_auth_test_count_async(self, 1) app.command("/another-one")(commander) response = await app.async_dispatch(request) assert response.status == 404 await assert_auth_test_count_async(self, 1)
async def test_failure(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) request = self.build_valid_request() response = await app.async_dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1 app.command("/another-one")(commander) response = await app.async_dispatch(request) assert response.status == 404 assert self.mock_received_requests["/auth.test"] == 1
def test_commands(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) async def command_handler(ack): await ack() app.command("/hello-world")(command_handler) input = ( "token=verification_token" "&team_id=T111" "&team_domain=test-domain" "&channel_id=C111" "&channel_name=random" "&user_id=W111" "&user_name=primary-owner" "&command=%2Fhello-world" "&text=Hi" "&enterprise_id=E111" "&enterprise_name=Org+Name" "&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT111%2F111%2Fxxxxx" "&trigger_id=111.111.xxx") timestamp, body = str(int(time())), 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
async def test_commands(self): app = AsyncApp( client=self.web_client, signing_secret=self.signing_secret, ) async def command_handler(ack): await ack() app.command("/hello-world")(command_handler) input = ( "token=verification_token" "&team_id=T111" "&team_domain=test-domain" "&channel_id=C111" "&channel_name=random" "&user_id=W111" "&user_name=primary-owner" "&command=%2Fhello-world" "&text=Hi" "&enterprise_id=E111" "&enterprise_name=Org+Name" "&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT111%2F111%2Fxxxxx" "&trigger_id=111.111.xxx" ) timestamp, body = str(int(time())), 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)