12
12
from contextlib import contextmanager
14
17
from canonical.testing.layers import LaunchpadZopelessLayer
17
21
def dbuser(temporary_name):
18
22
"""A context manager that temporarily changes the dbuser.
20
24
Use with the LaunchpadZopelessLayer layer and subclasses.
22
26
temporary_name is the name of the dbuser that should be in place for the
23
27
code in the "with" block.
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)
32
36
LaunchpadZopelessLayer.switchDbUser(restore_name)
35
40
"""A context manager that temporarily changes to the launchpad dbuser.
37
42
Use with the LaunchpadZopelessLayer layer and subclasses.
39
44
return dbuser('launchpad')