From 63a32652a3abebcd4dd05660b59108dad8947540 Mon Sep 17 00:00:00 2001 From: Afanasev Pavel Date: Fri, 18 Jan 2019 14:02:00 +0600 Subject: [PATCH 1/2] add support config_dict mapping #219 --- aiohttp_cors/mixin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp_cors/mixin.py b/aiohttp_cors/mixin.py index f5b4506..59991d7 100644 --- a/aiohttp_cors/mixin.py +++ b/aiohttp_cors/mixin.py @@ -18,7 +18,7 @@ class CorsViewMixin(_PreflightHandler): def get_request_config(cls, request, request_method): try: from . import APP_CONFIG_KEY - cors = request.app[APP_CONFIG_KEY] + cors = request.config_dict[APP_CONFIG_KEY] except KeyError: raise ValueError("aiohttp-cors is not configured.") From d9d19c5c302c044d1daf074bdf64d0cfb0c90712 Mon Sep 17 00:00:00 2001 From: Afanasev Pavel Date: Fri, 18 Jan 2019 14:20:26 +0600 Subject: [PATCH 2/2] fix test, add config_dict in request mock --- tests/unit/test_mixin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/test_mixin.py b/tests/unit/test_mixin.py index fb33b2e..f3851a2 100644 --- a/tests/unit/test_mixin.py +++ b/tests/unit/test_mixin.py @@ -68,6 +68,7 @@ def app(_app, cors): def test_raise_exception_when_cors_not_configure(): request = mock.Mock() request.app = {} + request.config_dict = {} view = CustomMethodView(request) with pytest.raises(ValueError): @@ -78,6 +79,7 @@ async def test_raises_forbidden_when_config_not_found(app): app[APP_CONFIG_KEY].defaults = {} request = mock.Mock() request.app = app + request.config_dict = app request.headers = { 'Origin': '*', 'Access-Control-Request-Method': 'GET' @@ -92,6 +94,7 @@ def test_method_with_custom_cors(app): """Test adding resource with web.View as handler""" request = mock.Mock() request.app = app + request.config_dict = app view = CustomMethodView(request) assert hasattr(view.post, 'post_cors_config') @@ -105,6 +108,7 @@ def test_method_with_class_config(app): """Test adding resource with web.View as handler""" request = mock.Mock() request.app = app + request.config_dict = app view = SimpleViewWithConfig(request) assert not hasattr(view.get, 'get_cors_config') @@ -117,6 +121,7 @@ def test_method_with_default_config(app): """Test adding resource with web.View as handler""" request = mock.Mock() request.app = app + request.config_dict = app view = SimpleView(request) assert not hasattr(view.get, 'get_cors_config')