Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sternakt committed Oct 7, 2024
1 parent 101b4dc commit 979fc4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions fastagency/api/openapi/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_security_class(cls, type: str, schema_parameters: dict[str, Any]) -> Ali

@classmethod
def get_security_parameters(cls, schema_parameters: dict[str, Any]) -> str:
return f"{cls.__name__}(name={schema_parameters.get('name')})"
return f"{cls.__name__}(name='{schema_parameters.get('name')}')"


class BaseSecurityParameters(Protocol):
Expand Down Expand Up @@ -205,7 +205,7 @@ def is_supported(cls, type: str, schema_parameters: dict[str, Any]) -> bool:
def get_security_parameters(cls, schema_parameters: dict[str, Any]) -> str:
name = schema_parameters.get("name")
token_url = f'{schema_parameters.get("server_url")}/{schema_parameters["flows"]["password"]["tokenUrl"]}'
return f"{cls.__name__}(name={name}, token_url='{token_url}')"
return f"{cls.__name__}(name='{name}', token_url='{token_url}')"

class Parameters(BaseModel): # BaseSecurityParameters
"""OAuth2 Password Bearer security class."""
Expand Down
4 changes: 2 additions & 2 deletions tests/api/openapi/security/expected_main_gen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ app = OpenAPI(
response_model=Any,
responses={'422': {'model': HTTPValidationError}},
security=[
APIKeyHeader(name="access_token"),
APIKeyCookie(name="access_token"),
APIKeyHeader(name='access_token'),
APIKeyCookie(name='access_token'),
],
)
def read_items_items__get(
Expand Down
10 changes: 9 additions & 1 deletion tests/api/openapi/security/test_oauth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ def openapi_oauth2_schema() -> dict[str, Any]:
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
"content": {
"application/json": {
"schema": {
"additionalProperties": {"type": "string"},
"type": "object",
"title": "Response Login Token Post",
}
}
},
},
"422": {
"description": "Validation Error",
Expand Down
3 changes: 1 addition & 2 deletions tests/api/openapi/security/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_generate_client(secure_fastapi_url: str) -> None:
with expected_models_gen_path.open() as f:
expected_models_gen = f.readlines()[4:]

# print(actual_main_gen_txt)
assert actual_main_gen_txt == expected_main_gen_txt
assert actual_models_gen == expected_models_gen

Expand Down Expand Up @@ -106,7 +105,7 @@ def test_import_and_call_generate_client(secure_fastapi_url: str) -> None:
assert client_resp == {"api_key": api_key}


def test__get_matching_security(secure_fastapi_url: str) -> None:
def test_get_matching_security(secure_fastapi_url: str) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
td = Path(temp_dir) / "gen"

Expand Down

0 comments on commit 979fc4c

Please sign in to comment.