summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/model/pending.py22
-rw-r--r--src/mailman/model/tests/test_pending.py29
2 files changed, 45 insertions, 6 deletions
diff --git a/src/mailman/model/pending.py b/src/mailman/model/pending.py
index 0c7ed7590..a98c9dfb8 100644
--- a/src/mailman/model/pending.py
+++ b/src/mailman/model/pending.py
@@ -35,8 +35,8 @@ from mailman.database.transaction import dbconnection
from mailman.interfaces.pending import (
IPendable, IPended, IPendedKeyValue, IPendings)
from mailman.utilities.datetime import now
-from sqlalchemy import Column, DateTime, ForeignKey, Integer, Unicode
-from sqlalchemy.orm import relationship
+from sqlalchemy import and_, Column, DateTime, ForeignKey, Integer, Unicode
+from sqlalchemy.orm import aliased, relationship
from zope.interface import implementer
from zope.interface.verify import verifyObject
@@ -157,6 +157,24 @@ class Pendings:
store.delete(pending)
@dbconnection
+ def find(self, store, mlist=None, type=None):
+ query = store.query(Pended)
+ if mlist is not None:
+ pkv_alias_mlist = aliased(PendedKeyValue)
+ query = query.join(pkv_alias_mlist).filter(and_(
+ pkv_alias_mlist.key == 'list_id',
+ pkv_alias_mlist.value == json.dumps(mlist.list_id)
+ ))
+ if type is not None:
+ pkv_alias_type = aliased(PendedKeyValue)
+ query = query.join(pkv_alias_type).filter(and_(
+ pkv_alias_type.key == 'type',
+ pkv_alias_type.value == json.dumps(type)
+ ))
+ for pending in query:
+ yield pending.token, self.confirm(pending.token, expunge=False)
+
+ @dbconnection
def __iter__(self, store):
for pending in store.query(Pended).all():
yield pending.token, self.confirm(pending.token, expunge=False)
diff --git a/src/mailman/model/tests/test_pending.py b/src/mailman/model/tests/test_pending.py
index 1884c8109..c97fdc1ce 100644
--- a/src/mailman/model/tests/test_pending.py
+++ b/src/mailman/model/tests/test_pending.py
@@ -24,11 +24,10 @@ __all__ = [
import unittest
+from mailman.app.lifecycle import create_list
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.interfaces.pending import IPendable, IPendings
+from mailman.model.pending import PendedKeyValue
from mailman.testing.layers import ConfigLayer
from zope.component import getUtility
from zope.interface import implementer
@@ -59,3 +58,25 @@ class TestPendings(unittest.TestCase):
pendable = pendingdb.confirm(token)
self.assertEqual(pendingdb.count, 0)
self.assertEqual(config.db.store.query(PendedKeyValue).count(), 0)
+
+ def test_find(self):
+ # Test getting pendables for a mailing-list
+ mlist = create_list('list1@example.com')
+ pendingdb = getUtility(IPendings)
+ subscription_1 = SimplePendable(
+ type='subscription',
+ list_id='list1.example.com')
+ subscription_2 = SimplePendable(
+ type='subscription',
+ list_id='list2.example.com')
+ subscription_3 = SimplePendable(
+ type='hold request',
+ list_id='list1.example.com')
+ token_1 = pendingdb.add(subscription_1)
+ pendingdb.add(subscription_2)
+ pendingdb.add(subscription_3)
+ self.assertEqual(pendingdb.count, 3)
+ mlist_pendings = list(pendingdb.find(mlist=mlist, type='subscription'))
+ self.assertEqual(len(mlist_pendings), 1)
+ self.assertEqual(mlist_pendings[0][0], token_1)
+ self.assertEqual(mlist_pendings[0][1]['list_id'], 'list1.example.com')