~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/testing/dbuser.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-09-19 23:43:35 UTC
  • mfrom: (13970.10.13 ztm-murder)
  • Revision ID: launchpad@pqm.canonical.com-20110919234335-wl2iifzeioub5uhc
[r=sinzui][no-qa] Stripped of its transaction management
 functionality,
 ZopelessTransactionManager is demoted to a mere database configuration
 manager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
from contextlib import contextmanager
13
13
 
 
14
import transaction
 
15
 
 
16
from canonical.database.sqlbase import ZopelessTransactionManager
14
17
from canonical.testing.layers import LaunchpadZopelessLayer
15
18
 
 
19
 
16
20
@contextmanager
17
21
def dbuser(temporary_name):
18
22
    """A context manager that temporarily changes the dbuser.
19
 
    
 
23
 
20
24
    Use with the LaunchpadZopelessLayer layer and subclasses.
21
 
    
 
25
 
22
26
    temporary_name is the name of the dbuser that should be in place for the
23
27
    code in the "with" block.
24
28
    """
25
 
    restore_name = LaunchpadZopelessLayer.txn._dbuser
26
 
    LaunchpadZopelessLayer.txn.commit()
 
29
    restore_name = ZopelessTransactionManager._dbuser
 
30
    transaction.commit()
27
31
    # Note that this will raise an assertion error if the
28
32
    # LaunchpadZopelessLayer is not already set up.
29
33
    LaunchpadZopelessLayer.switchDbUser(temporary_name)
30
34
    yield
31
 
    LaunchpadZopelessLayer.txn.commit()
 
35
    transaction.commit()
32
36
    LaunchpadZopelessLayer.switchDbUser(restore_name)
33
37
 
 
38
 
34
39
def lp_dbuser():
35
40
    """A context manager that temporarily changes to the launchpad dbuser.
36
 
    
 
41
 
37
42
    Use with the LaunchpadZopelessLayer layer and subclasses.
38
43
    """
39
44
    return dbuser('launchpad')