1
# Copyright (C) 2006, 2007, 2009-2012 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
51
49
out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
52
50
self.assertEquals("", out)
54
def set_branch_email(self, b, email):
55
b.get_config_stack().set('email', email)
57
52
def test_whoami_branch(self):
58
53
"""branch specific user identity works."""
59
54
wt = self.make_branch_and_tree('.')
60
55
b = bzrlib.branch.Branch.open('.')
61
self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
56
b.get_config().set_user_option('email',
57
'Branch Identity <branch@identi.ty>')
62
58
self.assertWhoAmI('Branch Identity <branch@identi.ty>')
63
59
self.assertWhoAmI('branch@identi.ty', '--email')
84
80
wt = self.make_branch_and_tree('.')
85
81
b = bzrlib.branch.Branch.open('.')
86
self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
82
b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
87
84
self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
89
86
self.assertWhoAmI('branch@identi.ty', '--email',
103
100
self.overrideEnv('EMAIL', None)
104
101
self.overrideEnv('BZR_EMAIL', None)
105
102
# Also, make sure that it's not inferred from mailname.
106
self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
103
self.overrideAttr(config, '_auto_user_id',
104
lambda: (None, None))
107
105
out, err = self.run_bzr(['whoami'], 3)
108
106
self.assertContainsRe(err, 'Unable to determine your name')
110
108
def test_whoami_directory(self):
111
109
"""Test --directory option."""
112
110
wt = self.make_branch_and_tree('subdir')
113
self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
111
c = wt.branch.get_config()
112
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
114
113
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
115
114
'--directory', 'subdir')
116
115
self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
117
116
'Changed Identity <changed@identi.ty>'])
118
# Refresh wt as 'whoami' modified it
119
wt = wt.bzrdir.open_workingtree()
120
c = wt.branch.get_config_stack()
117
c = wt.branch.get_config()
121
118
self.assertEquals('Changed Identity <changed@identi.ty>',
119
c.get_user_option('email'))
124
121
def test_whoami_remote_directory(self):
125
122
"""Test --directory option with a remote directory."""
126
123
wt = self.make_branch_and_tree('subdir')
127
self.set_branch_email(wt.branch, 'Branch Identity <branch@identi.ty>')
124
c = wt.branch.get_config()
125
c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
128
126
url = self.get_readonly_url() + '/subdir'
129
127
self.assertWhoAmI('Branch Identity <branch@identi.ty>',
130
128
'--directory', url)
133
131
'Changed Identity <changed@identi.ty>'])
134
132
# The identity has been set in the branch config (but not the global
136
c = branch.Branch.open(url).get_config_stack()
134
c = wt.branch.get_config()
137
135
self.assertEquals('Changed Identity <changed@identi.ty>',
139
# Ensuring that the value does not come from the bazaar.conf file
140
# itself requires some isolation setup
141
self.overrideEnv('BZR_EMAIL', None)
142
self.overrideEnv('EMAIL', None)
143
self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
144
global_conf = config.GlobalStack()
145
self.assertRaises(errors.NoWhoami, global_conf.get, 'email')
136
c.get_user_option('email'))
137
global_conf = config.GlobalConfig()
138
self.assertEquals(None, global_conf.get_user_option('email'))
147
140
def test_whoami_nonbranch_directory(self):
148
141
"""Test --directory mentioning a non-branch directory."""