1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00
webvirtcloud/accounts/tests/test_ssh_keys.py
catborise f09a1b67f5 test(accounts): validate_ssh_key is tested in one place
test_ssh_keys repeated test_utils' cases of a key with and without a
comment and of an invalid key; test_utils keeps them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
2026-11-08 21:20:06 +03:00

22 lines
819 B
Python

"""A user's SSH keys go with the user (validate_ssh_key: test_utils)."""
from django.contrib.auth import get_user_model
from django.test import TestCase
from accounts.models import UserSSHKey
class SshKeyTestCase(TestCase):
def test_ssh_key_cascade_deletion(self):
user = get_user_model().objects.create_user(username="sec_acc_user", password="password")
key = UserSSHKey.objects.create(
user=user,
keyname="my-key",
keypublic="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGabcdef123456 test@example.com",
)
self.assertTrue(UserSSHKey.objects.filter(id=key.id).exists())
# When user is deleted, key should be deleted via CASCADE (not left orphan)
user.delete()
self.assertFalse(UserSSHKey.objects.filter(id=key.id).exists())