~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_server.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-09 17:06:49 UTC
  • mto: (5029.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5030.
  • Revision ID: v.ladeuil+lp@free.fr-20100209170649-ae9ore5pp4durhdg
Move DecoratorServer to test_server.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        raise NotImplementedError
54
54
 
55
55
 
 
56
class DecoratorServer(Server):
 
57
    """Server for the TransportDecorator for testing with.
 
58
 
 
59
    To use this when subclassing TransportDecorator, override override the
 
60
    get_decorator_class method.
 
61
    """
 
62
 
 
63
    def start_server(self, server=None):
 
64
        """See bzrlib.transport.Server.start_server.
 
65
 
 
66
        :server: decorate the urls given by server. If not provided a
 
67
        LocalServer is created.
 
68
        """
 
69
        if server is not None:
 
70
            self._made_server = False
 
71
            self._server = server
 
72
        else:
 
73
            from bzrlib.transport.local import LocalURLServer
 
74
            self._made_server = True
 
75
            self._server = LocalURLServer()
 
76
            self._server.start_server()
 
77
 
 
78
    def stop_server(self):
 
79
        if self._made_server:
 
80
            self._server.stop_server()
 
81
 
 
82
    def get_decorator_class(self):
 
83
        """Return the class of the decorators we should be constructing."""
 
84
        raise NotImplementedError(self.get_decorator_class)
 
85
 
 
86
    def get_url_prefix(self):
 
87
        """What URL prefix does this decorator produce?"""
 
88
        return self.get_decorator_class()._get_url_prefix()
 
89
 
 
90
    def get_bogus_url(self):
 
91
        """See bzrlib.transport.Server.get_bogus_url."""
 
92
        return self.get_url_prefix() + self._server.get_bogus_url()
 
93
 
 
94
    def get_url(self):
 
95
        """See bzrlib.transport.Server.get_url."""
 
96
        return self.get_url_prefix() + self._server.get_url()
 
97
 
 
98