~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 Canonical Ltd
2
2
#
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
19
19
 
20
20
import bzrlib
21
21
from bzrlib import (
 
22
    branch,
22
23
    config,
 
24
    errors,
23
25
    tests,
24
26
    )
25
27
 
28
30
 
29
31
    def assertWhoAmI(self, expected, *cmd_args, **kwargs):
30
32
        out, err = self.run_bzr(('whoami',) + cmd_args, **kwargs)
31
 
        self.assertEquals('', err)
 
33
        self.assertEqual('', err)
32
34
        lines = out.splitlines()
33
35
        self.assertLength(1, lines)
34
 
        self.assertEquals(expected, lines[0].rstrip())
 
36
        self.assertEqual(expected, lines[0].rstrip())
35
37
 
36
38
    def test_whoami_no_args_no_conf(self):
37
39
        # this should always identify something, if only "john@localhost"
38
40
        out = self.run_bzr("whoami")[0]
39
41
        self.assertTrue(len(out) > 0)
40
 
        self.assertEquals(1, out.count('@'))
 
42
        self.assertEqual(1, out.count('@'))
41
43
 
42
44
    def test_whoami_email_no_args(self):
43
45
        out = self.run_bzr("whoami --email")[0]
44
46
        self.assertTrue(len(out) > 0)
45
 
        self.assertEquals(1, out.count('@'))
 
47
        self.assertEqual(1, out.count('@'))
46
48
 
47
49
    def test_whoami_email_arg(self):
48
50
        # whoami --email is mutually exclusive with any arguments
49
51
        out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
50
 
        self.assertEquals("", out)
 
52
        self.assertEqual("", out)
 
53
 
 
54
    def set_branch_email(self, b, email):
 
55
        b.get_config_stack().set('email', email)
51
56
 
52
57
    def test_whoami_branch(self):
53
58
        """branch specific user identity works."""
54
59
        wt = self.make_branch_and_tree('.')
55
60
        b = bzrlib.branch.Branch.open('.')
56
 
        b.get_config().set_user_option('email',
57
 
                                       '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().set_user_option('email', u'Branch Identity \u20ac ' +
83
 
                                       '<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',
90
93
        """verify that a warning is displayed if no email is given."""
91
94
        self.make_branch_and_tree('.')
92
95
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
93
 
        self.assertEquals('"Branch Identity" does not seem to contain an '
 
96
        self.assertEqual('"Branch Identity" does not seem to contain an '
94
97
                          'email address.  This is allowed, but not '
95
98
                          'recommended.\n', display)
96
99
 
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()
112
 
        c.set_user_option('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>'])
117
 
        c = wt.branch.get_config()
118
 
        self.assertEquals('Changed Identity <changed@identi.ty>',
119
 
                          c.get_user_option('email'))
 
118
        # Refresh wt as 'whoami' modified it
 
119
        wt = wt.bzrdir.open_workingtree()
 
120
        c = wt.branch.get_config_stack()
 
121
        self.assertEqual('Changed Identity <changed@identi.ty>',
 
122
                          c.get('email'))
120
123
 
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()
125
 
        c.set_user_option('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()
135
 
        self.assertEquals('Changed Identity <changed@identi.ty>',
136
 
                          c.get_user_option('email'))
137
 
        global_conf = config.GlobalConfig()
138
 
        self.assertEquals(None, global_conf.get_user_option('email'))
 
136
        c = branch.Branch.open(url).get_config_stack()
 
137
        self.assertEqual('Changed Identity <changed@identi.ty>',
 
138
                          c.get('email'))
 
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')
139
146
 
140
147
    def test_whoami_nonbranch_directory(self):
141
148
        """Test --directory mentioning a non-branch directory."""