Skip to content

Commit

Permalink
Fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kragniz committed May 31, 2017
1 parent b80e30c commit 045964c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 4 additions & 2 deletions boatd/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
11 changes: 5 additions & 6 deletions boatd/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 045964c

Please sign in to comment.