From 045964cc332620a9660fb2ed1081b779087c86e3 Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Wed, 31 May 2017 22:32:40 +0100 Subject: [PATCH] Fix api tests --- boatd/api.py | 6 ++++-- boatd/tests/test_api.py | 11 +++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/boatd/api.py b/boatd/api.py index e2436519..447a20b3 100644 --- a/boatd/api.py +++ b/boatd/api.py @@ -186,7 +186,9 @@ def post(self): class BoatdAPI(object): def __init__(self, boat, behaviour_manager, waypoint_manager, server_address): - log.info('boatd api listening on %s:%s', *server_address) + self.host = server_address[0] + self.port = server_address[1] + log.info('boatd api listening on %s:%s', self.host, self.port) self.boat = boat self.behaviour_manager = behaviour_manager @@ -216,5 +218,5 @@ def __init__(self, boat, behaviour_manager, waypoint_manager, ]) def run(self): - self.app.listen(2222) + self.app.listen(self.port, address=self.host) tornado.ioloop.IOLoop.instance().start() diff --git a/boatd/tests/test_api.py b/boatd/tests/test_api.py index 7ef9ad2a..6d96d86d 100644 --- a/boatd/tests/test_api.py +++ b/boatd/tests/test_api.py @@ -45,17 +45,16 @@ def setUp(self): self.boat = MockBoat() for _ in range(self.TEST_PORTS): try: - self.httpd = boatd.BoatdHTTPServer(self.boat, object, - object, - ('', self.port), - boatd.BoatdRequestHandler) + self.api = boatd.BoatdAPI(self.boat, object, + object, + ('', self.port)) break except socket.error as e: print('socket {} didn\'t work, trying a higher one ' '({})'.format(self.port, e)) self.port += 1 - self.http_thread = threading.Thread(target=self.httpd.handle_request) + self.http_thread = threading.Thread(target=self.api.run) self.http_thread.daemon = True self.http_thread.start() @@ -141,7 +140,7 @@ def test_quit(self): status_json = self._post_string(json.dumps({'quit': True})).read() status = json.loads(status_json.decode("utf-8")) assert status['quit'] == True - assert self.httpd.running == False + assert self.api.running == False def test_set_rudder(self): assert self.boat.rudder_angle == 20