Skip to content

Commit

Permalink
fix cors options method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Chegodaev authored and kazauwa committed Feb 2, 2021
1 parent 4b6bf00 commit 648dcef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion its_on/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def dispose_redis_pool(app: web.Application) -> None:
DBAuthorizationPolicy(app))

cors_config = {
origin: aiohttp_cors.ResourceOptions(allow_methods=['GET'])
origin: aiohttp_cors.ResourceOptions(allow_methods=['GET', 'OPTIONS'])
for origin in settings.CORS_ALLOW_ORIGIN
}
cors = aiohttp_cors.setup(app, defaults=cors_config)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_api_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ async def test_switch_cors(client):
assert response.headers['Access-Control-Allow-Origin'] == 'http://localhost:8081'


async def test_switch_cors_options(client):
response = await client.options('/api/v1/switch', headers={
'Origin': 'http://localhost:8081',
'Access-Control-Request-Method': 'GET',
})

assert response.status == 200
assert response.headers['Access-Control-Allow-Origin'] == 'http://localhost:8081'


@pytest.mark.parametrize('version,expected_result', [
(1, {'count': 0, 'result': []}),
(4, {'count': 1, 'result': ['switch4']}),
Expand Down

0 comments on commit 648dcef

Please sign in to comment.