diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-11-10 14:51:43 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-11-10 14:51:43 +0100 |
commit | e08bfa5ed89aefeb508b1bbae76bbf2a342f85a1 (patch) | |
tree | 8eba47fc7dd95a77f85841d435be38833d300f96 | |
parent | 5c9aa9aff7fed5feddc58845c72607caa7feb76c (diff) |
Pass configured port number to reactor.
-rw-r--r-- | service/pixelated/config/app_factory.py | 5 | ||||
-rw-r--r-- | service/pixelated/runserver.py | 6 | ||||
-rw-r--r-- | service/test/unit/config/app_factory_test.py | 15 | ||||
-rw-r--r-- | service/test/unit/runserver_test.py | 13 |
4 files changed, 34 insertions, 5 deletions
diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py index 3dc1c83a..6a9046ee 100644 --- a/service/pixelated/config/app_factory.py +++ b/service/pixelated/config/app_factory.py @@ -131,8 +131,9 @@ def init_app(app): sync_info_controller, attachments_controller) -def create_app(app, bind_address): - reactor.listenTCP(3333, Site(app.resource()), interface=bind_address) +def create_app(app, bind_address, bind_port): + print type(reactor.listenTCP) + reactor.listenTCP(bind_port, Site(app.resource()), interface=bind_address) reactor.callWhenRunning(lambda: init_app(app)) reactor.run() diff --git a/service/pixelated/runserver.py b/service/pixelated/runserver.py index 58ad53e1..518ea5fb 100644 --- a/service/pixelated/runserver.py +++ b/service/pixelated/runserver.py @@ -54,7 +54,7 @@ def setup(): app.config['LEAP_PASSWORD'] = config['password'] else: configuration_setup(args.config) - start_services(args.host) + start_services(args.host, args.port) def register(username, server_name): @@ -113,9 +113,9 @@ def configuration_setup(config_file): app.config['LEAP_PASSWORD'] = password -def start_services(bind_address): +def start_services(bind_address, bind_port): events_server.ensure_server(port=8090) - app_factory.create_app(app, bind_address) + app_factory.create_app(app, bind_address, bind_port) if __name__ == '__main__': diff --git a/service/test/unit/config/app_factory_test.py b/service/test/unit/config/app_factory_test.py new file mode 100644 index 00000000..5adf3722 --- /dev/null +++ b/service/test/unit/config/app_factory_test.py @@ -0,0 +1,15 @@ +import unittest +from mock import patch, MagicMock, ANY + +from pixelated.config.app_factory import create_app + + +class AppFactoryTest(unittest.TestCase): + + @patch('pixelated.config.app_factory.reactor') + def test_that_create_app_binds_to_port(self, reactor_mock): + app_mock = MagicMock() + + create_app(app_mock, '127.0.0.1', 12345) + + reactor_mock.listenTCP.assert_called_once_with(12345, ANY, interface='127.0.0.1') diff --git a/service/test/unit/runserver_test.py b/service/test/unit/runserver_test.py index e3cd8439..51ee899c 100644 --- a/service/test/unit/runserver_test.py +++ b/service/test/unit/runserver_test.py @@ -20,6 +20,7 @@ import os import thread import json +import pixelated.config.app_factory import pixelated.runserver from mockito import * import pixelated.config.app_factory as app_factory @@ -32,6 +33,9 @@ class RunserverTest(unittest.TestCase): events_server.ensure_server = lambda port=None: None when(app_factory).create_app().thenReturn(None) + def tearDown(self): + unstub() + def test_that_config_file_can_be_specified_on_command_line(self): self.config_file_loaded = None @@ -55,6 +59,15 @@ class RunserverTest(unittest.TestCase): sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path] pixelated.runserver.setup() + def test_start_services_provides_port(self): + bind_address = '127.0.0.1' + bind_port = 12345 + when(app_factory).create_app(any(), bind_address, bind_port).thenReturn(None) + + pixelated.runserver.start_services(bind_address, bind_port) + + verify(app_factory).create_app(any(), bind_address, bind_port) + def spin_up_fifo(self, test_fifo): with open(test_fifo, 'w') as fifo: fifo.write(json.dumps({'leap_provider_hostname': 'test_provider', 'user': 'test_user', 'password': 'test_password'})) |