~bigkevmcd/offspring/bug-1039135-fix-notifications

« back to all changes in this revision

Viewing changes to lib/offspring/tests/test_networking.py

  • Committer: Cody A.W. Somerville
  • Date: 2012-07-30 01:48:49 UTC
  • mfrom: (151.1.5 fix-offspring-on-python2.7)
  • Revision ID: cody.somerville@canonical.com-20120730014849-tzssditldxcnq0c9
Fixed Offspring running on python > 2.6 [r=timrc].

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
import sys
 
5
 
 
6
from mocker import MockerTestCase
 
7
 
 
8
from offspring.networking import (
 
9
    TimeoutHTTP,
 
10
    TimeoutHTTPConnection,
 
11
    TimeoutTransport,
 
12
)
 
13
 
 
14
class TestTimeoutTransport(MockerTestCase):
 
15
 
 
16
    def test_make_connection_before_python2_6(self):
 
17
        """
 
18
        When running on versions earlier than python 2.7, TimeoutTransport's
 
19
        make_connection method should return an instance of TimeoutHTTP as
 
20
        before python 2.7 xmlrpclib continued to use python 1.5 httplib API.
 
21
        """
 
22
        mock_sys = self.mocker.replace(sys)
 
23
        mock_sys.version_info
 
24
        self.mocker.result((2,6))
 
25
        self.mocker.replay()
 
26
        transport = TimeoutTransport()
 
27
        connection = transport.make_connection("http://localhost:1234")
 
28
        self.assertTrue(isinstance(connection, TimeoutHTTP))
 
29
 
 
30
    def test_make_connection_on_python2_7_or_later(self):
 
31
        """
 
32
        When running on versions python 2.7 or later, TimeoutTransport's
 
33
        make_connection method should return an instance of 
 
34
        TimeoutHTTPConnection instead of TimeoutHTTP.
 
35
        """
 
36
        mock_sys = self.mocker.replace(sys)
 
37
        mock_sys.version_info
 
38
        self.mocker.result((2,7))
 
39
        self.mocker.replay()
 
40
        transport = TimeoutTransport()
 
41
        connection = transport.make_connection("http://localhost:1234")
 
42
        self.assertTrue(isinstance(connection, TimeoutHTTPConnection))
 
43
 
 
44
    def test_make_connection_saves_extra_headers(self):
 
45
        """
 
46
        TimeoutTransport's make_connection should save extra headers returned
 
47
        when it calls it's get_host_info method as extra_headers. It'll be set
 
48
        to a list if there is auth details in host url.
 
49
        
 
50
        After python 2.6, the authorization header will not be sent if it
 
51
        hasn't been saved to extra_headers when make_connection is called.
 
52
        """
 
53
        transport = TimeoutTransport()
 
54
        transport.make_connection("http://admin:password@localhost:1234")
 
55
        self.assertTrue(transport._extra_headers is not None)