feat(testing.requests): add Request.__init__

This new constructor is a beginning to making Request a bit more easy
to deal with for standard testing needs. With this commit, users can
now specify a `user` and `authenticated` state while constructing a
Request:

    request = Request(user=some_user, authenticated=True)

By default, the `authenticated` kwarg is set to False and `user` is
set to `aurweb.testing.requests.User()`.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-12-31 15:10:54 -08:00
parent cab86035e9
commit 67dd432e86
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -29,13 +29,17 @@ class URL:
class Request:
""" A fake Request object which mimics a FastAPI Request for tests. """
client = Client()
user = User()
url = URL()
def __init__(self,
user: User = User(),
authenticated: bool = False,
method: str = "GET",
headers: Dict[str, str] = dict(),
cookies: Dict[str, str] = dict()) -> "Request":
self.user = user
self.user.authenticated = authenticated
self.method = method.upper()
self.headers = headers
self.cookies = cookies