1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-09 19:52:16 +00:00

Fix FK errors when deleting a user

This commit is contained in:
Alban Féron 2023-01-15 16:04:37 +01:00
parent 724f04726e
commit ad688a23c3
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
2 changed files with 5 additions and 2 deletions

View File

@ -37,12 +37,12 @@ class UserManager:
@staticmethod
def delete(uid):
user = UserManager.get(uid)
user.delete_instance()
user.delete_instance(recursive=True)
@staticmethod
def delete_by_name(name):
user = User.get(name=name)
user.delete_instance()
user.delete_instance(recursive=True)
@staticmethod
def try_auth(name, password):

View File

@ -104,6 +104,7 @@ class UserManagerTestCase(unittest.TestCase):
# Delete existing users
for name in ["alice", "bob", "charlie"]:
user = db.User.get(name=name)
db.ClientPrefs.create(user=user, client_name="tests") # test for FK handling
UserManager.delete(user.id)
self.assertRaises(db.User.DoesNotExist, db.User.__getitem__, user.id)
self.assertEqual(db.User.select().count(), 0)
@ -113,6 +114,8 @@ class UserManagerTestCase(unittest.TestCase):
# Delete existing users
for name in ["alice", "bob", "charlie"]:
user = db.User.get(name=name)
db.ClientPrefs.create(user=user, client_name="tests") # test for FK handling
UserManager.delete_by_name(name)
self.assertFalse(db.User.select().where(db.User.name == name).exists())