Skip to content

Commit

Permalink
Removed references to RequestResults
Browse files Browse the repository at this point in the history
  • Loading branch information
fullerzz committed Dec 15, 2023
1 parent b314170 commit e04f27e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pip install "loamy[uvloop]"
The package can be imported as shown:

```python
from loamy.session import Clump, RequestMap, RequestResults
from loamy.session import Clump, RequestMap, RequestResponse
```

| Class | Description|
| ----- | -----------|
| `Clump` | Container object that stores collection of requests (type RequestMap) to send |
| `RequestMap` | Container object that stores all info about an individual request to send |
| `RequestResults` | Container object that stores the request responses and any exceptions raised |
| `RequestResponse` | Container object that stores the request response and any exception raised for each individual request |


### Example
Expand All @@ -59,19 +59,19 @@ req3 = RequestMap(

# Create Clump and call sendRequests()
session = Clump(requests=[req1, req2, req3])
reqResps: RequestResults = session.sendRequests(return_exceptions=True)
responses: list[RequestResponse] = session.sendRequests(return_exceptions=True)

# Handle exceptions raised for individual requests
if len(reqResps.taskExceptions) > 0:
print("Handling exceptions")

# Handle responses for individual requests
for resp in requestResponses:
for resp in responses:
httpVerb = resp.requestMap.httpOperation
print(f"Evaluating response for {httpVerb} request to {resp.requestMap.url}")
print(f"Status Code: {resp.statusCode}")
if resp.body is not None:
print(resp.body)
if resp.error is not None:
print("Exception raised for request")
else:
print(f"Status Code: {resp.statusCode}")
if resp.body is not None:
print(resp.body)
```

#### RequestMap Class
Expand All @@ -94,12 +94,3 @@ class RequestResponse(msgspec.Struct):
statusCode: int
body: dict | None = None
```

#### RequestResults Class

```python
@dataclass
class RequestResults:
requestResponses: list[RequestResponse]
taskExceptions: list[BaseException]
```
22 changes: 15 additions & 7 deletions tests/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from loamy.session import Clump, RequestMap, RequestResults
from loamy.session import Clump, RequestMap, RequestResponse


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -35,9 +35,11 @@ def request_map_to_trigger_exception() -> RequestMap:

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
responses: list[RequestResponse] = session.sendRequests()
assert len(responses) == 100
for response in responses:
assert response.statusCode == 200
assert response.error is None


def test_send_requests_with_exceptions(
Expand All @@ -47,6 +49,12 @@ def test_send_requests_with_exceptions(
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
responses: list[RequestResponse] = session.sendRequests(return_exceptions=True)
assert len(responses) == 101
for response in responses:
if response.requestMap.url == "http://localhost:44777/exception":
assert response.statusCode == 0
assert response.error is not None
else:
assert response.statusCode == 200
assert response.error is None

0 comments on commit e04f27e

Please sign in to comment.