/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2020-05-06 02:13:25 UTC
  • mfrom: (7490.7.21 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200506021325-awbmmqu1zyorz7sj
Merge 3.1 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Black-box tests for brz whoami."""
19
19
 
20
 
import breezy
21
20
from breezy import (
22
21
    branch,
23
22
    config,
25
24
    tests,
26
25
    )
27
26
 
 
27
from ..test_bedding import override_whoami
 
28
 
28
29
 
29
30
class TestWhoami(tests.TestCaseWithTransport):
30
31
 
33
34
        self.assertEqual('', err)
34
35
        lines = out.splitlines()
35
36
        self.assertLength(1, lines)
 
37
        if isinstance(expected, bytes):
 
38
            expected = expected.decode(kwargs.get('encoding', 'ascii'))
36
39
        self.assertEqual(expected, lines[0].rstrip())
37
40
 
38
41
    def test_whoami_no_args_no_conf(self):
57
60
    def test_whoami_branch(self):
58
61
        """branch specific user identity works."""
59
62
        wt = self.make_branch_and_tree('.')
60
 
        b = breezy.branch.Branch.open('.')
 
63
        b = branch.Branch.open('.')
61
64
        self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
62
65
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
63
66
        self.assertWhoAmI('branch@identi.ty', '--email')
72
75
        """verify that an identity can be in utf-8."""
73
76
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
74
77
                     encoding='utf-8')
75
 
        self.assertWhoAmI('Branch Identity \xe2\x82\xac <branch@identi.ty>',
 
78
        self.assertWhoAmI(b'Branch Identity \xe2\x82\xac <branch@identi.ty>',
76
79
                          encoding='utf-8')
77
80
        self.assertWhoAmI('branch@identi.ty', '--email')
78
81
 
82
85
        encoding.
83
86
        """
84
87
        wt = self.make_branch_and_tree('.')
85
 
        b = breezy.branch.Branch.open('.')
 
88
        b = branch.Branch.open('.')
86
89
        self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
87
90
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
88
91
                          encoding='ascii')
94
97
        self.make_branch_and_tree('.')
95
98
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
96
99
        self.assertEqual('"Branch Identity" does not seem to contain an '
97
 
                          'email address.  This is allowed, but not '
98
 
                          'recommended.\n', display)
 
100
                         'email address.  This is allowed, but not '
 
101
                         'recommended.\n', display)
99
102
 
100
103
    def test_whoami_not_set(self):
101
104
        """Ensure whoami error if username is not set and not inferred.
102
105
        """
103
 
        self.overrideEnv('EMAIL', None)
104
 
        self.overrideEnv('BRZ_EMAIL', None)
105
 
        # Also, make sure that it's not inferred from mailname.
106
 
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
 
106
        override_whoami(self)
107
107
        out, err = self.run_bzr(['whoami'], 3)
108
108
        self.assertContainsRe(err, 'Unable to determine your name')
109
109
 
119
119
        wt = wt.controldir.open_workingtree()
120
120
        c = wt.branch.get_config_stack()
121
121
        self.assertEqual('Changed Identity <changed@identi.ty>',
122
 
                          c.get('email'))
 
122
                         c.get('email'))
123
123
 
124
124
    def test_whoami_remote_directory(self):
125
125
        """Test --directory option with a remote directory."""
135
135
        # config)
136
136
        c = branch.Branch.open(url).get_config_stack()
137
137
        self.assertEqual('Changed Identity <changed@identi.ty>',
138
 
                          c.get('email'))
 
138
                         c.get('email'))
139
139
        # Ensuring that the value does not come from the breezy.conf file
140
140
        # itself requires some isolation setup
141
 
        self.overrideEnv('BRZ_EMAIL', None)
142
 
        self.overrideEnv('EMAIL', None)
143
 
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
 
141
        override_whoami(self)
144
142
        global_conf = config.GlobalStack()
145
 
        self.assertRaises(config.NoWhoami, global_conf.get, 'email')
 
143
        self.assertRaises(errors.NoWhoami, global_conf.get, 'email')
146
144
 
147
145
    def test_whoami_nonbranch_directory(self):
148
146
        """Test --directory mentioning a non-branch directory."""