refactor: streamline code formatting in API and tests
Some checks failed
CI / lint-and-test (push) Failing after 1m17s
Some checks failed
CI / lint-and-test (push) Failing after 1m17s
- Consolidated function call formatting in `admin_reassign_duty` for improved readability. - Enhanced test cases by standardizing header formatting in API requests, ensuring consistency across tests. - Improved overall code clarity and maintainability by adhering to established coding style guidelines.
This commit is contained in:
@@ -39,7 +39,12 @@ def test_admin_me_returns_is_admin_true_when_admin(
|
||||
mock_get_user.return_value = SimpleNamespace(full_name="Admin", username="admin")
|
||||
mock_can_access.return_value = True
|
||||
mock_is_admin.return_value = True
|
||||
r = client.get("/api/admin/me", headers={"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A100%7D&hash=x"})
|
||||
r = client.get(
|
||||
"/api/admin/me",
|
||||
headers={
|
||||
"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A100%7D&hash=x"
|
||||
},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"is_admin": True}
|
||||
|
||||
@@ -59,7 +64,12 @@ def test_admin_me_returns_is_admin_false_when_not_admin(
|
||||
mock_get_user.return_value = SimpleNamespace(full_name="User", username="user")
|
||||
mock_can_access.return_value = True
|
||||
mock_is_admin.return_value = False
|
||||
r = client.get("/api/admin/me", headers={"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A200%7D&hash=x"})
|
||||
r = client.get(
|
||||
"/api/admin/me",
|
||||
headers={
|
||||
"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A200%7D&hash=x"
|
||||
},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"is_admin": False}
|
||||
|
||||
@@ -91,7 +101,9 @@ def test_admin_users_403_when_not_admin(
|
||||
mock_is_admin.return_value = False # not admin
|
||||
r = client.get(
|
||||
"/api/admin/users",
|
||||
headers={"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A100%7D&hash=x"},
|
||||
headers={
|
||||
"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A100%7D&hash=x"
|
||||
},
|
||||
)
|
||||
assert r.status_code == 403
|
||||
detail = r.json()["detail"]
|
||||
@@ -239,7 +251,9 @@ def test_admin_reassign_400_when_user_not_found(
|
||||
r = client.patch(
|
||||
"/api/admin/duties/1",
|
||||
json={"user_id": 999},
|
||||
headers={"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A1%7D&hash=x"},
|
||||
headers={
|
||||
"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A1%7D&hash=x"
|
||||
},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
mock_update.assert_not_called()
|
||||
@@ -293,7 +307,9 @@ def test_admin_reassign_200_updates_and_invalidates(
|
||||
r = client.patch(
|
||||
"/api/admin/duties/1",
|
||||
json={"user_id": 2},
|
||||
headers={"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A1%7D&hash=x"},
|
||||
headers={
|
||||
"X-Telegram-Init-Data": "auth_date=1&user=%7B%22id%22%3A1%7D&hash=x"
|
||||
},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
data = r.json()
|
||||
|
||||
Reference in New Issue
Block a user