Skip to content

add support config_dict mapping #219 #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiohttp_cors/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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')
Expand Down