/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 brzlib/tests/blackbox/test_whoami.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz whoami."""
 
18
"""Black-box tests for bzr whoami."""
19
19
 
20
 
from breezy import (
 
20
import brzlib
 
21
from brzlib import (
21
22
    branch,
22
23
    config,
23
24
    errors,
24
25
    tests,
25
26
    )
26
27
 
27
 
from ..test_bedding import override_whoami
28
 
 
29
28
 
30
29
class TestWhoami(tests.TestCaseWithTransport):
31
30
 
34
33
        self.assertEqual('', err)
35
34
        lines = out.splitlines()
36
35
        self.assertLength(1, lines)
37
 
        if isinstance(expected, bytes):
38
 
            expected = expected.decode(kwargs.get('encoding', 'ascii'))
39
36
        self.assertEqual(expected, lines[0].rstrip())
40
37
 
41
38
    def test_whoami_no_args_no_conf(self):
60
57
    def test_whoami_branch(self):
61
58
        """branch specific user identity works."""
62
59
        wt = self.make_branch_and_tree('.')
63
 
        b = branch.Branch.open('.')
 
60
        b = brzlib.branch.Branch.open('.')
64
61
        self.set_branch_email(b, 'Branch Identity <branch@identi.ty>')
65
62
        self.assertWhoAmI('Branch Identity <branch@identi.ty>')
66
63
        self.assertWhoAmI('branch@identi.ty', '--email')
67
64
 
68
65
        # Verify that the environment variable overrides the value
69
66
        # in the file
70
 
        self.overrideEnv('BRZ_EMAIL', 'Different ID <other@environ.ment>')
 
67
        self.overrideEnv('BZR_EMAIL', 'Different ID <other@environ.ment>')
71
68
        self.assertWhoAmI('Different ID <other@environ.ment>')
72
69
        self.assertWhoAmI('other@environ.ment', '--email')
73
70
 
75
72
        """verify that an identity can be in utf-8."""
76
73
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
77
74
                     encoding='utf-8')
78
 
        self.assertWhoAmI(b'Branch Identity \xe2\x82\xac <branch@identi.ty>',
 
75
        self.assertWhoAmI('Branch Identity \xe2\x82\xac <branch@identi.ty>',
79
76
                          encoding='utf-8')
80
77
        self.assertWhoAmI('branch@identi.ty', '--email')
81
78
 
85
82
        encoding.
86
83
        """
87
84
        wt = self.make_branch_and_tree('.')
88
 
        b = branch.Branch.open('.')
 
85
        b = brzlib.branch.Branch.open('.')
89
86
        self.set_branch_email(b, u'Branch Identity \u20ac <branch@identi.ty>')
90
87
        self.assertWhoAmI('Branch Identity ? <branch@identi.ty>',
91
88
                          encoding='ascii')
97
94
        self.make_branch_and_tree('.')
98
95
        display = self.run_bzr(['whoami', 'Branch Identity'])[1]
99
96
        self.assertEqual('"Branch Identity" does not seem to contain an '
100
 
                         'email address.  This is allowed, but not '
101
 
                         'recommended.\n', display)
 
97
                          'email address.  This is allowed, but not '
 
98
                          'recommended.\n', display)
102
99
 
103
100
    def test_whoami_not_set(self):
104
101
        """Ensure whoami error if username is not set and not inferred.
105
102
        """
106
 
        override_whoami(self)
 
103
        self.overrideEnv('EMAIL', None)
 
104
        self.overrideEnv('BZR_EMAIL', None)
 
105
        # Also, make sure that it's not inferred from mailname.
 
106
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
107
107
        out, err = self.run_bzr(['whoami'], 3)
108
108
        self.assertContainsRe(err, 'Unable to determine your name')
109
109
 
116
116
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
117
117
                      'Changed Identity <changed@identi.ty>'])
118
118
        # Refresh wt as 'whoami' modified it
119
 
        wt = wt.controldir.open_workingtree()
 
119
        wt = wt.bzrdir.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'))
139
 
        # Ensuring that the value does not come from the breezy.conf file
 
138
                          c.get('email'))
 
139
        # Ensuring that the value does not come from the bazaar.conf file
140
140
        # itself requires some isolation setup
141
 
        override_whoami(self)
 
141
        self.overrideEnv('BZR_EMAIL', None)
 
142
        self.overrideEnv('EMAIL', None)
 
143
        self.overrideAttr(config, '_auto_user_id', lambda: (None, None))
142
144
        global_conf = config.GlobalStack()
143
145
        self.assertRaises(errors.NoWhoami, global_conf.get, 'email')
144
146