From 0737f314106d0f62aa4a0ce7b901fd3d4b6aed1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Wed, 4 Mar 2020 12:37:42 +0200 Subject: [PATCH] Remove the old request context API deprecated in 19.9. Use request.ctx instead. --- sanic/request.py | 25 ------------------------- tests/test_request_data.py | 38 -------------------------------------- 2 files changed, 63 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 246eb351ef..9cab401759 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -127,31 +127,6 @@ def __repr__(self): self.__class__.__name__, self.method, self.path ) - def get(self, key, default=None): - """.. deprecated:: 19.9 - Custom context is now stored in `request.custom_context.yourkey`""" - return self.ctx.__dict__.get(key, default) - - def __contains__(self, key): - """.. deprecated:: 19.9 - Custom context is now stored in `request.custom_context.yourkey`""" - return key in self.ctx.__dict__ - - def __getitem__(self, key): - """.. deprecated:: 19.9 - Custom context is now stored in `request.custom_context.yourkey`""" - return self.ctx.__dict__[key] - - def __delitem__(self, key): - """.. deprecated:: 19.9 - Custom context is now stored in `request.custom_context.yourkey`""" - del self.ctx.__dict__[key] - - def __setitem__(self, key, value): - """.. deprecated:: 19.9 - Custom context is now stored in `request.custom_context.yourkey`""" - setattr(self.ctx, key, value) - def body_init(self): self.body = [] diff --git a/tests/test_request_data.py b/tests/test_request_data.py index 684561de0f..8136eeb36b 100644 --- a/tests/test_request_data.py +++ b/tests/test_request_data.py @@ -44,44 +44,6 @@ def handler(request): } -# Remove this once the deprecated API is abolished. -def test_custom_context_old(app): - @app.middleware("request") - def store(request): - try: - request["foo"] - except KeyError: - pass - request["user"] = "sanic" - sidekick = request.get("sidekick", "tails") # Item missing -> default - request["sidekick"] = sidekick - request["bar"] = request["sidekick"] - del request["sidekick"] - - @app.route("/") - def handler(request): - return json( - { - "user": request.get("user"), - "sidekick": request.get("sidekick"), - "has_bar": "bar" in request, - "has_sidekick": "sidekick" in request, - } - ) - - request, response = app.test_client.get("/") - - assert response.json == { - "user": "sanic", - "sidekick": None, - "has_bar": True, - "has_sidekick": False, - } - response_json = loads(response.text) - assert response_json["user"] == "sanic" - assert response_json.get("sidekick") is None - - def test_app_injection(app): expected = random.choice(range(0, 100))