From 81a05757c04f26961b71b32c7c7e41419ce811f2 Mon Sep 17 00:00:00 2001 From: Lukas Juhrich Date: Wed, 10 Jul 2024 16:49:50 +0200 Subject: [PATCH] Add missing test cases --- tests/model/test_unix_tombstone.py | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/model/test_unix_tombstone.py b/tests/model/test_unix_tombstone.py index 514895fd8..e39e3b598 100644 --- a/tests/model/test_unix_tombstone.py +++ b/tests/model/test_unix_tombstone.py @@ -11,7 +11,7 @@ from sqlalchemy.orm import Session from pycroft.model.user import User -from pycroft.model.unix_account import UnixTombstone +from pycroft.model.unix_account import UnixTombstone, UnixAccount from tests import factories as f @@ -182,6 +182,38 @@ def test_user_deletion(self, session, user): assert inspect(user).deleted, "user did not get deleted" assert inspect(ua).deleted, "unix_account did not get deleted" + def test_user_change_unix_account(self, session, user): + with pytest.raises(IntegrityError), session.begin_nested(): + ua = f.UnixAccountFactory() + user.unix_account = ua + session.add(user) + + +class TestUserNoUnixAccount: + @pytest.fixture(scope="class") + def user(self, class_session) -> User: + user = f.UserFactory() + class_session.flush() + return user + + def test_create_unix_account(self, session, user): + with session.begin_nested(): + ua = f.UnixAccountFactory() + user.unix_account = ua + session.add(user) + + +class TestUnixAccountNoUser: + @pytest.fixture(scope="class") + def unix_account(self, class_session) -> UnixAccount: + ua = f.UnixAccountFactory() + class_session.flush() + return ua + + def test_create_user(self, session, ua): + with pytest.raises(IntegrityError), session.begin_nested(): + session.add(f.UserFactory(unix_account=ua)) + class TestTombstoneLifeCycle: @pytest.fixture(scope="class")