Commit e0dcdefc authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Barry Warsaw

Use the relationship cascade feature to delete key-values

parent 33a64ede
......@@ -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
......
# 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='[email protected]',
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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment