Skip to content

Commit

Permalink
refactor: call self.requests directly inside HttpSession REST methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tdadela committed Jun 18, 2024
1 parent ddc6bfe commit e464109
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,27 +239,30 @@ def _send_request_safe_mode(self, method, url, **kwargs):
# These # type: ignore[override] comments below are needed because our overridden version of functions receives
# more arguments than functions in the base class.
def get(self, url: str | bytes, **kwargs: Unpack[RESTKwargs]): # type: ignore[override]
return super().get(url, **kwargs) # type: ignore[misc]
kwargs.setdefault("allow_redirects", True)
return self.request("GET", url, **kwargs) # type: ignore[misc]

def options(self, url: str | bytes, **kwargs: Unpack[RESTKwargs]): # type: ignore[override]
return super().options(url, **kwargs) # type: ignore[misc]
kwargs.setdefault("allow_redirects", True)
return self.request("OPTIONS", url, **kwargs) # type: ignore[misc]

def head(self, url: str | bytes, **kwargs: Unpack[RESTKwargs]): # type: ignore[override]
return super().head(url, **kwargs) # type: ignore[misc]
kwargs.setdefault("allow_redirects", False)
return self.request("HEAD", url, **kwargs) # type: ignore[misc]

# These # type: ignore[misc] comments below are needed because data and json parameters are already defined in the
# RESTKwargs TypedDict. An alternative approach is to define another TypedDict which doesn't contain them.
def post(self, url: str | bytes, data: Any | None = None, json: Any | None = None, **kwargs: Unpack[RESTKwargs]): # type: ignore[override, misc]
return super().post(url, data=data, json=json, **kwargs) # type: ignore[misc]
return self.request("POST", url, data=data, json=json, **kwargs) # type: ignore[misc]

def put(self, url: str | bytes, data: Any | None = None, **kwargs: Unpack[RESTKwargs]): # type: ignore[override, misc]
return super().put(url, data=data, **kwargs) # type: ignore[misc]
return self.request("PUT", url, data=data, **kwargs) # type: ignore[misc]

def patch(self, url: str | bytes, data: Any | None = None, **kwargs: Unpack[RESTKwargs]): # type: ignore[override, misc]
return super().patch(url, data=data, **kwargs) # type: ignore[misc]
return self.request("PATCH", url, data=data, **kwargs) # type: ignore[misc]

def delete(self, url: str | bytes, **kwargs: Unpack[RESTKwargs]): # type: ignore[override]
return super().delete(url, **kwargs) # type: ignore[misc]
return self.request("DELETE", url, **kwargs) # type: ignore[misc]


class ResponseContextManager(LocustResponse):
Expand Down

0 comments on commit e464109

Please sign in to comment.