Fixed tests
This commit is contained in:
parent
0ff5adc4c1
commit
75fac37984
3 changed files with 19 additions and 13 deletions
|
@ -4,7 +4,6 @@ import logging
|
|||
import json
|
||||
import os
|
||||
import time
|
||||
import websockets
|
||||
|
||||
from threading import Thread
|
||||
from multiprocessing import Process
|
||||
|
@ -24,12 +23,14 @@ class HttpBackend(Backend):
|
|||
-d '{"type":"request","target":"nodename","action":"tts.say","args": {"phrase":"This is a test"}}' \
|
||||
http://localhost:8008/execute """
|
||||
|
||||
def __init__(self, port=8008, websocket_port=8009, token=None, **kwargs):
|
||||
def __init__(self, port=8008, websocket_port=8009, disable_websocket=False,
|
||||
token=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.port = port
|
||||
self.websocket_port = websocket_port
|
||||
self.token = token
|
||||
self.server_proc = None
|
||||
self.disable_websocket = disable_websocket
|
||||
self.websocket_thread = None
|
||||
self.active_websockets = set()
|
||||
|
||||
|
@ -47,6 +48,8 @@ class HttpBackend(Backend):
|
|||
|
||||
|
||||
def notify_web_clients(self, event):
|
||||
import websockets
|
||||
|
||||
async def send_event(websocket):
|
||||
await websocket.send(str(event))
|
||||
|
||||
|
@ -110,6 +113,8 @@ class HttpBackend(Backend):
|
|||
|
||||
|
||||
def websocket(self):
|
||||
import websockets
|
||||
|
||||
async def register_websocket(websocket, path):
|
||||
logging.info('New websocket connection from {}'.format(websocket.remote_address[0]))
|
||||
self.active_websockets.add(websocket)
|
||||
|
@ -139,13 +144,15 @@ class HttpBackend(Backend):
|
|||
'debug':True, 'host':'0.0.0.0', 'port':self.port, 'use_reloader':False
|
||||
})
|
||||
|
||||
self.websocket_thread = Thread(target=self.websocket)
|
||||
time.sleep(1)
|
||||
|
||||
self.server_proc.start()
|
||||
self.websocket_thread.start()
|
||||
|
||||
if not self.disable_websocket:
|
||||
self.websocket_thread = Thread(target=self.websocket)
|
||||
self.websocket_thread.start()
|
||||
|
||||
self.server_proc.join()
|
||||
self.websocket_thread.join()
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
backend.http:
|
||||
port: 8123
|
||||
disable_websocket: True
|
||||
|
||||
|
|
|
@ -47,14 +47,12 @@ class TestHttp(unittest.TestCase):
|
|||
on_timeout=self.on_timeout('Receiver response timed out'))
|
||||
|
||||
response = requests.post(
|
||||
u'http://localhost:8123/',
|
||||
data = {
|
||||
'msg': json.dumps({
|
||||
'type': 'request',
|
||||
'target': Config.get('device_id'),
|
||||
'action': 'shell.exec',
|
||||
'args': { 'cmd':'echo ping' }
|
||||
})
|
||||
u'http://localhost:8123/execute',
|
||||
json = {
|
||||
'type': 'request',
|
||||
'target': Config.get('device_id'),
|
||||
'action': 'shell.exec',
|
||||
'args': { 'cmd':'echo ping' }
|
||||
}
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue