-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: move
submit
out of the http_server.py (#37)
BREAKING CHANGE: `submit` is removed from BackgroundHTTPServer Signed-off-by: Hongli Chen <[email protected]>
- Loading branch information
1 parent
305fcad
commit cdc3c7c
Showing
6 changed files
with
113 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/openjd/adaptor_runtime/unit/background/test_server_response.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
from unittest.mock import MagicMock | ||
import pytest | ||
from openjd.adaptor_runtime._background.server_response import ServerResponseGenerator | ||
from openjd.adaptor_runtime._background.http_server import BackgroundHTTPServer | ||
from http import HTTPStatus | ||
|
||
|
||
class TestServerResponseGenerator: | ||
def test_submits_work(self): | ||
# GIVEN | ||
def my_fn(): | ||
pass | ||
|
||
args = ("one", "two") | ||
kwargs = {"three": 3, "four": 4} | ||
|
||
mock_future_runner = MagicMock() | ||
mock_server = MagicMock(spec=BackgroundHTTPServer) | ||
mock_server._future_runner = mock_future_runner | ||
mock_response_method = MagicMock() | ||
mock_server_response = MagicMock() | ||
mock_server_response.server = mock_server | ||
mock_server_response.response_method = mock_response_method | ||
|
||
# WHEN | ||
ServerResponseGenerator.submit(mock_server_response, my_fn, *args, **kwargs) | ||
|
||
# THEN | ||
mock_future_runner.submit.assert_called_once_with(my_fn, *args, **kwargs) | ||
mock_future_runner.wait_for_start.assert_called_once() | ||
# assert mock_response_method.assert_called_once_with(HTTPStatus.OK) | ||
mock_response_method.assert_called_once_with(HTTPStatus.OK) | ||
|
||
def test_returns_500_if_fails_to_submit_work(self, caplog: pytest.LogCaptureFixture): | ||
# GIVEN | ||
def my_fn(): | ||
pass | ||
|
||
args = ("one", "two") | ||
kwargs = {"three": 3, "four": 4} | ||
|
||
mock_server = MagicMock(spec=BackgroundHTTPServer) | ||
mock_future_runner = MagicMock() | ||
exc = Exception() | ||
mock_future_runner.submit.side_effect = exc | ||
mock_server._future_runner = mock_future_runner | ||
mock_response_method = MagicMock() | ||
mock_server_response = MagicMock() | ||
mock_server_response.server = mock_server | ||
mock_server_response.response_method = mock_response_method | ||
|
||
# WHEN | ||
ServerResponseGenerator.submit(mock_server_response, my_fn, *args, **kwargs) | ||
|
||
# THEN | ||
mock_future_runner.submit.assert_called_once_with(my_fn, *args, **kwargs) | ||
mock_response_method.assert_called_once_with( | ||
HTTPStatus.INTERNAL_SERVER_ERROR, body=str(exc) | ||
) | ||
|
||
assert "Failed to submit work: " in caplog.text |