~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/codehosting/scanner/tests/test_bzrsync.py

  • Committer: Jeroen Vermeulen
  • Date: 2011-09-26 07:21:53 UTC
  • mfrom: (14031 devel)
  • mto: This revision was merged to the branch mainline in revision 14049.
  • Revision ID: jeroen.vermeulen@canonical.com-20110926072153-0lj7d2924rf5xpoc
Merge devel, resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
#
3
 
# Copyright 2009-2010 Canonical Ltd.  This software is licensed under the
 
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
5
 
6
6
# pylint: disable-msg=W0141
24
24
from zope.security.proxy import removeSecurityProxy
25
25
 
26
26
from canonical.config import config
27
 
from canonical.database.sqlbase import ZopelessTransactionManager
28
27
from canonical.launchpad.interfaces.lpstorm import IStore
29
28
from canonical.testing.layers import LaunchpadZopelessLayer
30
29
from lp.code.interfaces.branchjob import IRosettaUploadJobSource
45
44
    read_locked,
46
45
    write_locked,
47
46
    )
48
 
from lp.codehosting.safe_open import (
49
 
    SafeBranchOpener,
50
 
    )
 
47
from lp.codehosting.safe_open import SafeBranchOpener
51
48
from lp.codehosting.scanner.bzrsync import BzrSync
52
49
from lp.services.osutils import override_environ
53
50
from lp.testing import (
54
51
    temp_dir,
55
52
    TestCaseWithFactory,
56
53
    )
 
54
from lp.testing.dbuser import dbuser
57
55
from lp.translations.interfaces.translations import (
58
56
    TranslationsBranchImportMode,
59
57
    )
66
64
    def _run_with_different_user(f):
67
65
 
68
66
        def decorated(*args, **kwargs):
69
 
            current_user = ZopelessTransactionManager._dbuser
70
 
            if current_user == username:
71
 
                return f(*args, **kwargs)
72
 
            LaunchpadZopelessLayer.switchDbUser(username)
73
 
            try:
74
 
                return f(*args, **kwargs)
75
 
            finally:
76
 
                LaunchpadZopelessLayer.switchDbUser(current_user)
 
67
            with dbuser(username):
 
68
                return f(*args, **kwargs)
77
69
        return mergeFunctionMetadata(f, decorated)
78
70
 
79
71
    return _run_with_different_user