Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
style(ruff): remove legacy async
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm committed Apr 19, 2024
1 parent 0ec0975 commit 873d228
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/app/api/api_v1/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


@router.get("/authorize", summary="Request authorization code through GitHub OAuth app", include_in_schema=False)
async def authorize_github(
def authorize_github(
scope: str,
redirect_uri: HttpUrl,
) -> RedirectResponse:
Expand All @@ -40,7 +40,7 @@ async def authorize_github(
summary="Request a GitHub token from authorization code",
include_in_schema=False,
)
async def request_github_token_from_code(
def request_github_token_from_code(
payload: TokenRequest,
) -> GHToken:
return gh_client.get_token_from_code(payload.code, payload.redirect_uri)
Expand Down Expand Up @@ -99,7 +99,7 @@ async def login_with_github_token(


@router.get("/validate", status_code=status.HTTP_200_OK, summary="Check token validity")
async def check_token_validity(
def check_token_validity(
payload: TokenPayload = Security(get_token_payload, scopes=[UserScope.USER, UserScope.ADMIN]),
) -> TokenPayload:
return payload
10 changes: 5 additions & 5 deletions src/app/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
)


async def get_user_crud(session: AsyncSession = Depends(get_session)) -> UserCRUD:
def get_user_crud(session: AsyncSession = Depends(get_session)) -> UserCRUD:
return UserCRUD(session=session)


async def get_repo_crud(session: AsyncSession = Depends(get_session)) -> RepositoryCRUD:
def get_repo_crud(session: AsyncSession = Depends(get_session)) -> RepositoryCRUD:
return RepositoryCRUD(session=session)


async def get_guideline_crud(session: AsyncSession = Depends(get_session)) -> GuidelineCRUD:
def get_guideline_crud(session: AsyncSession = Depends(get_session)) -> GuidelineCRUD:
return GuidelineCRUD(session=session)


async def get_token_payload(
def get_token_payload(
security_scopes: SecurityScopes,
token: str = Depends(oauth2_scheme),
) -> TokenPayload:
Expand Down Expand Up @@ -91,5 +91,5 @@ async def get_current_user(
users: UserCRUD = Depends(get_user_crud),
) -> User:
"""Dependency to use as fastapi.security.Security with scopes"""
token_payload = await get_token_payload(security_scopes, token)
token_payload = get_token_payload(security_scopes, token)
return cast(User, await users.get(token_payload.user_id, strict=True))
6 changes: 3 additions & 3 deletions src/app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


async def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int] = None) -> str:
def create_access_token(content: Dict[str, Any], expires_minutes: Optional[int] = None) -> str:
"""Encode content dict using security algorithm, setting expiration."""
expire_delta = timedelta(minutes=expires_minutes or settings.ACCESS_TOKEN_EXPIRE_MINUTES)
expire = datetime.utcnow() + expire_delta
return jwt.encode({**content, "exp": expire}, settings.SECRET_KEY, algorithm=settings.JWT_ENCODING_ALGORITHM)


async def verify_password(plain_password: str, hashed_password: str) -> bool:
def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)


async def hash_password(password: str) -> str:
def hash_password(password: str) -> str:
return pwd_context.hash(password)
2 changes: 1 addition & 1 deletion src/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def add_process_time_header(request: Request, call_next):

# Overrides swagger to include favicon
@app.get("/docs", include_in_schema=False)
async def swagger_ui_html():
def swagger_ui_html():
return get_swagger_ui_html(
openapi_url=f"{settings.API_V1_STR}/openapi.json",
title=settings.PROJECT_NAME,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ async def async_session() -> AsyncSession:
await session.rollback()


async def mock_verify_password(plain_password, hashed_password):
def mock_verify_password(plain_password, hashed_password):
return hashed_password == f"hashed_{plain_password}"


async def mock_hash_password(password):
def mock_hash_password(password):
return f"hashed_{password}"


Expand Down
24 changes: 12 additions & 12 deletions src/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
)
@pytest.mark.asyncio()
async def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_name):
def test_githubclient_get_repo(repo_id, status_code, status_detail, expected_name):
github_client = GitHubClient()
if isinstance(expected_name, str):
response = github_client.get_repo(repo_id)
Expand All @@ -33,7 +33,7 @@ async def test_githubclient_get_repo(repo_id, status_code, status_detail, expect
],
)
@pytest.mark.asyncio()
async def test_githubclient_get_user(user_id, status_code, status_detail, expected_name):
def test_githubclient_get_user(user_id, status_code, status_detail, expected_name):
github_client = GitHubClient()
if isinstance(expected_name, str):
response = github_client.get_user(user_id)
Expand All @@ -53,7 +53,7 @@ async def test_githubclient_get_user(user_id, status_code, status_detail, expect
],
)
@pytest.mark.asyncio()
async def test_githubclient_get_readme(repo_name, status_code, status_detail, expected_path):
def test_githubclient_get_readme(repo_name, status_code, status_detail, expected_path):
github_client = GitHubClient()
if isinstance(expected_path, str):
response = github_client.get_readme(repo_name)
Expand All @@ -74,7 +74,7 @@ async def test_githubclient_get_readme(repo_name, status_code, status_detail, ex
],
)
@pytest.mark.asyncio()
async def test_githubclient_get_file(repo_name, file_path, status_code, status_detail):
def test_githubclient_get_file(repo_name, file_path, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.get_file(repo_name, file_path)
Expand All @@ -95,7 +95,7 @@ async def test_githubclient_get_file(repo_name, file_path, status_code, status_d
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_pulls(repo_name, status_code, status_detail):
def test_githubclient_list_pulls(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_pulls(repo_name)
Expand All @@ -114,7 +114,7 @@ async def test_githubclient_list_pulls(repo_name, status_code, status_detail):
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_code, status_detail):
def test_githubclient_list_comments_from_issue(repo_name, issue_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_comments_from_issue(issue_number, repo_name)
Expand All @@ -133,7 +133,7 @@ async def test_githubclient_list_comments_from_issue(repo_name, issue_number, st
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code, status_detail):
def test_githubclient_list_reviews_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_reviews_from_pull(repo_name, pull_number)
Expand All @@ -152,7 +152,7 @@ async def test_githubclient_list_reviews_from_pull(repo_name, pull_number, statu
],
)
@pytest.mark.asyncio()
async def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, status_code, status_detail):
def test_githubclient_list_review_comments_from_pull(repo_name, pull_number, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.list_review_comments_from_pull(pull_number, repo_name)
Expand All @@ -171,7 +171,7 @@ async def test_githubclient_list_review_comments_from_pull(repo_name, pull_numbe
],
)
@pytest.mark.asyncio()
async def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_detail):
def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.fetch_reviews_from_repo(repo_name, num_pulls=1)
Expand All @@ -190,7 +190,7 @@ async def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, stat
],
)
@pytest.mark.asyncio()
async def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, status_detail):
def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code, status_detail):
github_client = GitHubClient()
if status_code // 100 == 2:
response = github_client.fetch_pull_comments_from_repo(repo_name, num_pulls=1)
Expand Down Expand Up @@ -221,7 +221,7 @@ async def test_githubclient_fetch_pull_comments_from_repo(repo_name, status_code
],
)
@pytest.mark.asyncio()
async def test_githubclient_arrange_in_threads(comments, expected_output):
def test_githubclient_arrange_in_threads(comments, expected_output):
assert GitHubClient.arrange_in_threads(comments) == expected_output


Expand All @@ -232,6 +232,6 @@ async def test_githubclient_arrange_in_threads(comments, expected_output):
],
)
@pytest.mark.asyncio()
async def test_execute_in_parallel(func, arr, output):
def test_execute_in_parallel(func, arr, output):
assert list(execute_in_parallel(func, arr, num_threads=1)) == output
assert list(execute_in_parallel(func, arr, num_threads=2)) == output

0 comments on commit 873d228

Please sign in to comment.