diff --git a/test/.gitignore b/test/.gitignore index 4d536c8d6..5c690a3d1 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,4 +1,4 @@ wifi.txt __pycache__ wificonfig.py - +*.pyc diff --git a/test/config.py b/test/config.py index 9c2dc7c97..9ba94a1ce 100644 --- a/test/config.py +++ b/test/config.py @@ -29,6 +29,6 @@ nodes=[ mqtt_broker="192.168.13.236" -#make sure this command is running on the http_pretender: -# python -m pretenders.server.server --host 0.0.0.0 --port 8000 -http_pretender="192.168.13.236" +#ip of the server running this script +http_server="192.168.13.236" +http_port=8080 diff --git a/test/espeasy.py b/test/espeasy.py index 071fc4650..a468074b2 100644 --- a/test/espeasy.py +++ b/test/espeasy.py @@ -47,6 +47,29 @@ class EspEasy: ) + def controller_domoticz_http(self, **kwargs): + """config controller to use domoticz via http""" + + self._node.log.info("Config controller domoticz http "+str(kwargs)) + self._node.http_post( + twice=True, # needed for controllers and devices because of the way its implemented + page="controllers", + + params=""" + index:{index} + """.format(**kwargs), + + data=""" + protocol:1 + usedns:0 + controllerip:{controllerip} + controllerport:{controllerport} + controlleruser: + controllerpassword: + controllerenabled:on + """.format(**kwargs) + ) + def device_p001(self, **kwargs): self._node.log.info("Config device plugin p001 "+str(kwargs)) diff --git a/test/esptest.py b/test/esptest.py index 3a87be312..21934e687 100644 --- a/test/esptest.py +++ b/test/esptest.py @@ -6,6 +6,9 @@ import config import time import paho.mqtt.client as mqtt import json +import bottle +import threading +from Queue import Queue, Empty from espcore import * @@ -64,8 +67,39 @@ for n in config.nodes: espeasy.append(EspEasy(node[-1])) -### http pretender -from pretenders.client.http import HTTPMock -from pretenders.common.constants import FOREVER -mock = HTTPMock(config.http_pretender, 8000, timeout=20, name='esptest') -mock.reset() +### http server stuff. + +# the http server just accepts everything and stores it in the http_requests queue +import bottle + +http_requests = Queue() +@bottle.route('/') +def urlhandler(filename): + http_requests.put(bottle.request.copy()) + +http_thread=threading.Thread(target=bottle.run, kwargs=dict(host='0.0.0.0', port=config.http_port, reloader=False)) +http_thread.daemon=True +http_thread.start() + +def http_expect_request(path, matches, timeout=60): + """wait until a specific path and paraters are request on the http server. ignores all other requests""" + + start_time=time.time() + + logging.getLogger("HTTP").info("Waiting for http request on path {path}, with values {matches}".format(path=path, matches=matches)) + + # check http results + while time.time()-start_time0 and float(temp1.params['svalue'])<40 and float(temp2.params['svalue'])>0 and float(temp2.params['svalue'])<40): + raise(Exception("Wrong results")) + + +### reconfig for mqtt and expect results +espeasy[0].controller_domoticz_mqtt(index=1, controllerip=config.mqtt_broker) temp1=mqtt_expect_json("domoticz/in", { 'idx': 1417 }, timeout=10) temp2=mqtt_expect_json("domoticz/in", { 'idx': 1418 }, timeout=10) -if float(temp1['svalue'])>0 and float(temp1['svalue'])<40 and float(temp2['svalue'])>0 and float(temp2['svalue'])<40: - - #FIXME: - log.info("passed") -else: - raise(Exception("Test failed")) +if not ( float(temp1['svalue'])>0 and float(temp1['svalue'])<40 and float(temp2['svalue'])>0 and float(temp2['svalue'])<40): + raise(Exception("Wrong results"))