feat: update application version to 0.8.36 and enhance profile creation process
Deploy Development / deploy (push) Successful in 35s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 37s
Deploy Development / deploy (push) Successful in 35s
Test Suite / pytest-backend (push) Successful in 7s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 6s
Test Suite / playwright-tests (push) Failing after 37s
- Bumped application version to 0.8.36 in both backend and frontend files. - Updated the ProfileCreate model to require name and email fields, ensuring schema compliance. - Implemented a new POST /api/profiles endpoint restricted to platform admins, utilizing a random PIN for user setup. - Added integration tests for profile creation, including checks for unauthorized access and duplicate email handling. - Enhanced changelog to reflect the new version and changes made in this release.
This commit is contained in:
1 parent
caab9f2863
commit
35b14fe1a6
5 files changed
+124
-18
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Zugriffsrechte Profile: GET /api/profiles/{pid} und DELETE /api/profiles/{pid}.
|
||||
Zugriffsrechte Profile: POST/GET/DELETE /api/profiles/{pid}.
|
||||
|
||||
TestClient + Dependency-Override für Sessions; GET mockt profile_document, DELETE mockt DB,
|
||||
TestClient + Dependency-Override für Sessions; GET mockt profile_document, DELETE/POST mocken DB,
|
||||
damit keine echte Datenbank nötig ist.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -129,3 +129,65 @@ def test_delete_profile_admin_ok_when_multiple_profiles(client: TestClient) -> N
|
||||
assert any(
|
||||
args and "DELETE FROM profiles" in str(args[0][0]) for args in calls
|
||||
)
|
||||
|
||||
|
||||
def test_create_profile_forbidden_non_admin(client: TestClient) -> None:
|
||||
app.dependency_overrides[require_auth] = lambda: {"profile_id": 1, "role": "trainer"}
|
||||
with patch("routers.profiles.get_db") as mock_get_db:
|
||||
r = client.post(
|
||||
"/api/profiles",
|
||||
json={"name": "Neu", "email": "neu@example.com"},
|
||||
headers={"X-Auth-Token": "dummy"},
|
||||
)
|
||||
assert r.status_code == 403
|
||||
mock_get_db.assert_not_called()
|
||||
|
||||
|
||||
def test_create_profile_admin_duplicate_email(client: TestClient) -> None:
|
||||
mock_cm = MagicMock()
|
||||
mock_conn = MagicMock()
|
||||
mock_cm.__enter__.return_value = mock_conn
|
||||
mock_cm.__exit__.return_value = False
|
||||
mock_cur = MagicMock()
|
||||
mock_cur.fetchone.return_value = {"id": 99}
|
||||
|
||||
app.dependency_overrides[require_auth] = lambda: {"profile_id": 1, "role": "admin"}
|
||||
with patch("routers.profiles.get_db", return_value=mock_cm), patch(
|
||||
"routers.profiles.get_cursor", return_value=mock_cur
|
||||
), patch("routers.profiles.hash_pin", return_value="hashed"):
|
||||
r = client.post(
|
||||
"/api/profiles",
|
||||
json={"name": "Dup", "email": "dup@example.com"},
|
||||
headers={"X-Auth-Token": "dummy"},
|
||||
)
|
||||
assert r.status_code == 409
|
||||
|
||||
|
||||
def test_create_profile_admin_success(client: TestClient) -> None:
|
||||
mock_cm = MagicMock()
|
||||
mock_conn = MagicMock()
|
||||
mock_cm.__enter__.return_value = mock_conn
|
||||
mock_cm.__exit__.return_value = False
|
||||
mock_cur = MagicMock()
|
||||
mock_cur.fetchone.side_effect = [None, {"id": 501}]
|
||||
|
||||
doc = {"id": 501, "name": "Nu User", "email": "nu@example.com"}
|
||||
|
||||
app.dependency_overrides[require_auth] = lambda: {"profile_id": 1, "role": "superadmin"}
|
||||
with patch("routers.profiles.get_db", return_value=mock_cm), patch(
|
||||
"routers.profiles.get_cursor", return_value=mock_cur
|
||||
), patch("routers.profiles.profile_document", return_value=doc), patch(
|
||||
"routers.profiles.hash_pin", return_value="hashed"
|
||||
):
|
||||
r = client.post(
|
||||
"/api/profiles",
|
||||
json={"name": "Nu User", "email": "nu@example.com"},
|
||||
headers={"X-Auth-Token": "dummy"},
|
||||
)
|
||||
assert r.status_code == 200
|
||||
assert r.json() == doc
|
||||
|
||||
insert_calls = [
|
||||
c.args[0] for c in mock_cur.execute.call_args_list if c.args and "INSERT INTO profiles" in str(c.args[0])
|
||||
]
|
||||
assert len(insert_calls) >= 1
|
||||
Reference in new issue
Block a user