Add port option.

This commit is contained in:
Steve Pulec 2013-06-25 12:42:24 -04:00
parent 87c86bb902
commit eb70174ed5
3 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -35,14 +35,18 @@ def configure_urls(service):
def main(args=sys.argv):
if len(args) != 2:
print("Usage: moto_server <service>")
if len(args) not in range(2, 4):
print("Usage: moto_server <service> [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()

View File

@ -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)