test_helpers: Default user_profile to AnonymousUser.

A request that has went through the auth middleware shouldn't have
`.user` being `None`. We should use `AnonymousUser` by default to
represent unauthenticated users.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-07-11 13:35:31 -04:00
committed by Tim Abbott
parent d8f1794698
commit 0056becd04
3 changed files with 7 additions and 10 deletions

View File

@@ -300,7 +300,7 @@ class HostRequestMock(HttpRequest):
def __init__(
self,
post_data: Dict[str, Any] = {},
user_profile: Optional[Union[UserProfile, AnonymousUser, RemoteZulipServer]] = None,
user_profile: Union[UserProfile, RemoteZulipServer, None] = None,
host: str = settings.EXTERNAL_HOST,
client_name: Optional[str] = None,
meta_data: Optional[Dict[str, Any]] = None,
@@ -325,7 +325,7 @@ class HostRequestMock(HttpRequest):
else:
self.META = meta_data
self.path = path
self.user = user_profile
self.user = user_profile or AnonymousUser()
self._body = b""
self.content_type = ""
BaseNotes[str, str].get_notes