Skip to content

Commit 020121e

Browse files
authored
Merge pull request #10 from FoamyGuy/headers_and_status
add headers and status_code to response
2 parents aa03428 + e55ab26 commit 020121e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

adafruit_fakerequests.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525

2626
try:
27-
from typing import Any
27+
from typing import Any, Optional
2828
except ImportError:
2929
pass
3030

@@ -33,10 +33,22 @@
3333

3434

3535
class Fake_Requests:
36-
"""For faking 'requests' using a local file instead of the network."""
36+
"""For faking 'requests' using a local file instead of the network.
3737
38-
def __init__(self, filename: str) -> None:
38+
:param string filename: Name of the file to read.
39+
:param dict headers: Headers to add to the faked response.
40+
:param int status_code: Status code to use to the faked response.
41+
"""
42+
43+
def __init__(
44+
self, filename: str, headers: Optional[dict] = None, status_code: int = 200
45+
) -> None:
3946
self._filename = filename
47+
if headers is None:
48+
self.headers = {"content-type": "application/json"}
49+
else:
50+
self.headers = headers
51+
self.status_code = status_code
4052

4153
def json(self) -> Any:
4254
"""json parsed version for local requests."""

0 commit comments

Comments
 (0)