Skip to content

add headers and status_code to response #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions adafruit_fakerequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import json

try:
from typing import Any
from typing import Any, Optional
except ImportError:
pass

Expand All @@ -33,10 +33,22 @@


class Fake_Requests:
"""For faking 'requests' using a local file instead of the network."""
"""For faking 'requests' using a local file instead of the network.

def __init__(self, filename: str) -> None:
:param string filename: Name of the file to read.
:param dict headers: Headers to add to the faked response.
:param int status_code: Status code to use to the faked response.
"""

def __init__(
self, filename: str, headers: Optional[dict] = None, status_code: int = 200
) -> None:
self._filename = filename
if headers is None:
self.headers = {"content-type": "application/json"}
else:
self.headers = headers
self.status_code = status_code

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