diff options
| author | Aurélien Bompard | 2015-12-02 08:56:54 +0100 |
|---|---|---|
| committer | Barry Warsaw | 2015-12-16 11:04:25 -0500 |
| commit | e0dcdefcc55f92470a0d339ba2b5e64ae67a723d (patch) | |
| tree | 9b8ce4a651c781457d241600fd1131c1af0705d2 /src | |
| parent | 33a64ede9aa2a6b6c5ebbbbbfbf789bc4d41e3f2 (diff) | |
| download | mailman-e0dcdefcc55f92470a0d339ba2b5e64ae67a723d.tar.gz mailman-e0dcdefcc55f92470a0d339ba2b5e64ae67a723d.tar.zst mailman-e0dcdefcc55f92470a0d339ba2b5e64ae67a723d.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/model/pending.py | 10 | ||||
| -rw-r--r-- | src/mailman/model/tests/test_pending.py | 61 |
2 files changed, 62 insertions, 9 deletions
diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py index 04b63f2ca..69ac9742b 100644 --- a/src/mailman/model/pending.py +++ b/src/mailman/model/pending.py @@ -68,7 +68,7 @@ class Pended(Model): id = Column(Integer, primary_key=True) token = Column(Unicode) expiration_date = Column(DateTime) - key_values = relationship('PendedKeyValue') + key_values = relationship('PendedKeyValue', cascade="all, delete-orphan") def __init__(self, token, expiration_date): super(Pended, self).__init__() @@ -147,8 +147,6 @@ class Pendings: if isinstance(value, dict) and '__encoding__' in value: value = value['value'].encode(value['__encoding__']) pendable[keyvalue.key] = value - if expunge: - store.delete(keyvalue) if expunge: store.delete(pending) return pendable @@ -158,12 +156,6 @@ class Pendings: right_now = now() for pending in store.query(Pended).all(): if pending.expiration_date < right_now: - # Find all PendedKeyValue entries that are associated with the - # pending object's ID. - q = store.query(PendedKeyValue).filter( - PendedKeyValue.pended_id == pending.id) - for keyvalue in q: - store.delete(keyvalue) store.delete(pending) @dbconnection diff --git a/src/mailman/model/tests/test_pending.py b/src/mailman/model/tests/test_pending.py new file mode 100644 index 000000000..1884c8109 --- /dev/null +++ b/src/mailman/model/tests/test_pending.py @@ -0,0 +1,61 @@ +# Copyright (C) 2015 by the Free Software Foundation, Inc. +# +# This file is part of GNU Mailman. +# +# GNU Mailman is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# GNU Mailman. If not, see <http://www.gnu.org/licenses/>. + +"""Test pendings.""" + +__all__ = [ + 'TestPendings', + ] + + +import unittest + +from mailman.config import config +from mailman.email.validate import InvalidEmailAddressError +from mailman.interfaces.pending import ( + IPendable, IPended, IPendedKeyValue, IPendings) +from mailman.model.pending import PendedKeyValue, Pended, Pendings +from mailman.testing.layers import ConfigLayer +from zope.component import getUtility +from zope.interface import implementer + + +@implementer(IPendable) +class SimplePendable(dict): + pass + + + +class TestPendings(unittest.TestCase): + """Test pendings.""" + + layer = ConfigLayer + + def test_delete_key_values(self): + # Deleting a pending should delete its key-values + pendingdb = getUtility(IPendings) + subscription = SimplePendable( + type='subscription', + address='aperson@example.com', + display_name='Anne Person', + language='en', + password='xyz') + token = pendingdb.add(subscription) + self.assertEqual(pendingdb.count, 1) + pendable = pendingdb.confirm(token) + self.assertEqual(pendingdb.count, 0) + self.assertEqual(config.db.store.query(PendedKeyValue).count(), 0) |
