[lint] more linting changes

This commit is contained in:
2026-07-29 03:30:54 +02:00
parent 3f20cdeed9
commit 7a70b6b1d4
6 changed files with 28 additions and 14 deletions

View File

@@ -69,7 +69,7 @@ def del_card(
logger.info(f"The key:'{key}' was not found in db!") logger.info(f"The key:'{key}' was not found in db!")
raise HTTPException( raise HTTPException(
status.HTTP_500_INTERNAL_SERVER_ERROR, status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Key on card not found in DB. Please tell an admin about this. KEY={key}", detail="Key on card not found in DB. Please tell an admin about this. KEY={key}", # noqa: E501
) )
db.delete(card) db.delete(card)
db.commit() db.commit()

View File

@@ -1,6 +1,4 @@
import logging import logging
logger = logging.getLogger(__name__)
import os import os
from contextlib import asynccontextmanager from contextlib import asynccontextmanager
@@ -11,6 +9,7 @@ from fastapi.security import OAuth2PasswordBearer
load_dotenv() load_dotenv()
# ruff: disable[E402]
from app.controllers import ( from app.controllers import (
aaManager, aaManager,
cardManager, cardManager,
@@ -24,6 +23,10 @@ from app.services.database import create_db_and_tables, get_db_session
from app.services.scanner import BackgroundScanner from app.services.scanner import BackgroundScanner
from app.services.settings import verify_settings from app.services.settings import verify_settings
# ruff: enable[E402]
logger = logging.getLogger(__name__)
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
scanner = BackgroundScanner(db=get_db_session()) scanner = BackgroundScanner(db=get_db_session())
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)

View File

@@ -17,7 +17,7 @@ def verify_settings():
"DISABLE_CARDS" "DISABLE_CARDS"
): ):
raise ValueError( raise ValueError(
f"Missing environment variable for scanner start: {setting} \n Run with DISABLE_CARDS env var to disable cards" f"Missing environment variable for scanner start: {setting} \n Run with DISABLE_CARDS env var to disable cards" # noqa: E501
) )
for setting in important_envs: for setting in important_envs:
if setting not in os.environ or setting == "": if setting not in os.environ or setting == "":

View File

@@ -31,6 +31,20 @@ python-desfire = ["poetry"]
py-modules = ["app"] py-modules = ["app"]
[tool.ruff] [tool.ruff]
exclude = [ exclude = ["alembic"]
"alembic" [tool.ruff.lint]
] select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
"I",
]
ignore = ["B008"]

View File

@@ -39,7 +39,7 @@ def test_update_card(client, auth_headers, test_group, test_card):
data = response.json() data = response.json()
assert data["name"] == "changed_name" assert data["name"] == "changed_name"
assert data["enabled"] == False assert data["enabled"] == False # noqa: E712
assert data["group_id"] == test_card.group_id assert data["group_id"] == test_card.group_id

View File

@@ -42,8 +42,7 @@ def test_check_access_with_valid_timetable(db_session):
db_session.commit() db_session.commit()
# Test: access should be granted within time window # Test: access should be granted within time window
result = checkAccess("test-key-123", db_session) assert checkAccess("test-key-123", db_session)
assert result == True
def test_check_access_outside_hours(db_session): def test_check_access_outside_hours(db_session):
@@ -74,8 +73,7 @@ def test_check_access_outside_hours(db_session):
group.accessauths = [aa] group.accessauths = [aa]
db_session.commit() db_session.commit()
result = checkAccess("test-key-123", db_session) assert not checkAccess("test-key-123", db_session)
assert result == False
def test_check_access_with_valid_oneshot(db_session): def test_check_access_with_valid_oneshot(db_session):
@@ -106,8 +104,7 @@ def test_check_access_with_valid_oneshot(db_session):
db_session.commit() db_session.commit()
# Test: access should be granted within time window # Test: access should be granted within time window
result = checkAccess("test-key-123", db_session) assert checkAccess("test-key-123", db_session)
assert result == True
assert aa.oneshot.uses == 0 assert aa.oneshot.uses == 0