-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2223305
commit 9ecf8c9
Showing
3 changed files
with
38 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
import json | ||
|
||
from requests import Response | ||
|
||
|
||
def create_mock_response(status_code: int, body: dict = None, is_json: bool = True) -> Response: | ||
""" | ||
Creates a mock Response object for testing. | ||
Args: | ||
status_code: HTTP status code to return | ||
body: Response body (dict for JSON responses) | ||
is_json: Whether the response should be treated as JSON | ||
""" | ||
response = Response() | ||
response.status_code = status_code | ||
|
||
if body is None: | ||
body = {} | ||
|
||
if is_json: | ||
response._content = json.dumps(body).encode() | ||
else: | ||
response._content = str(body).encode() | ||
return response | ||
|
||
return response |
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