~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Parth Malwankar
  • Date: 2010-05-05 14:02:53 UTC
  • mto: This revision was merged to the branch mainline in revision 5213.
  • Revision ID: parth.malwankar@gmail.com-20100505140253-fqdiwllq4o4htbsg
added comment to init/init-repo pass tests for lacking whoami.

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 import osutils
 
24
from bzrlib.branch import Branch
 
25
from bzrlib.tests.blackbox import ExternalBase
 
26
 
 
27
 
 
28
class TestWhoami(ExternalBase):
31
29
 
32
30
    def test_whoami(self):
33
31
        # this should always identify something, if only "john@localhost"
45
43
        b = bzrlib.branch.Branch.open('.')
46
44
        b.get_config().set_user_option('email',
47
45
                                       '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)
 
46
        bzr_email = os.environ.get('BZR_EMAIL')
 
47
        if bzr_email is not None:
 
48
            del os.environ['BZR_EMAIL']
 
49
        try:
 
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)
52
54
 
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)
 
55
            # Verify that the environment variable overrides the value
 
56
            # in the file
 
57
            os.environ['BZR_EMAIL'] = 'Different ID <other@environ.ment>'
 
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)
 
62
            del os.environ['BZR_EMAIL']
 
63
        finally:
 
64
            if bzr_email is not None:
 
65
                os.environ['BZR_EMAIL'] = bzr_email
60
66
 
61
67
    def test_whoami_utf8(self):
62
68
        """verify that an identity can be in utf-8."""
63
69
        wt = self.make_branch_and_tree('.')
64
70
        self.run_bzr(['whoami', u'Branch Identity \u20ac <branch@identi.ty>'],
65
71
                     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)
 
72
        bzr_email = os.environ.get('BZR_EMAIL')
 
73
        if bzr_email is not None:
 
74
            del os.environ['BZR_EMAIL']
 
75
        try:
 
76
            whoami = self.run_bzr("whoami", encoding='utf-8')[0]
 
77
            self.assertEquals('Branch Identity \xe2\x82\xac ' +
 
78
                              '<branch@identi.ty>\n', whoami)
 
79
            whoami_email = self.run_bzr("whoami --email",
 
80
                                        encoding='utf-8')[0]
 
81
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
82
        finally:
 
83
            if bzr_email is not None:
 
84
                os.environ['BZR_EMAIL'] = bzr_email
71
85
 
72
86
    def test_whoami_ascii(self):
73
87
        """
78
92
        b = bzrlib.branch.Branch.open('.')
79
93
        b.get_config().set_user_option('email', u'Branch Identity \u20ac ' +
80
94
                                       '<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)
 
95
        bzr_email = os.environ.get('BZR_EMAIL')
 
96
        if bzr_email is not None:
 
97
            del os.environ['BZR_EMAIL']
 
98
        try:
 
99
            whoami = self.run_bzr("whoami", encoding='ascii')[0]
 
100
            self.assertEquals('Branch Identity ? <branch@identi.ty>\n', whoami)
 
101
            whoami_email = self.run_bzr("whoami --email",
 
102
                                        encoding='ascii')[0]
 
103
            self.assertEquals('branch@identi.ty\n', whoami_email)
 
104
        finally:
 
105
            if bzr_email is not None:
 
106
                os.environ['BZR_EMAIL'] = bzr_email
85
107
 
86
108
    def test_warning(self):
87
109
        """verify that a warning is displayed if no email is given."""
98
120
        osutils.set_or_unset_env('BZR_EMAIL', None)
99
121
        out, err = self.run_bzr(['whoami'], 3)
100
122
        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')