From eb70174ed57c3151aa69f3240f6985e1a020649c Mon Sep 17 00:00:00 2001 From: Steve Pulec Date: Tue, 25 Jun 2013 12:42:24 -0400 Subject: [PATCH] Add port option. --- README.md | 8 ++++++++ moto/server.py | 10 +++++++--- tests/test_core/test_server.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ed8e14424..243d8c203 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,14 @@ $ moto_server ec2 * Running on http://127.0.0.1:5000/ ``` +You can also pass the port as the second argument: + +```console +$ moto_server ec2 3000 + * Running on http://127.0.0.1:3000/ +``` + + Then go to [localhost](http://localhost:5000/?Action=DescribeInstances) to see a list of running instances (it will be empty since you haven't added any yet). ## Install diff --git a/moto/server.py b/moto/server.py index 5746a7108..70f5b03db 100644 --- a/moto/server.py +++ b/moto/server.py @@ -35,14 +35,18 @@ def configure_urls(service): def main(args=sys.argv): - if len(args) != 2: - print("Usage: moto_server ") + if len(args) not in range(2, 4): + print("Usage: moto_server [port]") sys.exit(1) service_name = args[1] configure_urls(service_name) + try: + port = int(args[2]) + except IndexError: + port = None app.testing = True - app.run() + app.run(port=port) if __name__ == '__main__': main() diff --git a/tests/test_core/test_server.py b/tests/test_core/test_server.py index e86098c4f..6cf87b1d4 100644 --- a/tests/test_core/test_server.py +++ b/tests/test_core/test_server.py @@ -6,7 +6,7 @@ from moto.server import main def test_wrong_arguments(): try: - main(["name", "test1", "test2"]) + main(["name", "test1", "test2", "test3"]) assert False, ("main() when called with the incorrect number of args" " should raise a system exit") except SystemExit: @@ -16,4 +16,10 @@ def test_wrong_arguments(): @patch('moto.server.app.run') def test_right_arguments(app_run): main(["name", "s3"]) - app_run.assert_called_once_with() + app_run.assert_called_once_with(port=None) + + +@patch('moto.server.app.run') +def test_port_argument(app_run): + main(["name", "s3", 8080]) + app_run.assert_called_once_with(port=8080)