Browse Source

Update for updated tests

pull/4791/head
bilalAlpaslan 2 years ago
parent
commit
35726e0e14
  1. 35
      tests/test_security_api_key_cookie.py
  2. 42
      tests/test_security_api_key_cookie_description.py
  3. 35
      tests/test_security_api_key_cookie_optional.py
  4. 33
      tests/test_security_api_key_header.py
  5. 40
      tests/test_security_api_key_header_description.py
  6. 33
      tests/test_security_api_key_header_optional.py
  7. 33
      tests/test_security_api_key_query.py
  8. 40
      tests/test_security_api_key_query_description.py
  9. 33
      tests/test_security_api_key_query_optional.py

35
tests/test_security_api_key_cookie.py

@ -22,37 +22,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
return current_user return current_user
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "cookie"}}
},
}
def test_openapi_schema():
client = TestClient(app)
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
client = TestClient(app, cookies={"key": "secret"}) client = TestClient(app, cookies={"key": "secret"})
response = client.get("/users/me") response = client.get("/users/me")
@ -85,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyCookie": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyCookie": {"type": "apiKey", "name": "key", "in": "cookie"} "key": {"type": "apiKey", "name": "key", "in": "cookie"}
} }
}, },
} }

42
tests/test_security_api_key_cookie_description.py

@ -22,44 +22,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
return current_user return current_user
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {
"key": {
"type": "apiKey",
"name": "key",
"in": "cookie",
"description": "An API Cookie Key",
}
}
},
}
def test_openapi_schema():
client = TestClient(app)
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
client = TestClient(app, cookies={"key": "secret"}) client = TestClient(app, cookies={"key": "secret"})
response = client.get("/users/me") response = client.get("/users/me")
@ -92,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyCookie": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyCookie": { "key": {
"type": "apiKey", "type": "apiKey",
"name": "key", "name": "key",
"in": "cookie", "in": "cookie",

35
tests/test_security_api_key_cookie_optional.py

@ -29,37 +29,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
return current_user return current_user
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "cookie"}}
},
}
def test_openapi_schema():
client = TestClient(app)
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
client = TestClient(app, cookies={"key": "secret"}) client = TestClient(app, cookies={"key": "secret"})
response = client.get("/users/me") response = client.get("/users/me")
@ -92,13 +61,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyCookie": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyCookie": {"type": "apiKey", "name": "key", "in": "cookie"} "key": {"type": "apiKey", "name": "key", "in": "cookie"}
} }
}, },
} }

33
tests/test_security_api_key_header.py

@ -24,35 +24,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "header"}}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me", headers={"key": "secret"}) response = client.get("/users/me", headers={"key": "secret"})
@ -83,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyHeader": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyHeader": {"type": "apiKey", "name": "key", "in": "header"} "key": {"type": "apiKey", "name": "key", "in": "header"}
} }
}, },
} }

40
tests/test_security_api_key_header_description.py

@ -24,42 +24,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {
"key": {
"type": "apiKey",
"name": "key",
"in": "header",
"description": "An API Key Header",
}
}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me", headers={"key": "secret"}) response = client.get("/users/me", headers={"key": "secret"})
@ -90,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyHeader": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyHeader": { "key": {
"type": "apiKey", "type": "apiKey",
"name": "key", "name": "key",
"in": "header", "in": "header",

33
tests/test_security_api_key_header_optional.py

@ -30,35 +30,6 @@ def read_current_user(current_user: Optional[User] = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "header"}}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me", headers={"key": "secret"}) response = client.get("/users/me", headers={"key": "secret"})
@ -89,13 +60,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyHeader": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyHeader": {"type": "apiKey", "name": "key", "in": "header"} "key": {"type": "apiKey", "name": "key", "in": "header"}
} }
}, },
} }

33
tests/test_security_api_key_query.py

@ -24,35 +24,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "query"}}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me?key=secret") response = client.get("/users/me?key=secret")
@ -83,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyQuery": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyQuery": {"type": "apiKey", "name": "key", "in": "query"} "key": {"type": "apiKey", "name": "key", "in": "query"}
} }
}, },
} }

40
tests/test_security_api_key_query_description.py

@ -24,42 +24,6 @@ def read_current_user(current_user: User = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {
"key": {
"type": "apiKey",
"name": "key",
"in": "query",
"description": "API Key Query",
}
}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me?key=secret") response = client.get("/users/me?key=secret")
@ -90,13 +54,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyQuery": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyQuery": { "key": {
"type": "apiKey", "type": "apiKey",
"name": "key", "name": "key",
"in": "query", "in": "query",

33
tests/test_security_api_key_query_optional.py

@ -30,35 +30,6 @@ def read_current_user(current_user: Optional[User] = Depends(get_current_user)):
client = TestClient(app) client = TestClient(app)
openapi_schema = {
"openapi": "3.0.2",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/users/me": {
"get": {
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
}
},
"summary": "Read Current User",
"operationId": "read_current_user_users_me_get",
"security": [{"key": []}],
}
}
},
"components": {
"securitySchemes": {"key": {"type": "apiKey", "name": "key", "in": "query"}}
},
}
def test_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
def test_security_api_key(): def test_security_api_key():
response = client.get("/users/me?key=secret") response = client.get("/users/me?key=secret")
@ -89,13 +60,13 @@ def test_openapi_schema():
}, },
"summary": "Read Current User", "summary": "Read Current User",
"operationId": "read_current_user_users_me_get", "operationId": "read_current_user_users_me_get",
"security": [{"APIKeyQuery": []}], "security": [{"key": []}],
} }
} }
}, },
"components": { "components": {
"securitySchemes": { "securitySchemes": {
"APIKeyQuery": {"type": "apiKey", "name": "key", "in": "query"} "key": {"type": "apiKey", "name": "key", "in": "query"}
} }
}, },
} }

Loading…
Cancel
Save