/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 bzrlib/tests/blackbox/test_aliases.py

  • Committer: Adeodato Simó
  • Date: 2007-07-18 15:51:52 UTC
  • mto: (2639.1.1 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 2640.
  • Revision ID: dato@net.com.org.es-20070718155152-pv6rwq41eckqyxem
New EmailMessage class, façade around email.Message and MIMEMultipart.

* bzrlib/email_message.py,
  bzrlib/tests/test_email_message.py:
  New files.

* bzrlib/tests/__init__.py:
  (test_suite): add bzrlib.tests.test_email_message.

* bzrlib/merge_directive.py:
  (MergeDirective.to_email): Use EmailMessage instead of email.Message.

* bzrlib/tests/test_merge_directive.py,
  bzrlib/tests/blackbox/test_merge_directive.py:
  (__main__): adjust EMAIL1 and EMAIL2 strings to how EmailMessage
  formats itself.

* bzrlib/smtp_connection.py:
  (SMTPConnection.get_message_addresses): do not use methods present in
  email.Message but not in EmailMessage (get_all). Use get() instead of
  __getitem__ to make explicit that None is returned if the header does
  not exist.

* bzrlib/tests/test_smtp_connection.py:
  (TestSMTPConnection.test_get_message_addresses, 
   TestSMTPConnection.test_destination_address_required): test the
   functions against EmailMessage in addition to email.Message.

* NEWS:
  Mention EmailMessage in INTERNALS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
"""Black-box tests for bzr aliases.
 
17
"""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.branch import Branch
 
22
from bzrlib.tests import TestCaseInTempDir
 
23
from bzrlib.trace import mutter
 
24
from bzrlib.config import (ensure_config_dir_exists, config_filename)
 
25
 
 
26
 
 
27
class TestAliases(TestCaseInTempDir):
 
28
 
 
29
    def test_aliases(self):
 
30
 
 
31
        def bzr(args, **kwargs):
 
32
            return self.run_bzr(args, **kwargs)[0]
 
33
 
 
34
        def bzr_catch_error(args, **kwargs):
 
35
            return self.run_bzr(args, **kwargs)[1]
 
36
 
 
37
 
 
38
        if os.path.isfile(config_filename()):
 
39
            # Something is wrong in environment, 
 
40
            # we risk overwriting users config 
 
41
            self.assert_(config_filename() + "exists, abort")
 
42
        
 
43
        ensure_config_dir_exists()
 
44
        CONFIG=("[ALIASES]\n"
 
45
                "c=cat\n"
 
46
                "c1=cat -r 1\n"
 
47
                "c2=cat -r 1 -r2\n")
 
48
 
 
49
        open(config_filename(),'wb').write(CONFIG)
 
50
 
 
51
 
 
52
        str1 = 'foo\n'
 
53
        str2 = 'bar\n'
 
54
 
 
55
        bzr('init')
 
56
        open('a', 'wb').write(str1)
 
57
        bzr('add a')
 
58
 
 
59
        bzr('commit -m 1')
 
60
 
 
61
        self.assertEquals(bzr('c a'), str1)
 
62
 
 
63
        open('a', 'wb').write(str2)
 
64
        bzr('commit -m 2')
 
65
 
 
66
        self.assertEquals(bzr('c a'), str2)
 
67
        self.assertEquals(bzr('c1 a'), str1)
 
68
        self.assertEquals(bzr('c1 --revision 2 a'), str2)
 
69
 
 
70
        # If --no-aliases isn't working, we will not get retcode=3
 
71
        bzr('--no-aliases c a', retcode=3)
 
72
 
 
73
        # If --no-aliases breaks all of bzr, we also get retcode=3
 
74
        # So we need to catch the output as well
 
75
        self.assertEquals(bzr_catch_error('--no-aliases c a',
 
76
                                          retcode=None),
 
77
                          'bzr: ERROR: unknown command "c"\n')
 
78
 
 
79
        bzr('c -r1 -r2', retcode=3)
 
80
        bzr('c1 -r1 -r2', retcode=3)
 
81
        bzr('c2', retcode=3)
 
82
        bzr('c2 -r1', retcode=3)