archive
/
catfish
Archived
1
Fork 0

Allow router to be tested properly

This commit is contained in:
Jake Howard 2018-12-15 16:08:37 +00:00
parent 9ac2e60843
commit ec58111360
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 21 additions and 1 deletions

View File

@ -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

View 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)