summaryrefslogtreecommitdiff
path: root/src/mailman/testing/helpers.py
diff options
context:
space:
mode:
authorBarry Warsaw2016-03-23 16:01:10 -0400
committerBarry Warsaw2016-03-23 16:01:10 -0400
commitab2b619db5f3de47cffc2740901c4f82958a7d96 (patch)
treebb62420bd04ebe829d91fdb4a0f0ac06344673b5 /src/mailman/testing/helpers.py
parent63fcaa68c99a0398002c1a1a752754483fa0b757 (diff)
downloadmailman-ab2b619db5f3de47cffc2740901c4f82958a7d96.tar.gz
mailman-ab2b619db5f3de47cffc2740901c4f82958a7d96.tar.zst
mailman-ab2b619db5f3de47cffc2740901c4f82958a7d96.zip
Diffstat (limited to 'src/mailman/testing/helpers.py')
-rw-r--r--src/mailman/testing/helpers.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index 631424661..e0d46cd20 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -122,12 +122,14 @@ class _Bag:
setattr(self, key, value)
-def get_queue_messages(queue_name, sort_on=None):
+def get_queue_messages(queue_name, sort_on=None, expected_count=None):
"""Return and clear all the messages in the given queue.
:param queue_name: A string naming a queue.
:param sort_on: The message header to sort on. If None (the default),
no sorting is performed.
+ :param expected_count: If given and there aren't exactly this number of
+ messages in the queue, raise an AssertionError.
:return: A list of 2-tuples where each item contains the message and
message metadata.
"""
@@ -137,6 +139,9 @@ def get_queue_messages(queue_name, sort_on=None):
msg, msgdata = queue.dequeue(filebase)
messages.append(_Bag(msg=msg, msgdata=msgdata))
queue.finish(filebase)
+ if expected_count is not None:
+ assert len(messages) == expected_count, 'Wanted {}, got {}'.format(
+ expected_count, len(messages))
if sort_on is not None:
messages.sort(key=lambda item: str(item.msg[sort_on]))
return messages