11"""tests.test_api_gateway.test_rest.service module."""
22
3+ import os
34import unittest
45from unittest import (
56 mock ,
67)
8+
9+ import attr
710from aiohttp .test_utils import (
811 AioHTTPTestCase ,
912 unittest_run_loop ,
1013)
11- import os
12- import attr
14+ from aiohttp_middlewares .cors import (
15+ ACCESS_CONTROL_ALLOW_HEADERS ,
16+ ACCESS_CONTROL_ALLOW_METHODS ,
17+ ACCESS_CONTROL_ALLOW_ORIGIN ,
18+ DEFAULT_ALLOW_HEADERS ,
19+ DEFAULT_ALLOW_METHODS ,
20+ )
21+
1322from minos .api_gateway .common import (
1423 MinosConfig ,
1524)
2231from tests .utils import (
2332 BASE_PATH ,
2433)
25- from aiohttp_middlewares .cors import (
26- ACCESS_CONTROL_ALLOW_HEADERS ,
27- ACCESS_CONTROL_ALLOW_METHODS ,
28- ACCESS_CONTROL_ALLOW_ORIGIN ,
29- DEFAULT_ALLOW_HEADERS ,
30- DEFAULT_ALLOW_METHODS ,
31- )
3234
3335
3436class TestApiGatewayRestService (AioHTTPTestCase ):
@@ -253,21 +255,13 @@ async def get_application(self):
253255
254256 @staticmethod
255257 def check_allow_origin (
256- response ,
257- origin ,
258- * ,
259- allow_headers = DEFAULT_ALLOW_HEADERS ,
260- allow_methods = DEFAULT_ALLOW_METHODS ,
258+ response , origin , * , allow_headers = DEFAULT_ALLOW_HEADERS , allow_methods = DEFAULT_ALLOW_METHODS ,
261259 ):
262260 assert response .headers [ACCESS_CONTROL_ALLOW_ORIGIN ] == origin
263261 if allow_headers :
264- assert response .headers [ACCESS_CONTROL_ALLOW_HEADERS ] == ", " .join (
265- allow_headers
266- )
262+ assert response .headers [ACCESS_CONTROL_ALLOW_HEADERS ] == ", " .join (allow_headers )
267263 if allow_methods :
268- assert response .headers [ACCESS_CONTROL_ALLOW_METHODS ] == ", " .join (
269- allow_methods
270- )
264+ assert response .headers [ACCESS_CONTROL_ALLOW_METHODS ] == ", " .join (allow_methods )
271265
272266 @unittest_run_loop
273267 async def test_cors_enabled (self ):
@@ -285,9 +279,7 @@ async def test_cors_enabled(self):
285279 kwargs ["allow_methods" ] = expected_allow_methods
286280
287281 self .check_allow_origin (
288- await self .client .request (
289- method , url , headers = {"Origin" : self .TEST_ORIGIN , ** extra_headers }
290- ),
282+ await self .client .request (method , url , headers = {"Origin" : self .TEST_ORIGIN , ** extra_headers }),
291283 expected_origin ,
292284 ** kwargs ,
293285 )
0 commit comments