diff options
| author | Claude Sonnet 4.6 | 2026-08-31 10:01:00 +0000 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2026-08-31 10:27:14 -0500 |
| commit | 894f169bfc4f9ca9746f93a7032687be8ac24f88 (patch) | |
| tree | d9ccdb67885fc0b8cb781f4bf3f448bcbbe677e9 /tests/unit/auth/test_admin_users.py | |
| parent | 5b4380e61e003a9b4450221d0f499db069098c19 (diff) | |
| download | gn-auth-894f169bfc4f9ca9746f93a7032687be8ac24f88.tar.gz | |
Update test_admin_users.py for new admin users endpoint
Update HTTP endpoint tests to use the new URL POST /auth/system/administration/users/create and the new mock path gn_auth.auth.system.admin.users.require_oauth.acquire Model-level tests (create_verified_user) are unchanged. Reviewed-By: Frederick M. Muriith <fredmanglis@gmail.com>
Diffstat (limited to 'tests/unit/auth/test_admin_users.py')
| -rw-r--r-- | tests/unit/auth/test_admin_users.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/tests/unit/auth/test_admin_users.py b/tests/unit/auth/test_admin_users.py index f31e6af..eaa5bcd 100644 --- a/tests/unit/auth/test_admin_users.py +++ b/tests/unit/auth/test_admin_users.py @@ -81,21 +81,22 @@ def test_create_verified_user_raises_on_duplicate_email(conn_after_auth_migratio # --------------------------------------------------------------------------- -# HTTP endpoint tests: POST /auth/user/create +# HTTP endpoint tests: POST /auth/system/administration/users/create # --------------------------------------------------------------------------- _NEW_USER_BODY = {"email": "newbie@example.org", "name": "Newbie", "password": "s3cr3t"} +_CREATE_URL = "/auth/system/administration/users/create" @pytest.mark.unit_test def test_create_user_endpoint_no_token_returns_401(fxtr_app): """ GIVEN: no Authorization header - WHEN: POST /auth/user/create - THEN: 401 is returned (OAuth2 layer rejects unauthenticated request) + WHEN: POST /auth/system/administration/users/create + THEN: 401 is returned """ with fxtr_app.test_client() as http: - res = http.post("/auth/user/create", json=_NEW_USER_BODY) + res = http.post(_CREATE_URL, json=_NEW_USER_BODY) assert res.status_code == 401 @@ -103,19 +104,19 @@ def test_create_user_endpoint_no_token_returns_401(fxtr_app): def test_create_user_endpoint_non_admin_returns_403(fxtr_app, mocker, fxtr_oauth2_clients): """ GIVEN: a valid token belonging to a non-admin user - WHEN: POST /auth/user/create + WHEN: POST /auth/system/administration/users/create THEN: 403 is returned """ _conn, clients = fxtr_oauth2_clients user = conftest.TEST_USERS[3] # unaff@iliated.user — no privileges mocker.patch( - "gn_auth.auth.authorisation.users.views.require_oauth.acquire", + "gn_auth.auth.system.admin.users.require_oauth.acquire", conftest.get_tokeniser( user, tuple(c for c in clients if c.user == user)[0])) with fxtr_app.test_client() as http: res = http.post( - "/auth/user/create", + _CREATE_URL, json=_NEW_USER_BODY, headers={"Authorization": "Bearer some-mocked-token"}) assert res.status_code == 403 @@ -127,7 +128,7 @@ def _setup_admin_mock(conn, clients, mocker): with db.cursor(conn) as cursor: grant_sysadmin_role(cursor, admin) mocker.patch( - "gn_auth.auth.authorisation.users.views.require_oauth.acquire", + "gn_auth.auth.system.admin.users.require_oauth.acquire", conftest.get_tokeniser( admin, tuple(c for c in clients if c.user == admin)[0])) @@ -138,14 +139,14 @@ def _setup_admin_mock(conn, clients, mocker): def test_create_user_endpoint_admin_returns_201(fxtr_app, mocker, fxtr_oauth2_clients): """ GIVEN: a valid system-admin token and a valid request body - WHEN: POST /auth/user/create + WHEN: POST /auth/system/administration/users/create THEN: 201 is returned """ conn, clients = fxtr_oauth2_clients _setup_admin_mock(conn, clients, mocker) with fxtr_app.test_client() as http: res = http.post( - "/auth/user/create", + _CREATE_URL, json={**_NEW_USER_BODY, "password": "s3cr3tP4ssw0rd"}, headers={"Authorization": "Bearer some-mocked-token"}) assert res.status_code == 201 @@ -155,14 +156,14 @@ def test_create_user_endpoint_admin_returns_201(fxtr_app, mocker, fxtr_oauth2_cl def test_create_user_endpoint_admin_returns_new_user(fxtr_app, mocker, fxtr_oauth2_clients): """ GIVEN: a valid system-admin token and a valid request body - WHEN: POST /auth/user/create + WHEN: POST /auth/system/administration/users/create THEN: the response body contains the new user's email and name """ conn, clients = fxtr_oauth2_clients _setup_admin_mock(conn, clients, mocker) with fxtr_app.test_client() as http: res = http.post( - "/auth/user/create", + _CREATE_URL, json={**_NEW_USER_BODY, "password": "s3cr3tP4ssw0rd"}, headers={"Authorization": "Bearer some-mocked-token"}) data = res.get_json() @@ -176,14 +177,14 @@ def test_create_user_endpoint_short_password_returns_400( fxtr_app, mocker, fxtr_oauth2_clients): """ GIVEN: a valid system-admin token and a request body with a short password - WHEN: POST /auth/user/create + WHEN: POST /auth/system/administration/users/create THEN: 400 is returned (password must be at least 8 characters) """ conn, clients = fxtr_oauth2_clients _setup_admin_mock(conn, clients, mocker) with fxtr_app.test_client() as http: res = http.post( - "/auth/user/create", + _CREATE_URL, json={**_NEW_USER_BODY, "password": "short"}, headers={"Authorization": "Bearer some-mocked-token"}) assert res.status_code == 400 |
