Skip to content

Commit

Permalink
Add test_unit_user_settings.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Sep 18, 2024
1 parent f0b8d93 commit 28d16cd
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions tests/no_version/test_unit_user_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from devtools import debug

from fractal_server.app.models import UserOAuth
from fractal_server.app.models import UserSettings


async def test_unit_link_user_to_settings(db):
# User with no settings
user_A = UserOAuth(
email="a@a.a",
hashed_password="xxx",
is_active=True,
is_superuser=False,
is_verified=True,
)
db.add(user_A)
await db.commit()
await db.refresh(user_A)
debug(user_A)
assert user_A.settings is None
assert user_A.user_settings_id is None

# User associated to settings after its initial creation
user_settings_1 = UserSettings(ssh_host="127.0.0.1")
db.add(user_settings_1)
await db.commit()
await db.refresh(user_settings_1)
debug(user_settings_1)

user_B = UserOAuth(
email="b@b.b",
hashed_password="xxx",
is_active=True,
is_superuser=False,
is_verified=True,
user_settings_id=user_settings_1.id,
)
db.add(user_B)
await db.commit()
await db.refresh(user_B)
debug(user_B)

assert user_B.settings is not None
assert user_B.user_settings_id is not None

# User associated to settings upon its initial creation
user_settings_2 = UserSettings(ssh_host="127.0.0.1")
user_C = UserOAuth(
email="c@c.c",
hashed_password="xxx",
is_active=True,
is_superuser=False,
is_verified=True,
settings=user_settings_2,
)
db.add(user_C)
await db.commit()
await db.refresh(user_C)
debug(user_C)
assert user_C.settings is not None
assert user_C.user_settings_id is not None

# FIXME: Test delete cascade

0 comments on commit 28d16cd

Please sign in to comment.