2024-02-26 08:41:24 -05:00
|
|
|
"""Tests for single server boot ups."""
|
|
|
|
|
2024-02-29 11:20:20 -05:00
|
|
|
import aiohttp
|
2024-02-26 08:41:24 -05:00
|
|
|
|
2024-02-29 11:20:20 -05:00
|
|
|
from asyncio import create_subprocess_exec
|
|
|
|
from pathlib import Path
|
2024-02-29 18:46:01 -05:00
|
|
|
from socket import gethostbyname, gethostname
|
2024-02-29 11:20:20 -05:00
|
|
|
from unittest import IsolatedAsyncioTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class Servers:
|
|
|
|
"""Setup and run servers."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Initialize class"""
|
|
|
|
self.servers = []
|
|
|
|
|
|
|
|
async def create_server(self, *args):
|
|
|
|
"""Create servers"""
|
|
|
|
app = Path.cwd().joinpath("target", "release", "morethantext")
|
|
|
|
if args:
|
|
|
|
cmd = list(args)
|
|
|
|
cmd.insert(0, app)
|
|
|
|
else:
|
|
|
|
cmd = [app]
|
|
|
|
self.servers.append(await create_subprocess_exec(*cmd))
|
|
|
|
|
|
|
|
async def destroy_servers(self):
|
|
|
|
"""destroy servers"""
|
|
|
|
for server in self.servers:
|
|
|
|
server.terminate()
|
|
|
|
await server.wait()
|
|
|
|
|
|
|
|
|
|
|
|
class SingleBootTC(IsolatedAsyncioTestCase):
|
2024-02-26 08:41:24 -05:00
|
|
|
"""Test single server boot up."""
|
|
|
|
|
2024-02-29 11:20:20 -05:00
|
|
|
async def asyncSetUp(self):
|
|
|
|
"""Test Case setup"""
|
|
|
|
self.servers = Servers()
|
|
|
|
|
|
|
|
async def asyncTearDown(self):
|
|
|
|
await self.servers.destroy_servers()
|
|
|
|
|
|
|
|
async def test_default_boot(self):
|
2024-02-26 08:41:24 -05:00
|
|
|
"Are the default settings available?"""
|
2024-02-29 11:20:20 -05:00
|
|
|
await self.servers.create_server()
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get("http://localhost:3000") as response:
|
|
|
|
self.assertEqual(response.status, 200)
|
|
|
|
|
|
|
|
async def test_alt_port_boot(self):
|
|
|
|
"""Can the server boot off on alternate port?"""
|
|
|
|
port = 9025
|
|
|
|
await self.servers.create_server("-p", str(port))
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get(f"http://localhost:{port}") as response:
|
|
|
|
self.assertEqual(response.status, 200)
|
2024-02-29 18:46:01 -05:00
|
|
|
|
|
|
|
async def test_alt_address_boot(self):
|
|
|
|
"""Can it boot off an alternate address?"""
|
|
|
|
addr = gethostbyname(gethostname())
|
|
|
|
await self.servers.create_server("-a", addr)
|
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get(f"http://{addr}:3000") as response:
|
|
|
|
self.assertEqual(response.status, 200)
|