|
|
@@ -284,16 +284,22 @@ class Test(unittest.TestCase): |
|
|
|
async def test_staticfiles(self): |
|
|
|
runner = web.AppRunner(self._app) |
|
|
|
await runner.setup() |
|
|
|
site = web.TCPSite(runner, 'localhost', self._webport) |
|
|
|
await site.start() |
|
|
|
try: |
|
|
|
site = web.TCPSite(runner, 'localhost', self._webport) |
|
|
|
await site.start() |
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session, \ |
|
|
|
session.get(self.makeurl('')) as req: |
|
|
|
#print(repr(req)) |
|
|
|
self.assertEqual(req.status, 200) |
|
|
|
body = await req.content.read() |
|
|
|
with open(os.path.join(self.rootdir, 'index.html'), 'rb') as fp: |
|
|
|
self.assertEqual(body, fp.read()) |
|
|
|
|
|
|
|
finally: |
|
|
|
await runner.cleanup() |
|
|
|
|
|
|
|
async with aiohttp.ClientSession() as session, \ |
|
|
|
session.get(self.makeurl('')) as req: |
|
|
|
#print(repr(req)) |
|
|
|
self.assertEqual(req.status, 200) |
|
|
|
body = await req.content.read() |
|
|
|
with open(os.path.join(self.rootdir, 'index.html'), 'rb') as fp: |
|
|
|
self.assertEqual(body, fp.read()) |
|
|
|
# XXX - add test where websocket is still connected when shutting down |
|
|
|
|
|
|
|
@async_test |
|
|
|
async def test_daemon(self): |
|
|
@@ -301,16 +307,17 @@ class Test(unittest.TestCase): |
|
|
|
|
|
|
|
runner = web.AppRunner(self._app) |
|
|
|
await runner.setup() |
|
|
|
site = web.TCPSite(runner, 'localhost', self._webport) |
|
|
|
await site.start() |
|
|
|
try: |
|
|
|
site = web.TCPSite(runner, 'localhost', self._webport) |
|
|
|
await site.start() |
|
|
|
|
|
|
|
with open(os.path.join(self.tempdir, 'raineagle.0.log'), 'w', buffering=1) as fp: |
|
|
|
fp.write('\t'.join([ 'm', '1578879268.23', '1578850464', 'Connected', '1.2740', '3.992000', 'kW', '85.575', '8.092', 'kWh' ]) + '\n') |
|
|
|
loop.call_later(.02, fp.write, '\t'.join([ 'm', '1578879269.23', '1578850465', 'Connected', '1.0000', '3.992000', 'kW', '85.575', '8.092', 'kWh' ]) + '\n') |
|
|
|
with open(os.path.join(self.tempdir, 'raineagle.0.log'), 'w', buffering=1) as fp: |
|
|
|
fp.write('\t'.join([ 'm', '1578879268.23', '1578850464', 'Connected', '1.2740', '3.992000', 'kW', '85.575', '8.092', 'kWh' ]) + '\n') |
|
|
|
loop.call_later(.02, fp.write, '\t'.join([ 'm', '1578879269.23', '1578850465', 'Connected', '1.0000', '3.992000', 'kW', '85.575', '8.092', 'kWh' ]) + '\n') |
|
|
|
|
|
|
|
# Test the websocket |
|
|
|
r = [] |
|
|
|
|
|
|
|
# Test the websocket |
|
|
|
r = [] |
|
|
|
try: |
|
|
|
async with aiohttp.ClientSession() as session, \ |
|
|
|
session.ws_connect(self.makeurl('solar.ws')) as ws: |
|
|
|
async for msg in ws: |
|
|
@@ -325,5 +332,5 @@ class Test(unittest.TestCase): |
|
|
|
|
|
|
|
self.assertEqual(r[1].type, aiohttp.WSMsgType.TEXT) |
|
|
|
self.assertEqual(r[1].data, 'ng 1.0000') |
|
|
|
finally: |
|
|
|
await runner.cleanup() |
|
|
|
finally: |
|
|
|
await runner.cleanup() |