tests/test_authentication.py::test_api_key_cookie_auth[pyloop] FAILED [ 5%]
tests/test_authentication.py::test_all_of_auth[pyloop] FAILED [ 7%]
tests/test_authentication.py::test_one_of_auth[pyloop] FAILED [ 8%]
tests/test_authentication.py::test_complex_auth[pyloop] FAILED [ 13%]
tests/test_docs_cookies.py::test_cookies[pyloop] FAILED [ 25%]
tests/test_docs_cookies.py::test_fail_validation[pyloop] FAILED [ 28%]
_______________________ test_api_key_cookie_auth[pyloop] _______________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006be54268>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_api_key_cookie_auth(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs", components="tests/testdata/components.yaml")
async def handler(request):
"""
---
security:
- apiKeyCookieAuth: []
responses:
'200':
description: OK.
"""
assert "C-API-KEY" in request["data"]
return web.json_response({"api_key": request["data"]["C-API-KEY"]})
s.add_route("GET", "/r", handler)
client = await aiohttp_client(app)
api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ4"
cookies = {"C-API-KEY": api_key}
resp = await client.get("/r", cookies=cookies)
> assert resp.status == 200
E assert 400 == 200
E + where 400 = <ClientResponse(http://127.0.0.1:56177/r) [400 {"C-API-KEY": "is required"}]>\n<CIMultiDictProxy('Content-Type': 'text/...harset=utf-8', 'Content-Length': '33', 'Date': 'Wed, 27 Nov 2019 13:17:32 GMT', 'Server': 'Python/3.7 aiohttp/3.5.1')>\n.status
tests/test_authentication.py:176: AssertionError
___________________________ test_all_of_auth[pyloop] ___________________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006bc722f0>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_all_of_auth(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs", components="tests/testdata/components.yaml")
async def handler(request):
"""
---
security:
- basicAuth: []
apiKeyCookieAuth: []
responses:
'200':
description: OK.
"""
assert "C-API-KEY" in request["data"]
assert "authorization" in request["data"]
return web.json_response(
{
"api_key": request["data"]["C-API-KEY"],
"authorization": request["data"]["authorization"],
}
)
s.add_route("GET", "/r", handler)
client = await aiohttp_client(app)
api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ4"
cookies = {"C-API-KEY": api_key}
authorization = "ZGVtbzpwQDU1dzByZA=="
headers = {"Authorization": f"Basic {authorization}"}
resp = await client.get("/r", headers=headers, cookies=cookies)
> assert resp.status == 200
E assert 400 == 200
E + where 400 = <ClientResponse(http://127.0.0.1:52737/r) [400 {"C-API-KEY": "is required"}]>\n<CIMultiDictProxy('Content-Type': 'text/...harset=utf-8', 'Content-Length': '33', 'Date': 'Wed, 27 Nov 2019 13:17:32 GMT', 'Server': 'Python/3.7 aiohttp/3.5.1')>\n.status
tests/test_authentication.py:226: AssertionError
___________________________ test_any_of_auth[pyloop] ___________________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006d56eb70>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_any_of_auth(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs", components="tests/testdata/components.yaml")
async def handler(request):
"""
---
security:
- bearerAuth: []
- apiKeyCookieAuth: []
responses:
'200':
description: OK.
"""
assert not (
"C-API-KEY" in request["data"] and "authorization" in request["data"]
)
r = {}
if "C-API-KEY" in request["data"]:
assert "authorization" not in request["data"]
r["api_key"] = request["data"]["C-API-KEY"]
else:
assert "authorization" in request["data"]
assert "C-API-KEY" not in request["data"]
r["authorization"] = request["data"]["authorization"]
return web.json_response(r)
s.add_route("GET", "/r", handler)
client = await aiohttp_client(app)
api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ4"
cookies = {"C-API-KEY": api_key}
resp = await client.get("/r", cookies=cookies)
> assert resp.status == 200
E assert 400 == 200
E + where 400 = <ClientResponse(http://127.0.0.1:54471/r) [400 "no auth has been provided"]>\n<CIMultiDictProxy('Content-Type': 'text/p...harset=utf-8', 'Content-Length': '32', 'Date': 'Wed, 27 Nov 2019 13:17:32 GMT', 'Server': 'Python/3.7 aiohttp/3.5.1')>\n.status
tests/test_authentication.py:283: AssertionError
__________________________ test_complex_auth[pyloop] ___________________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006be540d0>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_complex_auth(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs", components="tests/testdata/components.yaml")
async def handler(request):
"""
---
security:
- basicAuth: []
apiKeyCookieAuth: []
- bearerAuth: []
apiKeyHeaderAuth: []
responses:
'200':
description: OK.
"""
assert "C-API-KEY" in request["data"] or "x-api-key" in request["data"]
api_key = (
request["data"]["C-API-KEY"]
if "C-API-KEY" in request["data"]
else request["data"]["x-api-key"]
)
authorization = request["data"]["authorization"]
return web.json_response({"http": authorization, "api_key": api_key})
s.add_route("GET", "/r", handler)
client = await aiohttp_client(app)
option1_http = "111ZGVtbzpwQDU1dzByZA=="
option1_api_key = "111eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ4"
option1 = {
"cookies": {"C-API-KEY": option1_api_key},
"headers": {"Authorization": f"Basic {option1_http}"},
}
option2_http = "222ZGVtbzpwQDU1dzByZA=="
option2_api_key = "222eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ4"
option2 = {
"headers": {
"Authorization": f"Bearer {option2_http}",
"X-API-KEY": option2_api_key,
}
}
resp = await client.get("/r", **option1)
> assert resp.status == 200
E assert 400 == 200
E + where 400 = <ClientResponse(http://127.0.0.1:37611/r) [400 "no auth has been provided"]>\n<CIMultiDictProxy('Content-Type': 'text/p...harset=utf-8', 'Content-Length': '32', 'Date': 'Wed, 27 Nov 2019 13:17:32 GMT', 'Server': 'Python/3.7 aiohttp/3.5.1')>\n.status
tests/test_authentication.py:435: AssertionError
_____________________________ test_cookies[pyloop] _____________________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006be54510>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_cookies(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs")
async def handler(
request, array: List[int], integer: int, string: str, boolean: bool
):
"""
---
parameters:
- name: array
in: cookie
required: true
schema:
type: array
items:
type: integer
- name: integer
in: cookie
required: true
schema:
type: integer
- name: string
in: cookie
required: true
schema:
type: string
- name: boolean
in: cookie
required: true
schema:
type: boolean
responses:
'200':
description: OK.
"""
return web.json_response(
{"array": array, "integer": integer, "string": string, "boolean": boolean}
)
s.add_route("POST", "/r", handler)
client = await aiohttp_client(app)
c1 = [1, 2, 3, 4, 5]
c2 = 100
c3 = "string"
c4 = False
cookies = {
"array": ",".join(str(x) for x in c1),
"integer": c2,
"string": c3,
"boolean": str(c4).lower(),
}
resp = await client.post(f"/r", cookies=cookies)
> assert resp.status == 200
E assert 400 == 200
E + where 400 = <ClientResponse(http://127.0.0.1:50923/r) [400 {"array": "is required", "integer": "is required", "string": "is requir...arset=utf-8', 'Content-Length': '106', 'Date': 'Wed, 27 Nov 2019 13:17:32 GMT', 'Server': 'Python/3.7 aiohttp/3.5.1')>\n.status
tests/test_docs_cookies.py:71: AssertionError
_________________________ test_fail_validation[pyloop] _________________________
aiohttp_client = <function aiohttp_client.<locals>.go at 0x7f006bc9db70>
loop = <_UnixSelectorEventLoop running=False closed=False debug=False>
async def test_fail_validation(aiohttp_client, loop):
app = web.Application(loop=loop)
s = SwaggerDocs(app, "/docs")
async def handler(request, int32: int):
"""
---
parameters:
- name: int32
in: cookie
required: true
schema:
type: integer
format: int32
responses:
'200':
description: OK.
"""
return web.json_response({"int32": int32})
s.add_route("POST", "/r", handler)
client = await aiohttp_client(app)
cookies = {"int32": "abc"}
resp = await client.post(f"/r", cookies=cookies)
assert resp.status == 400
error = error_to_json(await resp.text())
> assert error == {"int32": "value should be type of int"}
E AssertionError: assert {'int32': 'is required'} == {'int32': 'value ... be type of int'}
E Differing items:
E {'int32': 'is required'} != {'int32': 'value should be type of int'}
E Full diff:
E - {'int32': 'is required'}
E + {'int32': 'value should be type of int'}
tests/test_docs_cookies.py:203: AssertionError