Allow router to be tested properly
This commit is contained in:
parent
9ac2e60843
commit
ec58111360
2 changed files with 21 additions and 1 deletions
|
@ -3,11 +3,12 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
|
||||
from aiohttp.test_utils import unused_port
|
||||
from aiohttp.test_utils import AioHTTPTestCase, unused_port
|
||||
from aiounittest import AsyncTestCase
|
||||
from click.testing import CliRunner
|
||||
|
||||
from catfish.__main__ import cli
|
||||
from catfish.router import get_server
|
||||
from catfish.utils.processes import terminate_subprocesses
|
||||
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
||||
|
||||
|
@ -49,3 +50,15 @@ class BaseWorkerTestCase(BaseTestCase):
|
|||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout)
|
||||
super().tearDown()
|
||||
|
||||
|
||||
class BaseRouterTestCase(AsyncTestCase, AioHTTPTestCase):
|
||||
async def get_application(self):
|
||||
return get_server()
|
||||
|
||||
def __getattribute__(self, name):
|
||||
attr = super(AioHTTPTestCase, self).__getattribute__(name)
|
||||
if name.startswith("test_") and callable(attr):
|
||||
return lambda: self.loop.run_until_complete(attr())
|
||||
else:
|
||||
return attr
|
||||
|
|
7
tests/test_router/test_router.py
Normal file
7
tests/test_router/test_router.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from tests import BaseRouterTestCase
|
||||
|
||||
|
||||
class RouterTestCase(BaseRouterTestCase):
|
||||
async def test_accessible(self):
|
||||
response = await self.client.request("GET", "/")
|
||||
self.assertEqual(response.status, 200)
|
Reference in a new issue