51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
import functools
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
|
|
from aiohttp.test_utils import unused_port
|
|
from aiounittest import AsyncTestCase
|
|
from click.testing import CliRunner
|
|
|
|
from catfish.__main__ import cli
|
|
from catfish.utils.processes import terminate_subprocesses
|
|
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
|
|
|
|
|
class BaseTestCase(AsyncTestCase):
|
|
DUMMY_EXE = os.path.join(os.path.dirname(__file__), "dummy_program.py")
|
|
|
|
def setUp(self):
|
|
create_base_socket_dir()
|
|
self.cli_runner = CliRunner()
|
|
self.cli = cli
|
|
self.run_cli = functools.partial(self.cli_runner.invoke, self.cli)
|
|
|
|
def tearDown(self):
|
|
terminate_subprocesses()
|
|
delete_base_socket_dir()
|
|
|
|
|
|
class BaseWorkerTestCase(BaseTestCase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.unused_port = unused_port()
|
|
result = subprocess.run(
|
|
[shutil.which("ctf"), "start", "--port", str(self.unused_port)],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True,
|
|
timeout=10,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stdout)
|
|
|
|
def tearDown(self):
|
|
result = subprocess.run(
|
|
[shutil.which("ctf"), "stop"],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True,
|
|
timeout=10,
|
|
)
|
|
self.assertEqual(result.returncode, 0, result.stdout)
|
|
super().tearDown()
|