Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 26f1310b by Barry Warsaw at 2016-04-29T09:39:16-04:00 Restore a test from !151 which only fails on PostgreSQL. For now, *deliberately* cause the test to fail. I want to prove this correctly addresses the issue on the GL CI. Once I've done that, I'll restore the patch and approve the new MR. - - - - - d8e179ec by Barry Warsaw at 2016-04-29T10:05:25-04:00 Restore a test from !151 which only fails on PostgreSQL. - - - - - 8ba39842 by Barry Warsaw at 2016-04-29T10:05:45-04:00 Merge branch 'mr151-pgtest' of gitlab.com:warsaw/mailman into mr151-pgtest - - - - - 63375f10 by Barry Warsaw at 2016-04-29T10:07:17-04:00 Restore the fix for PostgreSQL. - - - - - 1 changed file: - src/mailman/model/tests/test_requests.py Changes: ===================================== src/mailman/model/tests/test_requests.py ===================================== --- a/src/mailman/model/tests/test_requests.py +++ b/src/mailman/model/tests/test_requests.py @@ -19,11 +19,25 @@ import unittest +from contextlib import contextmanager +from itertools import count from mailman.app.lifecycle import create_list from mailman.app.moderator import hold_message +from mailman.config import config from mailman.interfaces.requests import IListRequests, RequestType +from mailman.model.requests import _Request from mailman.testing.helpers import specialized_message_from_string as mfs from mailman.testing.layers import ConfigLayer +from sqlalchemy.event import listen, remove + + +@contextmanager +def before_flush(id_hacker): + listen(config.db.store, 'before_flush', id_hacker) + try: + yield + finally: + remove(config.db.store, 'before_flush', id_hacker) class TestRequests(unittest.TestCase): @@ -75,3 +89,33 @@ Something else. request_id = hold_message(self._mlist, self._msg) bee = create_list('b...@example.com') self.assertIsNone(IListRequests(bee).get_request(request_id)) + + def test_request_order(self): + # Requests must be sorted in creation order. + # + # This test only "works" for PostgreSQL, in the sense that if you + # remove the fix in ../requests.py, it will still pass in SQLite. + # Apparently SQLite auto-sorts results by ID but PostgreSQL autosorts + # by insertion time. It's still worth keeping the test to prevent + # regressions. + # + # We modify the auto-incremented ids by listening to SQLAlchemy's + # flush event, and hacking all the _Request object id's to the next + # value in a descending counter. + request_ids = [] + counter = count(200, -1) + def id_hacker(session, flush_context, instances): # noqa + for instance in session.new: + if isinstance(instance, _Request): + instance.id = next(counter) + with before_flush(id_hacker): + for index in range(10): + msg = mfs(self._msg.as_string()) + msg.replace_header('Message-ID', '<alpha{}>'.format(index)) + request_ids.append(hold_message(self._mlist, msg)) + config.db.store.flush() + # Make sure that our ID are not already sorted. + self.assertNotEqual(request_ids, sorted(request_ids)) + # Get requests and check their order. + requests = self._requests_db.of_type(RequestType.held_message) + self.assertEqual([r.id for r in requests], sorted(request_ids)) View it on GitLab: https://gitlab.com/mailman/mailman/compare/78d1f5918d2ec0b2351edb3ed005d5b8f7e4319c...63375f10b530a5e573c9aff82cd351de5a1b4dc1
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org