~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/runners/tests/test_owner.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:
37
37
 
38
38
from mailman.app.lifecycle import create_list
39
39
from mailman.config import config
 
40
from mailman.database.transaction import transaction
40
41
from mailman.interfaces.member import MemberRole
41
42
from mailman.interfaces.usermanager import IUserManager
42
43
from mailman.testing.helpers import (
59
60
        self._mlist = create_list('test@example.com')
60
61
        # Add some owners, moderators, and members
61
62
        manager = getUtility(IUserManager)
62
 
        anne = manager.create_address('anne@example.com')
63
 
        bart = manager.create_address('bart@example.com')
64
 
        cris = manager.create_address('cris@example.com')
65
 
        dave = manager.create_address('dave@example.com')
66
 
        self._mlist.subscribe(anne, MemberRole.member)
67
 
        self._mlist.subscribe(anne, MemberRole.owner)
68
 
        self._mlist.subscribe(bart, MemberRole.moderator)
69
 
        self._mlist.subscribe(bart, MemberRole.owner)
70
 
        self._mlist.subscribe(cris, MemberRole.moderator)
71
 
        self._mlist.subscribe(dave, MemberRole.member)
72
 
        config.db.commit()
 
63
        with transaction():
 
64
            anne = manager.create_address('anne@example.com')
 
65
            bart = manager.create_address('bart@example.com')
 
66
            cris = manager.create_address('cris@example.com')
 
67
            dave = manager.create_address('dave@example.com')
 
68
            self._mlist.subscribe(anne, MemberRole.member)
 
69
            self._mlist.subscribe(anne, MemberRole.owner)
 
70
            self._mlist.subscribe(bart, MemberRole.moderator)
 
71
            self._mlist.subscribe(bart, MemberRole.owner)
 
72
            self._mlist.subscribe(cris, MemberRole.moderator)
 
73
            self._mlist.subscribe(dave, MemberRole.member)
73
74
        self._inq = make_testable_runner(IncomingRunner, 'in')
74
75
        self._pipelineq = make_testable_runner(PipelineRunner, 'pipeline')
75
76
        self._outq = make_testable_runner(OutgoingRunner, 'out')