~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-04 20:44:14 UTC
  • mfrom: (5807.2.2 inventory-tree-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20110504204414-j893hspmx3k1rki4
(jelmer) Skip per_tree tests that are InventoryTree-specific if they're run
 against non-inventory trees. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

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