~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_whoami.py

  • Committer: Patch Queue Manager
  • Date: 2012-02-14 18:29:43 UTC
  • mfrom: (6404.6.11 cached-branch-store)
  • Revision ID: pqm@pqm.ubuntu.com-20120214182943-vso6j0mqdnxfkp7s
(vila) Cache the branch config store to avoid useless IOs. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
 
22
    branch,
22
23
    config,
23
24
    errors,
24
25
    tests,
50
51
        out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
51
52
        self.assertEquals("", out)
52
53
 
 
54
    def set_branch_email(self, b, email):
 
55
        b.get_config_stack().set('email', email)
 
56
 
53
57
    def test_whoami_branch(self):
54
58
        """branch specific user identity works."""
55
59
        wt = self.make_branch_and_tree('.')
56
60
        b = bzrlib.branch.Branch.open('.')
57
 
        b.get_config_stack().set('email', 'Branch Identity <branch@identi.ty>')
 
61
        self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
58
62
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
59
63
        self.assertWhoAmI('branch@identi.ty', '--email')
60
64
 
79
83
        """
80
84
        wt = self.make_branch_and_tree('.')
81
85
        b = bzrlib.branch.Branch.open('.')
82
 
        b.get_config_stack().set(
83
 
            'email', u'Branch Identity \u20ac ' + '<branch@identi.ty>')
 
86
        self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
84
87
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
85
88
                          encoding='ascii')
86
89
        self.assertWhoAmI('branch@identi.ty', '--email',
100
103
        self.overrideEnv('EMAIL', None)
101
104
        self.overrideEnv('BZR_EMAIL', None)
102
105
        # Also, make sure that it's not inferred from mailname.
103
 
        self.overrideAttr(config, '_auto_user_id',
104
 
            lambda: (None, None))
 
106
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
105
107
        out, err = self.run_bzr(['whoami'], 3)
106
108
        self.assertContainsRe(err, 'Unable to determine your name')
107
109
 
108
110
    def test_whoami_directory(self):
109
111
        """Test --directory option."""
110
112
        wt = self.make_branch_and_tree('subdir')
111
 
        c = wt.branch.get_config_stack()
112
 
        c.set('email', 'Branch Identity <branch@identi.ty>')
 
113
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
113
114
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
114
115
                          '--directory', 'subdir')
115
116
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
116
117
                      'Changed Identity <changed@identi.ty>'])
 
118
        # Refresh wt as 'whoami' modified it
 
119
        wt = wt.bzrdir.open_workingtree()
117
120
        c = wt.branch.get_config_stack()
118
121
        self.assertEquals('Changed Identity <changed@identi.ty>',
119
122
                          c.get('email'))
121
124
    def test_whoami_remote_directory(self):
122
125
        """Test --directory option with a remote directory."""
123
126
        wt = self.make_branch_and_tree('subdir')
124
 
        c = wt.branch.get_config_stack()
125
 
        c.set('email', 'Branch Identity <branch@identi.ty>')
 
127
        self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
126
128
        url = self.get_readonly_url() + '/subdir'
127
129
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
128
130
                          '--directory', url)
131
133
                      'Changed Identity <changed@identi.ty>'])
132
134
        # The identity has been set in the branch config (but not the global
133
135
        # config)
134
 
        c = wt.branch.get_config_stack()
 
136
        c = branch.Branch.open(url).get_config_stack()
135
137
        self.assertEquals('Changed Identity <changed@identi.ty>',
136
138
                          c.get('email'))
137
139
        # Ensuring that the value does not come from the bazaar.conf file