/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: Jelmer Vernooij
  • Date: 2020-09-02 16:35:18 UTC
  • mto: (7490.40.109 work)
  • mto: This revision was merged to the branch mainline in revision 7526.
  • Revision ID: jelmer@jelmer.uk-20200902163518-sy9f4unbboljphgu
Handle duplicate directories entries for git.

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