about summary refs log tree commit diff
path: root/tests/unit
diff options
context:
space:
mode:
authorClaude2026-08-26 14:53:18 +0000
committerFrederick Muriuki Muriithi2026-08-26 10:15:06 -0500
commit04e3c7243e4754097749f88051d1589d75ed1cbf (patch)
tree651a985a80a5cd8102c19278bb5fbd906a5f44db /tests/unit
parentcc9368ed3da150728e970667602147f46e1692a9 (diff)
downloadgn-auth-04e3c7243e4754097749f88051d1589d75ed1cbf.tar.gz
test(admin/users): unit tests for create_verified_user model function
Two unit tests for the (not yet implemented) create_verified_user function
in gn_auth.auth.authorisation.users.admin.models:

* test_create_verified_user_sets_verified_flag — asserts user.verified is
  True and the flag is persisted in the DB
* test_create_verified_user_has_no_roles — asserts no roles are assigned
  to the newly created user

Both tests use conn_after_auth_migrations to run against a fully migrated
SQLite test database.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reviewed-By: Frederick M. Muriithi <fredmanglis@gmail.com>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/auth/test_admin_users.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unit/auth/test_admin_users.py b/tests/unit/auth/test_admin_users.py
new file mode 100644
index 0000000..f08bedd
--- /dev/null
+++ b/tests/unit/auth/test_admin_users.py
@@ -0,0 +1,40 @@
+"""Unit tests for admin user-management model functions."""
+import pytest
+
+from gn_auth.auth.db import sqlite3 as db
+from gn_auth.auth.authorisation.users.admin.models import create_verified_user
+
+
+@pytest.mark.unit_test
+def test_create_verified_user_sets_verified_flag(conn_after_auth_migrations):
+    """
+    GIVEN: a database with migrations applied
+    WHEN: create_verified_user is called with valid email, name and password
+    THEN: the returned user has verified=True and the flag is persisted in the DB
+    """
+    conn = conn_after_auth_migrations
+    user = create_verified_user(conn, "new@example.org", "New User", "s3cr3t")
+    assert user.verified is True
+    with db.cursor(conn) as cursor:
+        cursor.execute(
+            "SELECT verified FROM users WHERE user_id=?", (str(user.user_id),))
+        row = cursor.fetchone()
+    assert row is not None
+    assert bool(row["verified"]) is True
+
+
+@pytest.mark.unit_test
+def test_create_verified_user_has_no_roles(conn_after_auth_migrations):
+    """
+    GIVEN: a database with migrations applied
+    WHEN: create_verified_user is called with valid email, name and password
+    THEN: the new user is assigned no roles
+    """
+    conn = conn_after_auth_migrations
+    user = create_verified_user(conn, "noroles@example.org", "No Roles User", "s3cr3t")
+    with db.cursor(conn) as cursor:
+        cursor.execute(
+            "SELECT COUNT(*) AS cnt FROM user_roles WHERE user_id=?",
+            (str(user.user_id),))
+        row = cursor.fetchone()
+    assert row["cnt"] == 0