2024-02-26 08:41:24 -05:00
|
|
|
"""Tests for single server boot ups."""
|
|
|
|
|
2024-02-29 18:46:01 -05:00
|
|
|
from socket import gethostbyname, gethostname
|
2024-03-17 15:40:00 -04:00
|
|
|
from aiohttp import ClientSession
|
|
|
|
from .mtt_tc import MTTClusterTC, SESSION_KEY
|
2024-02-26 08:41:24 -05:00
|
|
|
|
2024-02-29 11:20:20 -05:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
class BootUpTC(MTTClusterTC):
|
|
|
|
"""Single server boot tests."""
|
2024-02-29 11:20:20 -05:00
|
|
|
|
|
|
|
async def test_default_boot(self):
|
2024-03-04 11:21:42 -05:00
|
|
|
"""Does the server default boot on http://localhost:3000?"""
|
|
|
|
await self.create_server_with_flags()
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
def tests(response):
|
|
|
|
"""Response tests."""
|
|
|
|
self.assertEqual(response.status, 200)
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.run_tests("/", tests)
|
2024-02-29 11:20:20 -05:00
|
|
|
|
|
|
|
async def test_alt_port_boot(self):
|
|
|
|
"""Can the server boot off on alternate port?"""
|
|
|
|
port = 9025
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.create_server_with_flags("-p", str(port))
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
def tests(response):
|
|
|
|
"""Response tests."""
|
|
|
|
self.assertEqual(response.status, 200)
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.run_tests("/", tests)
|
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())
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.create_server_with_flags("-a", addr)
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
def tests(response):
|
|
|
|
"""Response tests."""
|
|
|
|
self.assertEqual(response.status, 200)
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.run_tests("/", tests)
|
|
|
|
|
|
|
|
async def test_for_session_id(self):
|
2024-03-17 15:40:00 -04:00
|
|
|
"""Is there a session if?"""
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.create_server()
|
2024-03-17 15:40:00 -04:00
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
def tests(response):
|
|
|
|
"""Response tests."""
|
2024-03-17 15:40:00 -04:00
|
|
|
self.assertIn(SESSION_KEY, response.cookies)
|
|
|
|
|
2024-03-04 11:21:42 -05:00
|
|
|
await self.run_tests("/", tests)
|
2024-03-17 15:40:00 -04:00
|
|
|
|
|
|
|
async def test_session_id_is_random(self):
|
|
|
|
"""Is the session id random?"""
|
|
|
|
await self.create_server()
|
|
|
|
async with ClientSession() as session:
|
|
|
|
async with session.get(f"{self.servers[0].host}/") as response:
|
|
|
|
result1 = response.cookies[SESSION_KEY].value
|
|
|
|
async with ClientSession() as session:
|
|
|
|
async with session.get(f"{self.servers[0].host}/") as response:
|
|
|
|
result2 = response.cookies[SESSION_KEY].value
|
|
|
|
self.assertNotEqual(result1, result2, "Session ids should be unique.")
|
|
|
|
|
|
|
|
async def test_session_does_not_reset_after_connection(self):
|
|
|
|
"""Does the session id remain constant during the session"""
|
|
|
|
await self.create_server()
|
|
|
|
ids = []
|
|
|
|
|
|
|
|
def tests(response):
|
|
|
|
"""tests"""
|
|
|
|
if SESSION_KEY in response.cookies:
|
|
|
|
ids.append(response.cookies[SESSION_KEY].value)
|
|
|
|
|
|
|
|
for _ in range(2):
|
|
|
|
await self.run_tests("/", tests)
|
|
|
|
self.assertEqual(len(ids), 1)
|