start refactoring confserver
This commit is contained in:
parent
ba3f28165f
commit
4dce3c262c
32 changed files with 627 additions and 840 deletions
|
|
@ -1,2 +1,3 @@
|
|||
HOST = "127.0.0.1"
|
||||
MQTT_PORT = 8883
|
||||
CONF_SERVER_PORT = 11111
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import pytest
|
|||
from amqtt.client import MQTTClient
|
||||
|
||||
import bumper
|
||||
from tests import HOST, MQTT_PORT
|
||||
from bumper import WebServerBinding
|
||||
from tests import HOST, MQTT_PORT, CONF_SERVER_PORT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -37,10 +38,8 @@ async def mqtt_client():
|
|||
|
||||
@pytest.fixture
|
||||
async def conf_server_client(aiohttp_client):
|
||||
confserver = bumper.ConfServer("127.0.0.1:11111", False)
|
||||
confserver.confserver_app()
|
||||
|
||||
client = await aiohttp_client(confserver.app)
|
||||
confserver = bumper.ConfServer(WebServerBinding(HOST, CONF_SERVER_PORT, False))
|
||||
client = await aiohttp_client(confserver._app)
|
||||
|
||||
yield client
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ from aiohttp import web
|
|||
from testfixtures import LogCapture
|
||||
|
||||
import bumper
|
||||
from tests import HOST, MQTT_PORT
|
||||
from bumper import WebServerBinding
|
||||
from tests import HOST, MQTT_PORT, CONF_SERVER_PORT
|
||||
|
||||
|
||||
def create_confserver():
|
||||
return bumper.ConfServer("127.0.0.1:11111", False)
|
||||
return bumper.ConfServer(WebServerBinding(HOST, CONF_SERVER_PORT, False))
|
||||
|
||||
|
||||
def async_return(result):
|
||||
|
|
@ -28,27 +29,13 @@ def remove_existing_db():
|
|||
|
||||
|
||||
async def test_confserver_ssl():
|
||||
conf_server = bumper.ConfServer((HOST, 11111), usessl=True)
|
||||
conf_server.confserver_app()
|
||||
await conf_server.start_server()
|
||||
conf_server = bumper.ConfServer(WebServerBinding(HOST, CONF_SERVER_PORT, True))
|
||||
await conf_server.start()
|
||||
|
||||
|
||||
async def test_confserver_no_ssl():
|
||||
conf_server = bumper.ConfServer((HOST, 11112), usessl=False)
|
||||
conf_server.confserver_app()
|
||||
await conf_server.start_server()
|
||||
|
||||
|
||||
def test_get_milli_time():
|
||||
cserv = create_confserver()
|
||||
assert (
|
||||
cserv.get_milli_time(
|
||||
datetime.datetime(
|
||||
2018, 1, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc
|
||||
).timestamp()
|
||||
)
|
||||
== 1514768400000
|
||||
)
|
||||
conf_server = bumper.ConfServer(WebServerBinding(HOST, 11112, False))
|
||||
await conf_server.start()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mqtt_server")
|
||||
|
|
|
|||
|
|
@ -26,15 +26,12 @@ async def test_start_stop():
|
|||
|
||||
b = bumper
|
||||
b.db = "tests/tmp.db" # Set db location for testing
|
||||
b.conf1_listen_address = "127.0.0.1"
|
||||
b.conf1_listen_port = 444
|
||||
asyncio.create_task(b.start())
|
||||
await asyncio.sleep(0.1)
|
||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||
l.clear()
|
||||
|
||||
asyncio.create_task(b.shutdown())
|
||||
await asyncio.sleep(0.1)
|
||||
await b.shutdown()
|
||||
l.check_present(
|
||||
("bumper", "INFO", "Shutting down"), ("bumper", "INFO", "Shutdown complete")
|
||||
)
|
||||
|
|
|
|||
14
tests/test_util.py
Normal file
14
tests/test_util.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import datetime
|
||||
|
||||
from bumper.util import convert_to_millis
|
||||
|
||||
|
||||
def test_get_milli_time():
|
||||
assert (
|
||||
convert_to_millis(
|
||||
datetime.datetime(
|
||||
2018, 1, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc
|
||||
).timestamp()
|
||||
)
|
||||
== 1514768400000
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue