Refactored tests to include clusters.

This commit is contained in:
2024-03-04 11:21:42 -05:00
parent ec3f033ff6
commit a493fbf387
3 changed files with 119 additions and 55 deletions

View File

@ -1,66 +1,42 @@
"""Tests for single server boot ups."""
import aiohttp
from asyncio import create_subprocess_exec
from pathlib import Path
from .mtt_tc import MTTClusterTC
from socket import gethostbyname, gethostname
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):
"""Test single server boot up."""
async def asyncSetUp(self):
"""Test Case setup"""
self.servers = Servers()
async def asyncTearDown(self):
await self.servers.destroy_servers()
class BootUpTC(MTTClusterTC):
"""Single server boot tests."""
async def test_default_boot(self):
"Are the default settings available?"""
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)
"""Does the server default boot on http://localhost:3000?"""
await self.create_server_with_flags()
def tests(response):
"""Response tests."""
self.assertEqual(response.status, 200)
await self.run_tests("/", tests)
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)
await self.create_server_with_flags("-p", str(port))
def tests(response):
"""Response tests."""
self.assertEqual(response.status, 200)
await self.run_tests("/", tests)
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)
await self.create_server_with_flags("-a", addr)
def tests(response):
"""Response tests."""
self.assertEqual(response.status, 200)
await self.run_tests("/", tests)
async def test_for_session_id(self):
await self.create_server()
def tests(response):
"""Response tests."""
self.assertEqual(response.status, 200)
await self.run_tests("/", tests)
self.assertEqual(len(self.jar), 1, "There should be a session id.")