summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-22 16:18:59 -0400
committerBarry Warsaw2012-04-22 16:18:59 -0400
commitd64b2c1aa557b815fcc1277ebcf13ce52834b836 (patch)
treed10a16b6bb4236719284b6073ad307537bb9169f /src
parent0a942a671a06d65b6355b383a5d140dc93ad9587 (diff)
downloadmailman-d64b2c1aa557b815fcc1277ebcf13ce52834b836.tar.gz
mailman-d64b2c1aa557b815fcc1277ebcf13ce52834b836.tar.zst
mailman-d64b2c1aa557b815fcc1277ebcf13ce52834b836.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/archiving/tests/test_prototype.py5
-rw-r--r--src/mailman/model/tests/test_bounce.py25
-rw-r--r--src/mailman/rest/tests/test_addresses.py9
-rw-r--r--src/mailman/rest/tests/test_domains.py13
-rw-r--r--src/mailman/rest/tests/test_lists.py22
-rw-r--r--src/mailman/rest/tests/test_membership.py58
-rw-r--r--src/mailman/rest/tests/test_users.py7
-rw-r--r--src/mailman/runners/tests/test_owner.py23
8 files changed, 86 insertions, 76 deletions
diff --git a/src/mailman/archiving/tests/test_prototype.py b/src/mailman/archiving/tests/test_prototype.py
index 29f6ba1cb..bc1cee8b9 100644
--- a/src/mailman/archiving/tests/test_prototype.py
+++ b/src/mailman/archiving/tests/test_prototype.py
@@ -37,6 +37,7 @@ from flufl.lock import Lock
from mailman.app.lifecycle import create_list
from mailman.archiving.prototype import Prototype
from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.testing.helpers import LogFileMark
from mailman.testing.helpers import (
specialized_message_from_string as mfs)
@@ -61,8 +62,8 @@ X-Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW
Tests are better than no tests
but the water deserves to be swum.
""")
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
# Set up a temporary directory for the prototype archiver so that it's
# easier to clean up.
self._tempdir = tempfile.mkdtemp()
diff --git a/src/mailman/model/tests/test_bounce.py b/src/mailman/model/tests/test_bounce.py
index da2b661ea..377fab4cc 100644
--- a/src/mailman/model/tests/test_bounce.py
+++ b/src/mailman/model/tests/test_bounce.py
@@ -17,7 +17,7 @@
"""Test bounce model objects."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -30,7 +30,7 @@ from datetime import datetime
from zope.component import getUtility
from mailman.app.lifecycle import create_list
-from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.interfaces.bounce import BounceContext, IBounceProcessor
from mailman.testing.helpers import (
specialized_message_from_string as message_from_string)
@@ -52,8 +52,9 @@ Message-Id: <first>
""")
def test_events_iterator(self):
- self._processor.register(self._mlist, 'anne@example.com', self._msg)
- config.db.commit()
+ with transaction():
+ self._processor.register(
+ self._mlist, 'anne@example.com', self._msg)
events = list(self._processor.events)
self.assertEqual(len(events), 1)
event = events[0]
@@ -75,23 +76,25 @@ Message-Id: <first>
self.assertEqual(event.processed, False)
def test_unprocessed_events_iterator(self):
- self._processor.register(self._mlist, 'anne@example.com', self._msg)
- self._processor.register(self._mlist, 'bart@example.com', self._msg)
- config.db.commit()
+ with transaction():
+ self._processor.register(
+ self._mlist, 'anne@example.com', self._msg)
+ self._processor.register(
+ self._mlist, 'bart@example.com', self._msg)
events = list(self._processor.events)
self.assertEqual(len(events), 2)
unprocessed = list(self._processor.unprocessed)
# The unprocessed list will be exactly the same right now.
self.assertEqual(len(unprocessed), 2)
# Process one of the events.
- events[0].processed = True
- config.db.commit()
+ with transaction():
+ events[0].processed = True
# Now there will be only one unprocessed event.
unprocessed = list(self._processor.unprocessed)
self.assertEqual(len(unprocessed), 1)
# Process the other event.
- events[1].processed = True
- config.db.commit()
+ with transaction():
+ events[1].processed = True
# Now there will be no unprocessed events.
unprocessed = list(self._processor.unprocessed)
self.assertEqual(len(unprocessed), 0)
diff --git a/src/mailman/rest/tests/test_addresses.py b/src/mailman/rest/tests/test_addresses.py
index f4e7cab62..385b83912 100644
--- a/src/mailman/rest/tests/test_addresses.py
+++ b/src/mailman/rest/tests/test_addresses.py
@@ -17,10 +17,11 @@
"""REST address tests."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestAddresses',
]
@@ -29,7 +30,7 @@ import unittest
from urllib2 import HTTPError
from mailman.app.lifecycle import create_list
-from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
@@ -39,8 +40,8 @@ class TestAddresses(unittest.TestCase):
layer = RESTLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
def test_membership_of_missing_address(self):
# Try to get the memberships of a missing address.
diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py
index 89cc34630..a86768481 100644
--- a/src/mailman/rest/tests/test_domains.py
+++ b/src/mailman/rest/tests/test_domains.py
@@ -17,10 +17,11 @@
"""REST domain tests."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestDomains',
]
@@ -30,7 +31,7 @@ from urllib2 import HTTPError
from zope.component import getUtility
from mailman.app.lifecycle import create_list
-from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.interfaces.listmanager import IListManager
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
@@ -41,8 +42,8 @@ class TestDomains(unittest.TestCase):
layer = RESTLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
def test_bogus_endpoint_extension(self):
# /domains/<domain>/lists/<anything> is not a valid endpoint.
@@ -67,8 +68,8 @@ class TestDomains(unittest.TestCase):
def test_lists_are_deleted_when_domain_is_deleted(self):
# /domains/<domain> DELETE removes all associated mailing lists.
- create_list('ant@example.com')
- config.db.commit()
+ with transaction():
+ create_list('ant@example.com')
content, response = call_api(
'http://localhost:9001/3.0/domains/example.com', method='DELETE')
self.assertEqual(response.status, 204)
diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py
index b030a2e8d..cd0ebaf8e 100644
--- a/src/mailman/rest/tests/test_lists.py
+++ b/src/mailman/rest/tests/test_lists.py
@@ -32,7 +32,7 @@ from urllib2 import HTTPError
from zope.component import getUtility
from mailman.app.lifecycle import create_list
-from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
@@ -96,8 +96,8 @@ class TestLists(unittest.TestCase):
layer = RESTLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
self._usermanager = getUtility(IUserManager)
def test_member_count_with_no_members(self):
@@ -109,9 +109,9 @@ class TestLists(unittest.TestCase):
def test_member_count_with_one_member(self):
# Add a member to a list and check that the resource reflects this.
- anne = self._usermanager.create_address('anne@example.com')
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
resource, response = call_api(
'http://localhost:9001/3.0/lists/test@example.com')
self.assertEqual(response.status, 200)
@@ -119,11 +119,11 @@ class TestLists(unittest.TestCase):
def test_member_count_with_two_members(self):
# Add two members to a list and check that the resource reflects this.
- anne = self._usermanager.create_address('anne@example.com')
- self._mlist.subscribe(anne)
- bart = self._usermanager.create_address('bar@example.com')
- self._mlist.subscribe(bart)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
+ bart = self._usermanager.create_address('bar@example.com')
+ self._mlist.subscribe(bart)
resource, response = call_api(
'http://localhost:9001/3.0/lists/test@example.com')
self.assertEqual(response.status, 200)
diff --git a/src/mailman/rest/tests/test_membership.py b/src/mailman/rest/tests/test_membership.py
index 202e5f057..875f5e254 100644
--- a/src/mailman/rest/tests/test_membership.py
+++ b/src/mailman/rest/tests/test_membership.py
@@ -17,10 +17,11 @@
"""REST membership tests."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestMembership',
]
@@ -31,6 +32,7 @@ from zope.component import getUtility
from mailman.app.lifecycle import create_list
from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
@@ -42,8 +44,8 @@ class TestMembership(unittest.TestCase):
layer = RESTLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
self._usermanager = getUtility(IUserManager)
def test_try_to_join_missing_list(self):
@@ -85,9 +87,9 @@ class TestMembership(unittest.TestCase):
raise AssertionError('Expected HTTPError')
def test_try_to_leave_a_list_twice(self):
- anne = self._usermanager.create_address('anne@example.com')
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
url = 'http://localhost:9001/3.0/members/1'
content, response = call_api(url, method='DELETE')
# For a successful DELETE, the response code is 204 and there is no
@@ -104,9 +106,9 @@ class TestMembership(unittest.TestCase):
raise AssertionError('Expected HTTPError')
def test_try_to_join_a_list_twice(self):
- anne = self._usermanager.create_address('anne@example.com')
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
try:
# For Python 2.6.
call_api('http://localhost:9001/3.0/members', {
@@ -151,12 +153,12 @@ class TestMembership(unittest.TestCase):
self.assertEqual(members[0].address.email, 'hugh/person@example.com')
def test_join_as_user_with_preferred_address(self):
- anne = self._usermanager.create_user('anne@example.com')
- preferred = list(anne.addresses)[0]
- preferred.verified_on = now()
- anne.preferred_address = preferred
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_user('anne@example.com')
+ preferred = list(anne.addresses)[0]
+ preferred.verified_on = now()
+ anne.preferred_address = preferred
+ self._mlist.subscribe(anne)
content, response = call_api('http://localhost:9001/3.0/members')
self.assertEqual(response.status, 200)
self.assertEqual(int(content['total_size']), 1)
@@ -169,12 +171,12 @@ class TestMembership(unittest.TestCase):
self.assertEqual(entry_0['fqdn_listname'], 'test@example.com')
def test_member_changes_preferred_address(self):
- anne = self._usermanager.create_user('anne@example.com')
- preferred = list(anne.addresses)[0]
- preferred.verified_on = now()
- anne.preferred_address = preferred
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_user('anne@example.com')
+ preferred = list(anne.addresses)[0]
+ preferred.verified_on = now()
+ anne.preferred_address = preferred
+ self._mlist.subscribe(anne)
# Take a look at Anne's current membership.
content, response = call_api('http://localhost:9001/3.0/members')
self.assertEqual(int(content['total_size']), 1)
@@ -182,10 +184,10 @@ class TestMembership(unittest.TestCase):
self.assertEqual(entry_0['address'], 'anne@example.com')
# Anne registers a new address and makes it her preferred address.
# There are no changes to her membership.
- new_preferred = anne.register('aperson@example.com')
- new_preferred.verified_on = now()
- anne.preferred_address = new_preferred
- config.db.commit()
+ with transaction():
+ new_preferred = anne.register('aperson@example.com')
+ new_preferred.verified_on = now()
+ anne.preferred_address = new_preferred
# Take another look at Anne's current membership.
content, response = call_api('http://localhost:9001/3.0/members')
self.assertEqual(int(content['total_size']), 1)
@@ -214,9 +216,9 @@ class TestMembership(unittest.TestCase):
def test_patch_member_bogus_attribute(self):
# /members/<id> PATCH 'bogus' returns 400
- anne = self._usermanager.create_address('anne@example.com')
- self._mlist.subscribe(anne)
- config.db.commit()
+ with transaction():
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
try:
# For Python 2.6
call_api('http://localhost:9001/3.0/members/1', {
diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py
index 1630eb96a..301027885 100644
--- a/src/mailman/rest/tests/test_users.py
+++ b/src/mailman/rest/tests/test_users.py
@@ -21,6 +21,7 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestUsers',
]
@@ -29,7 +30,7 @@ import unittest
from urllib2 import HTTPError
from mailman.app.lifecycle import create_list
-from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
@@ -39,8 +40,8 @@ class TestUsers(unittest.TestCase):
layer = RESTLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
- config.db.commit()
+ with transaction():
+ self._mlist = create_list('test@example.com')
def test_delete_bogus_user(self):
# Try to delete a user that does not exist.
diff --git a/src/mailman/runners/tests/test_owner.py b/src/mailman/runners/tests/test_owner.py
index 622bb2255..4ea5771be 100644
--- a/src/mailman/runners/tests/test_owner.py
+++ b/src/mailman/runners/tests/test_owner.py
@@ -37,6 +37,7 @@ from zope.component import getUtility
from mailman.app.lifecycle import create_list
from mailman.config import config
+from mailman.database.transaction import transaction
from mailman.interfaces.member import MemberRole
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import (
@@ -59,17 +60,17 @@ class TestEmailToOwner(unittest.TestCase):
self._mlist = create_list('test@example.com')
# Add some owners, moderators, and members
manager = getUtility(IUserManager)
- anne = manager.create_address('anne@example.com')
- bart = manager.create_address('bart@example.com')
- cris = manager.create_address('cris@example.com')
- dave = manager.create_address('dave@example.com')
- self._mlist.subscribe(anne, MemberRole.member)
- self._mlist.subscribe(anne, MemberRole.owner)
- self._mlist.subscribe(bart, MemberRole.moderator)
- self._mlist.subscribe(bart, MemberRole.owner)
- self._mlist.subscribe(cris, MemberRole.moderator)
- self._mlist.subscribe(dave, MemberRole.member)
- config.db.commit()
+ with transaction():
+ anne = manager.create_address('anne@example.com')
+ bart = manager.create_address('bart@example.com')
+ cris = manager.create_address('cris@example.com')
+ dave = manager.create_address('dave@example.com')
+ self._mlist.subscribe(anne, MemberRole.member)
+ self._mlist.subscribe(anne, MemberRole.owner)
+ self._mlist.subscribe(bart, MemberRole.moderator)
+ self._mlist.subscribe(bart, MemberRole.owner)
+ self._mlist.subscribe(cris, MemberRole.moderator)
+ self._mlist.subscribe(dave, MemberRole.member)
self._inq = make_testable_runner(IncomingRunner, 'in')
self._pipelineq = make_testable_runner(PipelineRunner, 'pipeline')
self._outq = make_testable_runner(OutgoingRunner, 'out')