mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
tests: Migrate mocked Request to HostMockRequest.
This migrates some mocked Request class and mocked request achieved with namedtuple in test_decorators and test_mirror_users to use the refactored HostMockRequest. Since weakref cannot be used with namedtuple, this old way of mocking a request object should be migrated to using HostRequestMock. Only after this change we can extract client from the request object and store it via ZulipRequestNotes.
This commit is contained in:
@@ -29,6 +29,7 @@ import ldap
|
||||
import orjson
|
||||
from boto3.resources.base import ServiceResource
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
||||
from django.http.request import QueryDict
|
||||
@@ -58,6 +59,7 @@ from zerver.models import (
|
||||
)
|
||||
from zerver.tornado.handlers import AsyncDjangoHandler, allocate_handler_id
|
||||
from zerver.worker import queue_processors
|
||||
from zilencer.models import RemoteZulipServer
|
||||
from zproject.backends import ExternalAuthDataDict, ExternalAuthResult
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -289,10 +291,11 @@ class HostRequestMock(HttpRequest):
|
||||
def __init__(
|
||||
self,
|
||||
post_data: Dict[str, Any] = {},
|
||||
user_profile: Optional[UserProfile] = None,
|
||||
user_profile: Optional[Union[UserProfile, AnonymousUser, RemoteZulipServer]] = None,
|
||||
host: str = settings.EXTERNAL_HOST,
|
||||
client_name: Optional[str] = None,
|
||||
meta_data: Optional[Dict[str, Any]] = None,
|
||||
tornado_handler: Optional[AsyncDjangoHandler] = DummyHandler(),
|
||||
) -> None:
|
||||
self.host = host
|
||||
self.GET = QueryDict(mutable=True)
|
||||
@@ -323,7 +326,7 @@ class HostRequestMock(HttpRequest):
|
||||
|
||||
request_notes_map[self] = ZulipRequestNotes(
|
||||
log_data={},
|
||||
tornado_handler=DummyHandler(),
|
||||
tornado_handler=tornado_handler,
|
||||
)
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user