=== modified file 'src/mailman/model/usermanager.py' --- src/mailman/model/usermanager.py 2015-02-06 03:04:45 +0000 +++ src/mailman/model/usermanager.py 2015-03-20 13:41:37 +0000 @@ -49,6 +49,7 @@ @dbconnection def delete_user(self, store, user): """See `IUserManager`.""" + store.delete(user.preferences) store.delete(user) @dbconnection === modified file 'src/mailman/rest/tests/test_users.py' --- src/mailman/rest/tests/test_users.py 2015-02-10 00:41:46 +0000 +++ src/mailman/rest/tests/test_users.py 2015-03-20 13:41:08 +0000 @@ -36,6 +36,7 @@ from mailman.testing.layers import RESTLayer from urllib.error import HTTPError from zope.component import getUtility +from mailman.model.preferences import Preferences @@ -46,6 +47,24 @@ with transaction(): self._mlist = create_list('test@example.com') + def test_preferences_deletion_on_user_deletion(self): + #deleting a user should also delete her preferences + with transaction(): + anne = getUtility(IUserManager).create_user( + 'anne@example.com', 'Anne Person') + preferences_id=anne.preferences.id + #preferences should be there in the table + preferences_before_deletion=config.db.store.query(Preferences).filter_by(id=preferences_id) + self.assertEqual(preferences_before_deletion.count(), 1) + #delete the user + content, response = call_api( + 'http://localhost:9001/3.0/users/anne@example.com', + method='DELETE') + self.assertEqual(response.status, 204) + #the corresponding prefernces must no longer exist + preferences_after_deletion=config.db.store.query(Preferences).filter_by(id=preferences_id) + self.assertEqual(preferences_after_deletion.count(), 0) + def test_get_missing_user_by_id(self): # You can't GET a missing user by user id. with self.assertRaises(HTTPError) as cm: === modified file 'src/mailman/rest/users.py' --- src/mailman/rest/users.py 2015-02-10 00:41:46 +0000 +++ src/mailman/rest/users.py 2015-03-19 05:29:11 +0000 @@ -185,7 +185,7 @@ return UserAddresses(self._user) def on_delete(self, request, response): - """Delete the named user, all her memberships, and addresses.""" + """Delete the named user, all her memberships, addresses and preferences.""" if self._user is None: not_found(response) return