/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/test_api.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 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
 
 
17
"""Tests for library API infrastructure
 
18
 
 
19
This is specifically for things controlling the interface, such as versioning.  
 
20
Tests for particular parts of the library interface should be in specific
 
21
relevant test modules.
 
22
"""
 
23
 
 
24
import bzrlib
 
25
import bzrlib.api
 
26
from bzrlib.errors import IncompatibleAPI
 
27
from bzrlib.tests import TestCase
 
28
 
 
29
class APITests(TestCase):
 
30
 
 
31
    def test_library_version(self):
 
32
        """Library API version is exposed"""
 
33
        self.assert_(isinstance(bzrlib.__version__, str))
 
34
        self.assert_(isinstance(bzrlib.version_string, str))
 
35
        self.assert_(isinstance(bzrlib.version_info, tuple))
 
36
        self.assertEqual(len(bzrlib.version_info), 5)
 
37
 
 
38
 
 
39
class TrivialObject(object):
 
40
    """This class allows assignment to any attribute."""
 
41
 
 
42
 
 
43
class TestAPIVersioning(TestCase):
 
44
 
 
45
    def test_get_minimum_api_version_reads_api_minimum_version(self):
 
46
        an_object = TrivialObject()
 
47
        an_object.api_minimum_version = (0, 1, 2)
 
48
        self.assertEqual((0, 1, 2),
 
49
            bzrlib.api.get_minimum_api_version(an_object))
 
50
 
 
51
    def test_get_minimum_api_version_fallsback_to_bzr_minimum_version(self):
 
52
        an_object = TrivialObject()
 
53
        self.assertEqual(bzrlib.api_minimum_version,
 
54
            bzrlib.api.get_minimum_api_version(an_object))
 
55
 
 
56
    def test_get_current_api_version_reads_api_current_version(self):
 
57
        an_object = TrivialObject()
 
58
        an_object.api_current_version = (3, 2, 1)
 
59
        an_object.version_info = (1, 2, 3, "final", 0)
 
60
        self.assertEqual((3, 2, 1),
 
61
            bzrlib.api.get_current_api_version(an_object))
 
62
 
 
63
    def test_get_current_api_version_fallsback_to_version_info(self):
 
64
        an_object = TrivialObject()
 
65
        an_object.version_info = (1, 2, 3, "final", 0)
 
66
        self.assertEqual((1, 2, 3),
 
67
            bzrlib.api.get_current_api_version(an_object))
 
68
 
 
69
    def test_get_current_api_version_fallsback_to_bzrlib_version_info(self):
 
70
        an_object = TrivialObject()
 
71
        self.assertEqual(bzrlib.version_info[0:3],
 
72
            bzrlib.api.get_current_api_version(an_object))
 
73
 
 
74
    def test_require_api_wanted_is_minimum_is_ok(self):
 
75
        an_object = TrivialObject()
 
76
        an_object.api_minimum_version = (1, 2, 3)
 
77
        an_object.api_current_version = (4, 5, 6)
 
78
        bzrlib.api.require_api(an_object, (1, 2, 3))
 
79
 
 
80
    def test_require_api_wanted_is_current_is_ok(self):
 
81
        an_object = TrivialObject()
 
82
        an_object.api_minimum_version = (1, 2, 3)
 
83
        an_object.api_current_version = (4, 5, 6)
 
84
        bzrlib.api.require_api(an_object, (4, 5, 6))
 
85
 
 
86
    def test_require_api_wanted_is_above_minimum_is_ok(self):
 
87
        an_object = TrivialObject()
 
88
        an_object.api_minimum_version = (1, 2, 3)
 
89
        an_object.api_current_version = (4, 5, 6)
 
90
        bzrlib.api.require_api(an_object, (1, 2, 4))
 
91
 
 
92
    def test_require_api_wanted_is_below_current_is_ok(self):
 
93
        an_object = TrivialObject()
 
94
        an_object.api_minimum_version = (1, 2, 3)
 
95
        an_object.api_current_version = (4, 5, 6)
 
96
        bzrlib.api.require_api(an_object, (4, 5, 5))
 
97
 
 
98
    def test_require_api_wanted_is_below_minimum_raises(self):
 
99
        an_object = TrivialObject()
 
100
        an_object.api_minimum_version = (1, 2, 3)
 
101
        an_object.api_current_version = (4, 5, 6)
 
102
        err = self.assertRaises(IncompatibleAPI,
 
103
            bzrlib.api.require_api, an_object, (1, 2, 2))
 
104
        self.assertEqual(err.api, an_object)
 
105
        self.assertEqual(err.wanted, (1, 2, 2))
 
106
        self.assertEqual(err.minimum, (1, 2, 3))
 
107
        self.assertEqual(err.current, (4, 5, 6))
 
108
 
 
109
    def test_require_api_wanted_is_above_current_raises(self):
 
110
        an_object = TrivialObject()
 
111
        an_object.api_minimum_version = (1, 2, 3)
 
112
        an_object.api_current_version = (4, 5, 6)
 
113
        err = self.assertRaises(IncompatibleAPI,
 
114
            bzrlib.api.require_api, an_object, (4, 5, 7))
 
115
        self.assertEqual(err.api, an_object)
 
116
        self.assertEqual(err.wanted, (4, 5, 7))
 
117
        self.assertEqual(err.minimum, (1, 2, 3))
 
118
        self.assertEqual(err.current, (4, 5, 6))