~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: 2009-06-03 15:02:09 UTC
  • mfrom: (4398.2.1 export-test-fix)
  • Revision ID: pqm@pqm.ubuntu.com-20090603150209-szap3popp2j8fpl3
(John Szakmeister) Fix error formatting for tar related KnowFailure
        on Mac

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006 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
20
20
import os
21
21
 
22
22
import bzrlib
23
 
from bzrlib import (
24
 
    osutils,
25
 
    config,
26
 
    )
27
 
from bzrlib.tests import TestCaseWithTransport
28
 
 
29
 
 
30
 
class TestWhoami(TestCaseWithTransport):
 
23
from bzrlib.branch import Branch
 
24
from bzrlib.tests.blackbox import ExternalBase
 
25
 
 
26
 
 
27
class TestWhoami(ExternalBase):
31
28
 
32
29
    def test_whoami(self):
33
30
        # this should always identify something, if only "john@localhost"
45
42
        b = bzrlib.branch.Branch.open('.')
46
43
        b.get_config().set_user_option('email',
47
44
                                       '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)
 
45
        bzr_email = os.environ.get('BZR_EMAIL')
 
46
        if bzr_email is not None:
 
47
            del os.environ['BZR_EMAIL']
 
48
        try:
 
49
            whoami = self.run_bzr("whoami")[0]
 
50
            self.assertEquals('Branch Identity <branch@identi.ty>\n', whoami)
 
51
            whoami_email = self.run_bzr("whoami --email")[0]
 
52
            self.assertEquals('branch@identi.ty\n', whoami_email)
52
53
 
53
 
        # Verify that the environment variable overrides the value
54
 
        # in the file
55
 
        os.environ['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)
 
54
            # Verify that the environment variable overrides the value
 
55
            # in the file
 
56
            os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
 
57
            whoami = self.run_bzr("whoami")[0]
 
58
            self.assertEquals('Different ID <other@environ.ment>\n', whoami)
 
59
            whoami_email = self.run_bzr("whoami --email")[0]
 
60
            self.assertEquals('other@environ.ment\n', whoami_email)
 
61
            del os.environ['BZR_EMAIL']
 
62
        finally:
 
63
            if bzr_email is not None:
 
64
                os.environ['BZR_EMAIL'] = bzr_email
60
65
 
61
66
    def test_whoami_utf8(self):
62
67
        """verify that an identity can be in utf-8."""
63
68
        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
        bzr_email = os.environ.get('BZR_EMAIL')
 
72
        if bzr_email is not None:
 
73
            del os.environ['BZR_EMAIL']
 
74
        try:
 
75
            whoami = self.run_bzr("whoami", encoding='utf-8')[0]
 
76
            self.assertEquals('Branch Identity \xe2\x82\xac ' +
 
77
                              '<branch@identi.ty>\n', whoami)
 
78
            whoami_email = self.run_bzr("whoami --email",
 
79
                                        encoding='utf-8')[0]
 
80
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
81
        finally:
 
82
            if bzr_email is not None:
 
83
                os.environ['BZR_EMAIL'] = bzr_email
71
84
 
72
85
    def test_whoami_ascii(self):
73
86
        """
78
91
        b = bzrlib.branch.Branch.open('.')
79
92
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
80
93
                                       '<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)
 
94
        bzr_email = os.environ.get('BZR_EMAIL')
 
95
        if bzr_email is not None:
 
96
            del os.environ['BZR_EMAIL']
 
97
        try:
 
98
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
 
99
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
 
100
            whoami_email = self.run_bzr("whoami --email",
 
101
                                        encoding='ascii')[0]
 
102
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
103
        finally:
 
104
            if bzr_email is not None:
 
105
                os.environ['BZR_EMAIL'] = bzr_email
85
106
 
86
107
    def test_warning(self):
87
108
        """verify that a warning is displayed if no email is given."""
90
111
        self.assertEquals('"Branch Identity" does not seem to contain an '
91
112
                          'email address.  This is allowed, but not '
92
113
                          'recommended.\n', display)
93
 
 
94
 
    def test_whoami_not_set(self):
95
 
        """Ensure whoami error if username is not set.
96
 
        """
97
 
        osutils.set_or_unset_env('EMAIL', None)
98
 
        osutils.set_or_unset_env('BZR_EMAIL', None)
99
 
        out, err = self.run_bzr(['whoami'], 3)
100
 
        self.assertContainsRe(err, 'Unable to determine your name')
101
 
 
102
 
    def test_whoami_directory(self):
103
 
        """Test --directory option."""
104
 
        wt = self.make_branch_and_tree('subdir')
105
 
        c = wt.branch.get_config()
106
 
        c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
107
 
        out, err = self.run_bzr("whoami --directory subdir")
108
 
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
109
 
        self.run_bzr(['whoami', '--directory', 'subdir', '--branch',
110
 
                      'Changed Identity <changed@identi.ty>'])
111
 
        self.assertEquals('Changed Identity <changed@identi.ty>',
112
 
                          c.get_user_option('email'))
113
 
 
114
 
    def test_whoami_remote_directory(self):
115
 
        """Test --directory option with a remote directory."""
116
 
        wt = self.make_branch_and_tree('subdir')
117
 
        c = wt.branch.get_config()
118
 
        c.set_user_option('email', 'Branch Identity <branch@identi.ty>')
119
 
        url = self.get_readonly_url() + '/subdir'
120
 
        out, err = self.run_bzr(['whoami', '--directory', url])
121
 
        self.assertEquals('Branch Identity <branch@identi.ty>\n', out)
122
 
        url = self.get_url('subdir')
123
 
        self.run_bzr(['whoami', '--directory', url, '--branch',
124
 
                      'Changed Identity <changed@identi.ty>'])
125
 
        # The identity has been set in the branch config (but not the global
126
 
        # config)
127
 
        self.assertEquals('Changed Identity <changed@identi.ty>',
128
 
                          c.get_user_option('email'))
129
 
        global_conf = config.GlobalConfig()
130
 
        self.assertEquals(None, global_conf.get_user_option('email'))
131
 
 
132
 
    def test_whoami_nonbranch_directory(self):
133
 
        """Test --directory mentioning a non-branch directory."""
134
 
        wt = self.build_tree(['subdir/'])
135
 
        out, err = self.run_bzr("whoami --directory subdir", retcode=3)
136
 
        self.assertContainsRe(err, 'ERROR: Not a branch')