/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_http.py

1st cut merge of bzr.dev r3907

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
import bzrlib
36
36
from bzrlib import (
 
37
    bzrdir,
37
38
    config,
38
39
    errors,
39
40
    osutils,
 
41
    remote as _mod_remote,
40
42
    tests,
41
43
    transport,
42
44
    ui,
118
120
    t_adapter = TransportAdapter()
119
121
    t_classes= (TestHttpTransportRegistration,
120
122
                TestHttpTransportUrls,
 
123
                Test_redirected_to,
121
124
                )
122
125
    is_testing_for_transports = tests.condition_isinstance(t_classes)
123
126
 
447
450
            '"GET /foo/bar HTTP/1.1" 200 - "-" "bzr/%s'
448
451
            % bzrlib.__version__) > -1)
449
452
 
450
 
    def test_get_smart_medium(self):
451
 
        # For HTTP, get_smart_medium should return the transport object.
452
 
        server = self.get_readonly_server()
453
 
        http_transport = self._transport(server.get_url())
454
 
        medium = http_transport.get_smart_medium()
455
 
        self.assertIs(medium, http_transport)
456
 
 
457
453
    def test_has_on_bogus_host(self):
458
454
        # Get a free address and don't 'accept' on it, so that we
459
455
        # can be sure there is no http handler there, but set a
1143
1139
        url = self.server.get_url()
1144
1140
        t = self._transport(url)
1145
1141
        try:
1146
 
            self.assertEqual(t.get('foo').read(), 'proxied contents of foo\n')
 
1142
            self.assertEqual('proxied contents of foo\n', t.get('foo').read())
1147
1143
        finally:
1148
1144
            self._restore_env()
1149
1145
 
1152
1148
        url = self.server.get_url()
1153
1149
        t = self._transport(url)
1154
1150
        try:
1155
 
            self.assertEqual(t.get('foo').read(), 'contents of foo\n')
 
1151
            self.assertEqual('contents of foo\n', t.get('foo').read())
1156
1152
        finally:
1157
1153
            self._restore_env()
1158
1154
 
1268
1264
                                  ('bundle',
1269
1265
                                  '# Bazaar revision bundle v0.9\n#\n')
1270
1266
                                  ],)
1271
 
 
 
1267
        # The requests to the old server will be redirected to the new server
1272
1268
        self.old_transport = self._transport(self.old_server.get_url())
1273
1269
 
1274
1270
    def test_redirected(self):
1667
1663
        return http_utils.HTTPServerWithSmarts(
1668
1664
            protocol_version=self._protocol_version)
1669
1665
 
 
1666
    def test_open_bzrdir(self):
 
1667
        branch = self.make_branch('relpath')
 
1668
        http_server = self.get_readonly_server()
 
1669
        url = http_server.get_url() + 'relpath'
 
1670
        bd = bzrdir.BzrDir.open(url)
 
1671
        self.assertIsInstance(bd, _mod_remote.RemoteBzrDir)
 
1672
 
1670
1673
    def test_bulk_data(self):
1671
1674
        # We should be able to send and receive bulk data in a single message.
1672
1675
        # The 'readv' command in the smart protocol both sends and receives
1738
1741
        # No need to build a valid smart request here, the server will not even
1739
1742
        # try to interpret it.
1740
1743
        self.assertRaises(errors.SmartProtocolError,
1741
 
                          t.send_http_smart_request, 'whatever')
1742
 
 
 
1744
                          t.get_smart_medium().send_http_smart_request,
 
1745
                          'whatever')
 
1746
 
 
1747
class Test_redirected_to(tests.TestCase):
 
1748
 
 
1749
    def test_redirected_to_subdir(self):
 
1750
        t = self._transport('http://www.example.com/foo')
 
1751
        r = t._redirected_to('http://www.example.com/foo',
 
1752
                             'http://www.example.com/foo/subdir')
 
1753
        self.assertIsInstance(r, type(t))
 
1754
        # Both transports share the some connection
 
1755
        self.assertEquals(t._get_connection(), r._get_connection())
 
1756
 
 
1757
    def test_redirected_to_self_with_slash(self):
 
1758
        t = self._transport('http://www.example.com/foo')
 
1759
        r = t._redirected_to('http://www.example.com/foo',
 
1760
                             'http://www.example.com/foo/')
 
1761
        self.assertIsInstance(r, type(t))
 
1762
        # Both transports share the some connection (one can argue that we
 
1763
        # should return the exact same transport here, but that seems
 
1764
        # overkill).
 
1765
        self.assertEquals(t._get_connection(), r._get_connection())
 
1766
 
 
1767
    def test_redirected_to_host(self):
 
1768
        t = self._transport('http://www.example.com/foo')
 
1769
        r = t._redirected_to('http://www.example.com/foo',
 
1770
                             'http://foo.example.com/foo/subdir')
 
1771
        self.assertIsInstance(r, type(t))
 
1772
 
 
1773
    def test_redirected_to_same_host_sibling_protocol(self):
 
1774
        t = self._transport('http://www.example.com/foo')
 
1775
        r = t._redirected_to('http://www.example.com/foo',
 
1776
                             'https://www.example.com/foo')
 
1777
        self.assertIsInstance(r, type(t))
 
1778
 
 
1779
    def test_redirected_to_same_host_different_protocol(self):
 
1780
        t = self._transport('http://www.example.com/foo')
 
1781
        r = t._redirected_to('http://www.example.com/foo',
 
1782
                             'ftp://www.example.com/foo')
 
1783
        self.assertNotEquals(type(r), type(t))
 
1784
 
 
1785
    def test_redirected_to_different_host_same_user(self):
 
1786
        t = self._transport('http://joe@www.example.com/foo')
 
1787
        r = t._redirected_to('http://www.example.com/foo',
 
1788
                             'https://foo.example.com/foo')
 
1789
        self.assertIsInstance(r, type(t))
 
1790
        self.assertEquals(t._user, r._user)