~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

(vila) Bzr config should save the changes explicitly when needed (Vincent
 Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2015, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
288
288
        self.req_handler = RequestHandler(None, None, None)
289
289
 
290
290
    def assertRanges(self, ranges, header, file_size):
291
 
        self.assertEqual(ranges,
 
291
        self.assertEquals(ranges,
292
292
                          self.req_handler._parse_ranges(header, file_size))
293
293
 
294
294
    def test_simple_range(self):
656
656
 
657
657
    _req_handler_class = BadStatusRequestHandler
658
658
 
659
 
    def setUp(self):
660
 
        super(TestBadStatusServer, self).setUp()
661
 
        # See https://bugs.launchpad.net/bzr/+bug/1451448 for details.
662
 
        # TD;LR: Running both a TCP client and server in the same process and
663
 
        # thread uncovers a race in python. The fix is to run the server in a
664
 
        # different process. Trying to fix yet another race here is not worth
665
 
        # the effort. -- vila 2015-09-06
666
 
        if 'HTTP/1.0' in self.id():
667
 
            raise tests.TestSkipped(
668
 
                'Client/Server in the same process and thread can hang')
669
 
 
670
659
    def test_http_has(self):
671
660
        t = self.get_readonly_transport()
672
 
        self.assertRaises((errors.ConnectionError, errors.ConnectionReset,
673
 
                           errors.InvalidHttpResponse),
674
 
                          t.has, 'foo/bar')
 
661
        self.assertRaises(errors.InvalidHttpResponse, t.has, 'foo/bar')
675
662
 
676
663
    def test_http_get(self):
677
664
        t = self.get_readonly_transport()
678
 
        self.assertRaises((errors.ConnectionError, errors.ConnectionReset,
679
 
                           errors.InvalidHttpResponse),
680
 
                          t.get, 'foo/bar')
 
665
        self.assertRaises(errors.InvalidHttpResponse, t.get, 'foo/bar')
681
666
 
682
667
 
683
668
class InvalidStatusRequestHandler(http_server.TestingHTTPRequestHandler):
1200
1185
 
1201
1186
    def assertEvaluateProxyBypass(self, expected, host, no_proxy):
1202
1187
        handler = _urllib2_wrappers.ProxyHandler()
1203
 
        self.assertEqual(expected,
 
1188
        self.assertEquals(expected,
1204
1189
                          handler.evaluate_proxy_bypass(host, no_proxy))
1205
1190
 
1206
1191
    def test_empty_user(self):
1599
1584
            path='/',
1600
1585
            realm='Realm',
1601
1586
            ))
1602
 
        self.assertEqual((user, password), got_pass)
 
1587
        self.assertEquals((user, password), got_pass)
1603
1588
 
1604
1589
 
1605
1590
class TestAuth(http_utils.TestCaseWithWebserver):
2000
1985
        self.assertIsInstance(r, type(t))
2001
1986
        # Both transports share the some connection
2002
1987
        self.assertEqual(t._get_connection(), r._get_connection())
2003
 
        self.assertEqual('http://www.example.com/foo/subdir/', r.base)
 
1988
        self.assertEquals('http://www.example.com/foo/subdir/', r.base)
2004
1989
 
2005
1990
    def test_redirected_to_self_with_slash(self):
2006
1991
        t = self._transport('http://www.example.com/foo')
2017
2002
        r = t._redirected_to('http://www.example.com/foo',
2018
2003
                             'http://foo.example.com/foo/subdir')
2019
2004
        self.assertIsInstance(r, type(t))
2020
 
        self.assertEqual('http://foo.example.com/foo/subdir/',
 
2005
        self.assertEquals('http://foo.example.com/foo/subdir/',
2021
2006
            r.external_url())
2022
2007
 
2023
2008
    def test_redirected_to_same_host_sibling_protocol(self):
2025
2010
        r = t._redirected_to('http://www.example.com/foo',
2026
2011
                             'https://www.example.com/foo')
2027
2012
        self.assertIsInstance(r, type(t))
2028
 
        self.assertEqual('https://www.example.com/foo/',
 
2013
        self.assertEquals('https://www.example.com/foo/',
2029
2014
            r.external_url())
2030
2015
 
2031
2016
    def test_redirected_to_same_host_different_protocol(self):
2032
2017
        t = self._transport('http://www.example.com/foo')
2033
2018
        r = t._redirected_to('http://www.example.com/foo',
2034
2019
                             'ftp://www.example.com/foo')
2035
 
        self.assertNotEqual(type(r), type(t))
2036
 
        self.assertEqual('ftp://www.example.com/foo/', r.external_url())
 
2020
        self.assertNotEquals(type(r), type(t))
 
2021
        self.assertEquals('ftp://www.example.com/foo/', r.external_url())
2037
2022
 
2038
2023
    def test_redirected_to_same_host_specific_implementation(self):
2039
2024
        t = self._transport('http://www.example.com/foo')
2040
2025
        r = t._redirected_to('http://www.example.com/foo',
2041
2026
                             'https+urllib://www.example.com/foo')
2042
 
        self.assertEqual('https://www.example.com/foo/', r.external_url())
 
2027
        self.assertEquals('https://www.example.com/foo/', r.external_url())
2043
2028
 
2044
2029
    def test_redirected_to_different_host_same_user(self):
2045
2030
        t = self._transport('http://joe@www.example.com/foo')
2047
2032
                             'https://foo.example.com/foo')
2048
2033
        self.assertIsInstance(r, type(t))
2049
2034
        self.assertEqual(t._parsed_url.user, r._parsed_url.user)
2050
 
        self.assertEqual('https://joe@foo.example.com/foo/', r.external_url())
 
2035
        self.assertEquals('https://joe@foo.example.com/foo/', r.external_url())
2051
2036
 
2052
2037
 
2053
2038
class PredefinedRequestHandler(http_server.TestingHTTPRequestHandler):