~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/rest/tests/test_lists.py

  • Committer: Barry Warsaw
  • Date: 2012-04-22 21:33:33 UTC
  • mfrom: (7150.1.11 transactions)
  • Revision ID: barry@list.org-20120422213333-3skjqsjktooesgsl
Several non-functional improvements to the code base.

Reduce the explicit use of the config.db global by introducing two new
helpers:
 - A new transaction() context manager which will commit the transaction on
   successful exit, otherwise it will abort the transaction
 - A new dbconnection decorator which calls the decorated method with the
   Storm store object as the first argument (after self).  This can be used
   instead of config.db.store.

By reducing the explicit use of this global, we have a better chance of
refactoring it away in the future.  Still TODO: runner.py and lmtp.py.

Be explicit about the `store` attribute on the IDatabase interface.

More consistent use of __future__ imports.

Remove an obsolete command line script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
from zope.component import getUtility
33
33
 
34
34
from mailman.app.lifecycle import create_list
35
 
from mailman.config import config
 
35
from mailman.database.transaction import transaction
36
36
from mailman.interfaces.usermanager import IUserManager
37
37
from mailman.testing.helpers import call_api
38
38
from mailman.testing.layers import RESTLayer
96
96
    layer = RESTLayer
97
97
 
98
98
    def setUp(self):
99
 
        self._mlist = create_list('test@example.com')
100
 
        config.db.commit()
 
99
        with transaction():
 
100
            self._mlist = create_list('test@example.com')
101
101
        self._usermanager = getUtility(IUserManager)
102
102
 
103
103
    def test_member_count_with_no_members(self):
109
109
 
110
110
    def test_member_count_with_one_member(self):
111
111
        # Add a member to a list and check that the resource reflects this.
112
 
        anne = self._usermanager.create_address('anne@example.com')
113
 
        self._mlist.subscribe(anne)
114
 
        config.db.commit()
 
112
        with transaction():
 
113
            anne = self._usermanager.create_address('anne@example.com')
 
114
            self._mlist.subscribe(anne)
115
115
        resource, response = call_api(
116
116
            'http://localhost:9001/3.0/lists/test@example.com')
117
117
        self.assertEqual(response.status, 200)
119
119
 
120
120
    def test_member_count_with_two_members(self):
121
121
        # Add two members to a list and check that the resource reflects this.
122
 
        anne = self._usermanager.create_address('anne@example.com')
123
 
        self._mlist.subscribe(anne)
124
 
        bart = self._usermanager.create_address('bar@example.com')
125
 
        self._mlist.subscribe(bart)
126
 
        config.db.commit()
 
122
        with transaction():
 
123
            anne = self._usermanager.create_address('anne@example.com')
 
124
            self._mlist.subscribe(anne)
 
125
            bart = self._usermanager.create_address('bar@example.com')
 
126
            self._mlist.subscribe(bart)
127
127
        resource, response = call_api(
128
128
            'http://localhost:9001/3.0/lists/test@example.com')
129
129
        self.assertEqual(response.status, 200)