2018-12-12 22:34:51 +00:00
|
|
|
import functools
|
2018-12-13 14:06:47 +00:00
|
|
|
import os
|
2018-12-12 22:34:51 +00:00
|
|
|
|
2018-12-12 21:55:45 +00:00
|
|
|
from aiohttp.test_utils import unused_port
|
2018-12-12 22:34:51 +00:00
|
|
|
from aiounittest import AsyncTestCase
|
2018-12-12 15:53:56 +00:00
|
|
|
from click.testing import CliRunner
|
2018-12-12 22:34:51 +00:00
|
|
|
|
2018-12-12 18:47:40 +00:00
|
|
|
from catfish import worker
|
2018-12-12 22:34:51 +00:00
|
|
|
from catfish.__main__ import cli
|
|
|
|
from catfish.utils.processes import CURRENT_PROCESS, terminate_processes
|
2018-12-13 11:44:41 +00:00
|
|
|
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
2018-12-12 15:53:56 +00:00
|
|
|
|
|
|
|
|
2018-12-12 21:55:45 +00:00
|
|
|
class BaseTestCase(AsyncTestCase):
|
2018-12-13 14:06:47 +00:00
|
|
|
DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py")
|
|
|
|
|
2018-12-12 15:53:56 +00:00
|
|
|
def setUp(self):
|
2018-12-13 11:44:41 +00:00
|
|
|
create_base_socket_dir()
|
2018-12-12 18:47:40 +00:00
|
|
|
worker.stop_worker()
|
2018-12-12 15:53:56 +00:00
|
|
|
self.cli_runner = CliRunner()
|
|
|
|
self.cli = cli
|
2018-12-12 18:47:40 +00:00
|
|
|
self.run_cli = functools.partial(self.cli_runner.invoke, self.cli)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
worker.stop_worker()
|
2018-12-12 22:29:42 +00:00
|
|
|
terminate_processes(CURRENT_PROCESS.children(recursive=True))
|
2018-12-13 11:44:41 +00:00
|
|
|
delete_base_socket_dir()
|
2018-12-12 21:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BaseWorkerTestCase(BaseTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
|
|
|
self.unused_port = unused_port()
|
2018-12-13 17:10:14 +00:00
|
|
|
self.assertEqual(self.run_cli(["start"]).exit_code, 0)
|
2018-12-12 21:55:45 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2018-12-13 17:10:14 +00:00
|
|
|
self.assertEqual(self.run_cli(["stop"]).exit_code, 0)
|
2018-12-12 21:55:45 +00:00
|
|
|
super().tearDown()
|