/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 breezy/tests/test_mergeable.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2013, 2016 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import socketserver
 
18
 
 
19
from ..mergeable import read_mergeable_from_url
 
20
from ..directory_service import directories
 
21
from .. import (
 
22
    errors,
 
23
    tests,
 
24
    )
 
25
from ..bzr.tests import (
 
26
    test_read_bundle,
 
27
    )
 
28
from . import (
 
29
    test_server,
 
30
    )
 
31
 
 
32
 
 
33
class TestReadMergeableFromUrl(tests.TestCaseWithTransport):
 
34
 
 
35
    def test_read_mergeable_skips_local(self):
 
36
        """A local bundle named like the URL should not be read.
 
37
        """
 
38
        out, wt = test_read_bundle.create_bundle_file(self)
 
39
 
 
40
        class FooService(object):
 
41
            """A directory service that always returns source"""
 
42
 
 
43
            def look_up(self, name, url):
 
44
                return 'source'
 
45
        directories.register('foo:', FooService, 'Testing directory service')
 
46
        self.addCleanup(directories.remove, 'foo:')
 
47
        self.build_tree_contents([('./foo:bar', out.getvalue())])
 
48
        self.assertRaises(errors.NotABundle, read_mergeable_from_url,
 
49
                          'foo:bar')
 
50
 
 
51
    def test_infinite_redirects_are_not_a_bundle(self):
 
52
        """If a URL causes TooManyRedirections then NotABundle is raised.
 
53
        """
 
54
        from .blackbox.test_push import RedirectingMemoryServer
 
55
        server = RedirectingMemoryServer()
 
56
        self.start_server(server)
 
57
        url = server.get_url() + 'infinite-loop'
 
58
        self.assertRaises(errors.NotABundle, read_mergeable_from_url, url)
 
59
 
 
60
    def test_smart_server_connection_reset(self):
 
61
        """If a smart server connection fails during the attempt to read a
 
62
        bundle, then the ConnectionReset error should be propagated.
 
63
        """
 
64
        # Instantiate a server that will provoke a ConnectionReset
 
65
        sock_server = DisconnectingServer()
 
66
        self.start_server(sock_server)
 
67
        # We don't really care what the url is since the server will close the
 
68
        # connection without interpreting it
 
69
        url = sock_server.get_url()
 
70
        self.assertRaises(errors.ConnectionReset, read_mergeable_from_url, url)
 
71
 
 
72
 
 
73
class DisconnectingHandler(socketserver.BaseRequestHandler):
 
74
    """A request handler that immediately closes any connection made to it."""
 
75
 
 
76
    def handle(self):
 
77
        self.request.close()
 
78
 
 
79
 
 
80
class DisconnectingServer(test_server.TestingTCPServerInAThread):
 
81
 
 
82
    def __init__(self):
 
83
        super(DisconnectingServer, self).__init__(
 
84
            ('127.0.0.1', 0),
 
85
            test_server.TestingTCPServer,
 
86
            DisconnectingHandler)
 
87
 
 
88
    def get_url(self):
 
89
        """Return the url of the server"""
 
90
        return "bzr://%s:%d/" % self.server.server_address