Browse Source

use stick channels to better divorce the back end... Also, properly

clean up the app on one of the tests, and do a better job on another...
main
John-Mark Gurney 5 years ago
parent
commit
cb63ba910d
1 changed files with 26 additions and 19 deletions
  1. +26
    -19
      solardash/__init__.py

+ 26
- 19
solardash/__init__.py View File

@@ -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()

Loading…
Cancel
Save