diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ee4836f..2326503 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: debug-statements language_version: python3 - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.3.7' + rev: 'v0.4.0' hooks: - id: ruff args: diff --git a/poetry.lock b/poetry.lock index ec60f85..ef80c3a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2354,28 +2354,28 @@ files = [ [[package]] name = "ruff" -version = "0.3.7" +version = "0.4.0" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, - {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, - {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, - {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, - {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, - {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, + {file = "ruff-0.4.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:70b8c620cf2212744eabd6d69c4f839f2be0d8880d27beaeb0adb6aa0b316aa8"}, + {file = "ruff-0.4.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:cfa3e3ff53be05a8c5570c1585ea1e089f6b399ca99fcb78598d4a8234f248db"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5616cca501d1d16b932b7e607d7e1fd1b8c8c51d6ee484b7940fc1adc5bea541"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:46eff08dd480b5d9b540846159fe134d70e3c45a3c913c600047cbf7f0e4e308"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:2d546f511431fff2b17adcf7110f3b2c2c0c8d33b0e10e5fd27fd340bc617efc"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:c7b6b6b38e216036284c5779b6aa14acbf5664e3b5872533219cf93daf40ddfb"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5e1cf8b064bb2a6b4922af7274fe2dffcb552d96ba716b2fbe5e2c970ed7de18"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9911c9046b94253e1fa844c0192bb764b86866a881502dee324686474d498c17"}, + {file = "ruff-0.4.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4ca7a971c8f1a0b6f5ff4a819c0d1c2619536530bbd5a289af725d8b2ef1013d"}, + {file = "ruff-0.4.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:752e0f77f421141dd470a0b1bed4fd8f763aebabe32c80ed3580f740ef4ba807"}, + {file = "ruff-0.4.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:84f2a5dd8f33964d826c5377e094f7ce11e55e432cd42d3bf64efe4384224a03"}, + {file = "ruff-0.4.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:0b20e7db4a672495320a8a18149b7febf4e4f97509a4657367144569ce0915fd"}, + {file = "ruff-0.4.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:0b0eddd339e24dc4f7719b1cde4967f6b6bc0ad948cc183711ba8910f14aeafe"}, + {file = "ruff-0.4.0-py3-none-win32.whl", hash = "sha256:e70befd488271a2c28c80bd427f73d8855dd222fc549fa1e9967d287c5cfe781"}, + {file = "ruff-0.4.0-py3-none-win_amd64.whl", hash = "sha256:8584b9361900997ccf8d7aaa4dc4ab43e258a853ca7189d98ac929dc9ee50875"}, + {file = "ruff-0.4.0-py3-none-win_arm64.whl", hash = "sha256:fea4ec813c965e40af29ee627a1579ee1d827d77e81d54b85bdd7b42d1540cdd"}, + {file = "ruff-0.4.0.tar.gz", hash = "sha256:7457308d9ebf00d6a1c9a26aa755e477787a636c90b823f91cd7d4bea9e89260"}, ] [[package]] @@ -2885,4 +2885,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "c4ed327b3390d82fe7c3a4e0b100ca41caa6727ceec8117922b660c9c101a0c6" +content-hash = "77b0fef700b9f5cfb802d46bae93588c8881d65dcccd93c1f4051321859e3bf3" diff --git a/pyproject.toml b/pyproject.toml index 3b4a0b3..8e45f28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ prometheus-fastapi-instrumentator = "^6.1.0" optional = true [tool.poetry.group.quality.dependencies] -ruff = "==0.3.7" +ruff = "==0.4.0" mypy = "==1.9.0" types-requests = ">=2.0.0" types-passlib = ">=1.7.0" diff --git a/src/app/api/api_v1/endpoints/login.py b/src/app/api/api_v1/endpoints/login.py index a864c12..3127b91 100644 --- a/src/app/api/api_v1/endpoints/login.py +++ b/src/app/api/api_v1/endpoints/login.py @@ -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: @@ -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) @@ -59,16 +59,12 @@ async def login_with_creds( """ # Verify credentials user = await users.get_by_login(form_data.username) - if ( - user is None - or user.hashed_password is None - or not await verify_password(form_data.password, user.hashed_password) - ): + if user is None or user.hashed_password is None or not verify_password(form_data.password, user.hashed_password): raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials.") telemetry_client.capture(user.id, event="user-login", properties={"method": "credentials"}) # create access token using user user_id/user_scopes token_data = {"sub": str(user.id), "scopes": user.scope.split()} - token = await create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES) + token = create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES) return Token(access_token=token, token_type="bearer") # noqa S106 @@ -93,13 +89,13 @@ async def login_with_github_token( # create access token using user user_id/user_scopes token_data = {"sub": str(user.id), "scopes": user.scope.split()} - token = await create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES) + token = create_access_token(token_data, settings.ACCESS_TOKEN_UNLIMITED_MINUTES) return Token(access_token=token, token_type="bearer") # noqa S106 @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 diff --git a/src/app/api/api_v1/endpoints/users.py b/src/app/api/api_v1/endpoints/users.py index 1cf44b2..4234bfd 100644 --- a/src/app/api/api_v1/endpoints/users.py +++ b/src/app/api/api_v1/endpoints/users.py @@ -65,7 +65,7 @@ async def _create_user(payload: UserCreate, users: UserCRUD, requester_id: Union if (await users.get_by_login(payload.login, strict=False)) is not None: raise HTTPException(status.HTTP_409_CONFLICT, "Login already taken") valid_creds = True - hashed_password = await hash_password(payload.password) + hashed_password = hash_password(payload.password) if not valid_creds: raise HTTPException( @@ -135,7 +135,7 @@ async def update_user_password( token_payload: TokenPayload = Security(get_token_payload, scopes=[UserScope.ADMIN]), ) -> User: telemetry_client.capture(token_payload.user_id, event="user-pwd", properties={"user_id": user_id}) - pwd = await hash_password(payload.password) + pwd = hash_password(payload.password) return await users.update(user_id, CredHash(hashed_password=pwd)) diff --git a/src/app/api/dependencies.py b/src/app/api/dependencies.py index adc2b87..d668028 100644 --- a/src/app/api/dependencies.py +++ b/src/app/api/dependencies.py @@ -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: @@ -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)) diff --git a/src/app/core/security.py b/src/app/core/security.py index bff3ffb..021a9d5 100644 --- a/src/app/core/security.py +++ b/src/app/core/security.py @@ -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) diff --git a/src/app/db.py b/src/app/db.py index c8fe315..96cfe8c 100644 --- a/src/app/db.py +++ b/src/app/db.py @@ -41,7 +41,7 @@ async def init_db() -> None: logger.info("Initializing PostgreSQL database...") # Fetch authenticated GitHub User gh_user = gh_client.get_my_user(settings.SUPERADMIN_GH_PAT) - pwd = await hash_password(settings.SUPERADMIN_PWD) + pwd = hash_password(settings.SUPERADMIN_PWD) session.add( User( provider_user_id=gh_user["id"], diff --git a/src/app/main.py b/src/app/main.py index 7ac2c8f..a422754 100644 --- a/src/app/main.py +++ b/src/app/main.py @@ -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, diff --git a/src/tests/conftest.py b/src/tests/conftest.py index 42defd6..bb82913 100644 --- a/src/tests/conftest.py +++ b/src/tests/conftest.py @@ -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}" @@ -152,9 +152,9 @@ async def guideline_session(user_session: AsyncSession, monkeypatch): yield user_session -async def get_token(access_id: int, scopes: str) -> Dict[str, str]: +def get_token(access_id: int, scopes: str) -> Dict[str, str]: token_data = {"sub": str(access_id), "scopes": scopes} - token = await create_access_token(token_data) + token = create_access_token(token_data) return {"Authorization": f"Bearer {token}", "Content-Type": "application/json"} diff --git a/src/tests/endpoints/test_code.py b/src/tests/endpoints/test_code.py index 8474936..c094113 100644 --- a/src/tests/endpoints/test_code.py +++ b/src/tests/endpoints/test_code.py @@ -61,7 +61,7 @@ async def test_chat( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.post("/code/chat", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) diff --git a/src/tests/endpoints/test_guidelines.py b/src/tests/endpoints/test_guidelines.py index 7b966e6..ea067e6 100644 --- a/src/tests/endpoints/test_guidelines.py +++ b/src/tests/endpoints/test_guidelines.py @@ -25,7 +25,7 @@ async def test_create_guideline( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.post("/guidelines", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -62,7 +62,7 @@ async def test_get_guideline( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get(f"/guidelines/{guideline_id}", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -91,7 +91,7 @@ async def test_fetch_guidelines( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get("/guidelines", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -124,7 +124,7 @@ async def test_delete_guideline( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.request("DELETE", f"/guidelines/{guideline_id}", json={}, headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -159,7 +159,7 @@ async def test_update_guideline_content( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.patch(f"/guidelines/{guideline_id}", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) diff --git a/src/tests/endpoints/test_repos.py b/src/tests/endpoints/test_repos.py index 1369786..3b63d6b 100644 --- a/src/tests/endpoints/test_repos.py +++ b/src/tests/endpoints/test_repos.py @@ -44,7 +44,7 @@ async def test_create_repo( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.post("/repos", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -76,7 +76,7 @@ async def test_get_repo( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get(f"/repos/{repo_id}", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -105,7 +105,7 @@ async def test_fetch_repos( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get("/repos", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -138,7 +138,7 @@ async def test_delete_repo( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.delete(f"/repos/{repo_id}", headers=auth) assert response.status_code == status_code, print(response.__dict__) diff --git a/src/tests/endpoints/test_users.py b/src/tests/endpoints/test_users.py index e2caa2e..9a04790 100644 --- a/src/tests/endpoints/test_users.py +++ b/src/tests/endpoints/test_users.py @@ -54,7 +54,7 @@ async def test_create_user( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.post("/users", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -93,7 +93,7 @@ async def test_get_user( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get(f"/users/{user_id}", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -121,7 +121,7 @@ async def test_fetch_users( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.get("/users/", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -152,7 +152,7 @@ async def test_delete_user( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.delete(f"/users/{user_id}", headers=auth) assert response.status_code == status_code, print(response.__dict__) @@ -186,7 +186,7 @@ async def test_update_user_password( ): auth = None if isinstance(user_idx, int): - auth = await pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) + auth = pytest.get_token(pytest.user_table[user_idx]["id"], pytest.user_table[user_idx]["scope"].split()) response = await async_client.patch(f"/users/{user_id}", json=payload, headers=auth) assert response.status_code == status_code, print(response.__dict__) diff --git a/src/tests/test_dependencies.py b/src/tests/test_dependencies.py index 0042022..c8e8c3d 100644 --- a/src/tests/test_dependencies.py +++ b/src/tests/test_dependencies.py @@ -16,13 +16,12 @@ (["admin"], {"sub": "123", "scopes": ["user"]}, None, 403, None), ], ) -@pytest.mark.asyncio() -async def test_get_token_payload(scopes, token, expires_minutes, error_code, expected_payload): - _token = await create_access_token(token, expires_minutes) if isinstance(token, dict) else token +def test_get_token_payload(scopes, token, expires_minutes, error_code, expected_payload): + _token = create_access_token(token, expires_minutes) if isinstance(token, dict) else token if isinstance(error_code, int): with pytest.raises(HTTPException): - await get_token_payload(SecurityScopes(scopes), _token) + get_token_payload(SecurityScopes(scopes), _token) else: - payload = await get_token_payload(SecurityScopes(scopes), _token) + payload = get_token_payload(SecurityScopes(scopes), _token) if expected_payload is not None: assert payload.model_dump() == expected_payload diff --git a/src/tests/test_security.py b/src/tests/test_security.py index eb69161..2634a07 100644 --- a/src/tests/test_security.py +++ b/src/tests/test_security.py @@ -7,24 +7,22 @@ from app.core.security import create_access_token, hash_password, verify_password -@pytest.mark.asyncio() -async def test_hash_password(): +def test_hash_password(): pwd1 = "my_password" - hash_pwd1 = await hash_password(pwd1) + hash_pwd1 = hash_password(pwd1) assert hash_pwd1 != pwd1 - assert hash_pwd1 != await hash_password(pwd1 + "bis") + assert hash_pwd1 != hash_password(pwd1 + "bis") # Check that it's non deterministic - assert hash_pwd1 != await hash_password(pwd1) + assert hash_pwd1 != hash_password(pwd1) -@pytest.mark.asyncio() -async def test_verify_password(): +def test_verify_password(): pwd1 = "my_password" - hash_pwd1 = await hash_password(pwd1) + hash_pwd1 = hash_password(pwd1) - assert await verify_password(pwd1, hash_pwd1) - assert not await verify_password("another_try", hash_pwd1) + assert verify_password(pwd1, hash_pwd1) + assert not verify_password("another_try", hash_pwd1) @pytest.mark.parametrize( @@ -34,9 +32,8 @@ async def test_verify_password(): ({"data": "my_data"}, None, settings.ACCESS_TOKEN_EXPIRE_MINUTES), ], ) -@pytest.mark.asyncio() -async def test_create_access_token(content, expires_minutes, expected_delta): - payload = await create_access_token(content, expires_minutes) +def test_create_access_token(content, expires_minutes, expected_delta): + payload = create_access_token(content, expires_minutes) after = datetime.utcnow() assert isinstance(payload, str) decoded_data = jwt.decode(payload, settings.SECRET_KEY, algorithms=[settings.JWT_ENCODING_ALGORITHM]) diff --git a/src/tests/test_services.py b/src/tests/test_services.py index ebc3ae6..529b6c1 100644 --- a/src/tests/test_services.py +++ b/src/tests/test_services.py @@ -12,8 +12,7 @@ (249513553, 200, None, "frgfm/torch-cam"), ], ) -@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) @@ -32,8 +31,7 @@ async def test_githubclient_get_repo(repo_id, status_code, status_detail, expect (26927750, 200, None, "frgfm"), ], ) -@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) @@ -52,8 +50,7 @@ async def test_githubclient_get_user(user_id, status_code, status_detail, expect ("frgfm/torch-cam", 200, None, "README.md"), ], ) -@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) @@ -73,8 +70,7 @@ async def test_githubclient_get_readme(repo_name, status_code, status_detail, ex ("frgfm/torch-cam", "CONTRIBUTING.md", 200, None), ], ) -@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) @@ -94,8 +90,7 @@ async def test_githubclient_get_file(repo_name, file_path, status_code, status_d ("frgfm/torch-cam", 200, None), ], ) -@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) @@ -113,8 +108,7 @@ async def test_githubclient_list_pulls(repo_name, status_code, status_detail): ("frgfm/torch-cam", 181, 200, None), ], ) -@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) @@ -132,8 +126,7 @@ async def test_githubclient_list_comments_from_issue(repo_name, issue_number, st ("frgfm/Holocron", 279, 200, None), ], ) -@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) @@ -151,8 +144,7 @@ async def test_githubclient_list_reviews_from_pull(repo_name, pull_number, statu ("frgfm/Holocron", 279, 200, None), ], ) -@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) @@ -170,8 +162,7 @@ async def test_githubclient_list_review_comments_from_pull(repo_name, pull_numbe ("frgfm/Holocron", 200, None), ], ) -@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) @@ -189,8 +180,7 @@ async def test_githubclient_fetch_reviews_from_repo(repo_name, status_code, stat ("frgfm/Holocron", 200, None), ], ) -@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) @@ -220,8 +210,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 @@ -231,7 +220,6 @@ async def test_githubclient_arrange_in_threads(comments, expected_output): (lambda x: x**2, [1, 2, 3], [1, 4, 9]), ], ) -@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