moto/tests/test_core/test_server.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.6 KiB
Python
Raw Normal View History

from typing import Any
from unittest.mock import patch
from moto.server import DomainDispatcherApplication, create_backend_app, main
2013-03-05 13:14:43 +00:00
def test_wrong_arguments() -> None:
2013-03-05 13:14:43 +00:00
try:
2013-06-25 16:42:24 +00:00
main(["name", "test1", "test2", "test3"])
2013-03-05 13:14:43 +00:00
assert False, (
"main() when called with the incorrect number of args"
" should raise a system exit"
)
except SystemExit:
pass
2013-12-29 01:15:37 +00:00
@patch("moto.server.run_simple")
def test_right_arguments(run_simple: Any) -> None: # type: ignore[misc]
main(["s3"])
2013-12-29 01:15:37 +00:00
func_call = run_simple.call_args[0]
assert func_call[0] == "127.0.0.1"
assert func_call[1] == 5000
2013-06-25 16:42:24 +00:00
2013-12-29 01:15:37 +00:00
@patch("moto.server.run_simple")
def test_port_argument(run_simple: Any) -> None: # type: ignore[misc]
main(["s3", "--port", "8080"])
2013-12-29 01:15:37 +00:00
func_call = run_simple.call_args[0]
assert func_call[0] == "127.0.0.1"
assert func_call[1] == 8080
2014-03-30 16:05:38 +00:00
def test_domain_dispatched() -> None:
2014-03-30 16:05:38 +00:00
dispatcher = DomainDispatcherApplication(create_backend_app)
2017-02-24 02:37:43 +00:00
backend_app = dispatcher.get_application(
{"HTTP_HOST": "email.us-east1.amazonaws.com"}
)
2014-08-26 17:25:50 +00:00
keys = list(backend_app.view_functions.keys())
assert keys[0] == "EmailResponse.dispatch"
2014-03-30 16:05:38 +00:00
def test_domain_dispatched_with_service() -> None:
2014-03-30 16:05:38 +00:00
# If we pass a particular service, always return that.
dispatcher = DomainDispatcherApplication(create_backend_app, service="s3")
2017-02-24 02:37:43 +00:00
backend_app = dispatcher.get_application({"HTTP_HOST": "s3.us-east1.amazonaws.com"})
2014-08-26 17:25:50 +00:00
keys = set(backend_app.view_functions.keys())
assert "moto.s3.responses.key_response" in keys