-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'test-server-impl' into exception-gathering-enhancement
- Loading branch information
Showing
6 changed files
with
533 additions
and
184 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from blacksheep import Application, Request, Response, get, json, post | ||
|
||
app = Application() | ||
|
||
|
||
@get("/") | ||
async def index() -> Response: | ||
return json({"message": "Hello, world!"}) | ||
|
||
|
||
@post("/foo") | ||
async def post_foo(request: Request) -> Response: | ||
data = await request.json() | ||
return json(data) | ||
|
||
|
||
@get("/exception") | ||
async def mock_exception(): | ||
raise Exception("Mock exception") |
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,52 @@ | ||
import pytest | ||
from loamy.session import Clump, RequestMap, RequestResults | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def request_map_collection() -> list[RequestMap]: | ||
requests: list[RequestMap] = [] | ||
for i in range(0, 100): | ||
print(i) | ||
if i % 2 == 0: | ||
requests.append( | ||
RequestMap( | ||
url="http://localhost:44777/", | ||
httpOperation="GET", | ||
) | ||
) | ||
else: | ||
requests.append( | ||
RequestMap( | ||
url="http://localhost:44777/foo", | ||
httpOperation="POST", | ||
body={"foo": "bar"}, | ||
) | ||
) | ||
return requests | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def request_map_to_trigger_exception() -> RequestMap: | ||
return RequestMap( | ||
url="http://localhost:44777/exception", | ||
httpOperation="GET", | ||
) | ||
|
||
|
||
def test_send_requests(request_map_collection: list[RequestMap]) -> None: | ||
session = Clump(requests=request_map_collection) | ||
responses: RequestResults = session.sendRequests() | ||
assert len(responses.requestResponses) == 100 | ||
assert len(responses.taskExceptions) == 0 | ||
|
||
|
||
def test_send_requests_with_exceptions( | ||
request_map_collection: list[RequestMap], | ||
request_map_to_trigger_exception: RequestMap, | ||
) -> None: | ||
requests: list[RequestMap] = request_map_collection.copy() | ||
requests.append(request_map_to_trigger_exception) | ||
session = Clump(requests=requests) | ||
responses: RequestResults = session.sendRequests(return_exceptions=True) | ||
assert len(responses.requestResponses) == 100 | ||
assert len(responses.taskExceptions) == 1 |