~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smtp_connection.py

  • Committer: Vincent Ladeuil
  • Date: 2007-07-22 15:44:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070722154459-520ws2gnifghkpgy
From review comments, use a private scheme for testing.

* bzrlib/transport/__init__.py:
(_unregister_urlparse_netloc_protocol): New function.

* bzrlib/tests/transport_util.py:
(InstrumentedTransport.__init__): Use a dedicated scheme.
(TestCaseWithConnectionHookedTransport.setUp): Reworked to
register the new transport.
(TestCaseWithConnectionHookedTransport.get_url): Use our dedicated
scheme.
(TestCaseWithConnectionHookedTransport.install_hooks,
TestCaseWithConnectionHookedTransport.reset_hooks): Registering
transport is setUp job.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
from email.Message import Message
19
 
import errno
20
 
import smtplib
21
 
import socket
22
19
 
23
 
from bzrlib import (
24
 
    config,
25
 
    errors,
26
 
    )
 
20
from bzrlib import config
27
21
from bzrlib.email_message import EmailMessage
28
22
from bzrlib.errors import NoDestinationAddress
29
23
from bzrlib.tests import TestCase
30
24
from bzrlib.smtp_connection import SMTPConnection
31
25
 
32
26
 
33
 
def connection_refuser():
34
 
    def connect(server):
35
 
        raise socket.error(errno.ECONNREFUSED, 'Connection Refused')
36
 
    smtp = smtplib.SMTP()
37
 
    smtp.connect = connect
38
 
    return smtp
39
 
 
40
 
 
41
27
class TestSMTPConnection(TestCase):
42
28
 
43
 
    def get_connection(self, text, smtp_factory=None):
 
29
    def get_connection(self, text):
44
30
        my_config = config.GlobalConfig()
45
31
        config_file = StringIO(text)
46
32
        my_config._get_parser(config_file)
47
 
        return SMTPConnection(my_config, _smtp_factory=smtp_factory)
 
33
        return SMTPConnection(my_config)
48
34
 
49
35
    def test_defaults(self):
50
36
        conn = self.get_connection('')
56
42
        conn = self.get_connection('[DEFAULT]\nsmtp_server=host:10\n')
57
43
        self.assertEqual('host:10', conn._smtp_server)
58
44
 
59
 
    def test_missing_server(self):
60
 
        conn = self.get_connection('', smtp_factory=connection_refuser)
61
 
        self.assertRaises(errors.DefaultSMTPConnectionRefused, conn._connect)
62
 
        conn = self.get_connection('[DEFAULT]\nsmtp_server=smtp.example.com\n',
63
 
                                   smtp_factory=connection_refuser)
64
 
        self.assertRaises(errors.SMTPConnectionRefused, conn._connect)
65
 
 
66
45
    def test_smtp_username(self):
67
46
        conn = self.get_connection('')
68
47
        self.assertIs(None, conn._smtp_username)