~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Black-box tests for bzr whoami."""
19
19
 
20
 
import os
21
 
 
22
20
import bzrlib
23
21
from bzrlib import (
24
 
    osutils,
25
22
    config,
 
23
    tests,
26
24
    )
27
 
from bzrlib.tests import TestCaseWithTransport
28
 
 
29
 
 
30
 
class TestWhoami(TestCaseWithTransport):
31
 
 
32
 
    def test_whoami(self):
 
25
 
 
26
 
 
27
class TestWhoami(tests.TestCaseWithTransport):
 
28
 
 
29
    def assertWhoAmI(self, expected, *cmd_args, **kwargs):
 
30
        out, err = self.run_bzr(('whoami',) + cmd_args, **kwargs)
 
31
        self.assertEquals('', err)
 
32
        lines = out.splitlines()
 
33
        self.assertLength(1, lines)
 
34
        self.assertEquals(expected, lines[0].rstrip())
 
35
 
 
36
    def test_whoami_no_args_no_conf(self):
33
37
        # this should always identify something, if only "john@localhost"
34
38
        out = self.run_bzr("whoami")[0]
35
39
        self.assertTrue(len(out) > 0)
36
40
        self.assertEquals(1, out.count('@'))
37
41
 
 
42
    def test_whoami_email_no_args(self):
38
43
        out = self.run_bzr("whoami --email")[0]
39
44
        self.assertTrue(len(out) > 0)
40
45
        self.assertEquals(1, out.count('@'))
41
46
 
 
47
    def test_whoami_email_arg(self):
 
48
        # whoami --email is mutually exclusive with any arguments
 
49
        out = self.run_bzr("whoami --email 'foo <foo@example.com>'", 3)[0]
 
50
        self.assertEquals("", out)
 
51
 
42
52
    def test_whoami_branch(self):
43
53
        """branch specific user identity works."""
44
54
        wt = self.make_branch_and_tree('.')
45
55
        b = bzrlib.branch.Branch.open('.')
46
56
        b.get_config().set_user_option('email',
47
57
                                       'Branch Identity <branch@identi.ty>')
48
 
        whoami = self.run_bzr("whoami")[0]
49
 
        self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
50
 
        whoami_email = self.run_bzr("whoami --email")[0]
51
 
        self.assertEquals('branch@identi.ty\n', whoami_email)
 
58
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
 
59
        self.assertWhoAmI('branch@identi.ty', '--email')
52
60
 
53
61
        # Verify that the environment variable overrides the value
54
62
        # in the file
55
63
        self.overrideEnv('BZR_EMAIL', 'Different ID <other@environ.ment>')
56
 
        whoami = self.run_bzr("whoami")[0]
57
 
        self.assertEquals('Different ID <other@environ.ment>\n', whoami)
58
 
        whoami_email = self.run_bzr("whoami --email")[0]
59
 
        self.assertEquals('other@environ.ment\n', whoami_email)
 
64
        self.assertWhoAmI('Different ID <other@environ.ment>')
 
65
        self.assertWhoAmI('other@environ.ment', '--email')
60
66
 
61
67
    def test_whoami_utf8(self):
62
68
        """verify that an identity can be in utf-8."""
63
 
        wt = self.make_branch_and_tree('.')
64
69
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
65
70
                     encoding='utf-8')
66
 
        whoami = self.run_bzr("whoami", encoding='utf-8')[0]
67
 
        self.assertEquals('Branch Identity \xe2\x82\xac ' +
68
 
                          '<branch@identi.ty>\n', whoami)
69
 
        whoami_email = self.run_bzr("whoami --email", encoding='utf-8')[0]
70
 
        self.assertEquals('branch@identi.ty\n', whoami_email)
 
71
        self.assertWhoAmI('Branch Identity \xe2\x82\xac <branch@identi.ty>',
 
72
                          encoding='utf-8')
 
73
        self.assertWhoAmI('branch@identi.ty', '--email')
71
74
 
72
75
    def test_whoami_ascii(self):
73
76
        """
78
81
        b = bzrlib.branch.Branch.open('.')
79
82
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
80
83
                                       '<branch@identi.ty>')
81
 
        whoami = self.run_bzr("whoami", encoding='ascii')[0]
82
 
        self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
83
 
        whoami_email = self.run_bzr("whoami --email", encoding='ascii')[0]
84
 
        self.assertEquals('branch@identi.ty\n', whoami_email)
 
84
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
 
85
                          encoding='ascii')
 
86
        self.assertWhoAmI('branch@identi.ty', '--email',
 
87
                          encoding='ascii')
85
88
 
86
89
    def test_warning(self):
87
90
        """verify that a warning is displayed if no email is given."""
107
110
        wt = self.make_branch_and_tree('subdir')
108
111
        c = wt.branch.get_config()
109
112
        c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
110
 
        out, err = self.run_bzr("whoami --directory subdir")
111
 
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
 
113
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
 
114
                          '--directory', 'subdir')
112
115
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
113
116
                      'Changed Identity <changed@identi.ty>'])
 
117
        c = wt.branch.get_config()
114
118
        self.assertEquals('Changed Identity <changed@identi.ty>',
115
119
                          c.get_user_option('email'))
116
120
 
120
124
        c = wt.branch.get_config()
121
125
        c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
122
126
        url = self.get_readonly_url() + '/subdir'
123
 
        out, err = self.run_bzr(['whoami', '--directory', url])
124
 
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
 
127
        self.assertWhoAmI('Branch Identity <branch@identi.ty>',
 
128
                          '--directory', url)
125
129
        url = self.get_url('subdir')
126
130
        self.run_bzr(['whoami', '--directory', url, '--branch',
127
131
                      'Changed Identity <changed@identi.ty>'])
128
132
        # The identity has been set in the branch config (but not the global
129
133
        # config)
 
134
        c = wt.branch.get_config()
130
135
        self.assertEquals('Changed Identity <changed@identi.ty>',
131
136
                          c.get_user_option('email'))
132
137
        global_conf = config.GlobalConfig()