async def test_middleware_without_check(test_client): app = get_app(bot=Bot(check_signature=False)) app.router.add_post('/post', ping) client = await test_client(app) resp = await client.post('/post?sig=BAD-SIGNATURE', data=b'test_message') assert resp.status == 200
async def test_ping(test_client): app = get_app(bot=None) client = await test_client(app) resp = await client.get('/ping', ) assert resp.status == 200 assert 'pong' == await resp.text()
async def test_middleware_good_signature(test_client): app = get_app(bot=Bot()) app.router.add_post('/post', ping) client = await test_client(app) resp = await client.post( '/post?sig=9f29ef85c59020f5ab11d6a0937e841c0231116f91e078cc0c5e17c60509a199', data=b'test_message') assert resp.status == 200 assert 'pong' == await resp.text()
def get_app(self, static_serve=False) -> web.Application: """ Create aiohttp application for webhook handling """ app = get_app(self, static_serve=static_serve) # webhook handler webhook_path = urlparse(self.webhook).path app.router.add_post(webhook_path, self.webhook_handle) # viber webhooks registering if self._unset_webhook_on_cleanup: app.on_cleanup.append(lambda a: a.bot.api.unset_webhook()) if self._set_webhook_on_startup: app.on_startup.append(lambda a: a.bot.set_webhook_on_startup()) return app
async def test_no_static(test_client): app = get_app(bot=None, static_serve=False) client = await test_client(app) resp = await client.get('/static/favicon.ico', ) assert resp.status == 404