~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_serve.py

  • Committer: Aaron Bentley
  • Date: 2007-02-06 14:52:16 UTC
  • mfrom: (2266 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2268.
  • Revision ID: abentley@panoramicfeedback.com-20070206145216-fcpi8o3ufvuzwbp9
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import signal
22
22
import subprocess
23
 
import sys
24
23
import threading
25
24
 
26
 
from bzrlib import (
27
 
    errors,
28
 
    osutils,
29
 
    revision as _mod_revision,
30
 
    )
 
25
from bzrlib import errors
31
26
from bzrlib.branch import Branch
32
27
from bzrlib.bzrdir import BzrDir
33
28
from bzrlib.errors import ParamikoNotPresent
34
 
from bzrlib.smart import medium
35
29
from bzrlib.tests import TestCaseWithTransport, TestSkipped
36
 
from bzrlib.transport import get_transport, remote
 
30
from bzrlib.transport import get_transport, smart
37
31
 
38
32
 
39
33
class TestBzrServe(TestCaseWithTransport):
45
39
        process.stdin.close()
46
40
        # Hide stdin from the subprocess module, so it won't fail to close it.
47
41
        process.stdin = None
48
 
        result = self.finish_bzr_subprocess(process)
 
42
        result = self.finish_bzr_subprocess(process, retcode=0)
49
43
        self.assertEqual('', result[0])
50
44
        self.assertEqual('', result[1])
51
45
    
57
51
        self.assertEqual('', result[0])
58
52
        self.assertEqual('bzr: interrupted\n', result[1])
59
53
 
60
 
    def make_read_requests(self, branch):
61
 
        """Do some read only requests."""
62
 
        branch.lock_read()
63
 
        try:
64
 
            branch.repository.all_revision_ids()
65
 
            self.assertEqual(_mod_revision.NULL_REVISION,
66
 
                             _mod_revision.ensure_null(branch.last_revision()))
67
 
        finally:
68
 
            branch.unlock()
69
 
 
70
54
    def start_server_inet(self, extra_options=()):
71
55
        """Start a bzr server subprocess using the --inet option.
72
56
 
80
64
        # Connect to the server
81
65
        # We use this url because while this is no valid URL to connect to this
82
66
        # server instance, the transport needs a URL.
83
 
        url = 'bzr://localhost/'
84
 
        client_medium = medium.SmartSimplePipesClientMedium(
85
 
            process.stdout, process.stdin, url)
86
 
        transport = remote.RemoteTransport(url, medium=client_medium)
 
67
        medium = smart.SmartSimplePipesClientMedium(
 
68
            process.stdout, process.stdin)
 
69
        transport = smart.SmartTransport('bzr://localhost/', medium=medium)
87
70
        return process, transport
88
71
 
89
72
    def start_server_port(self, extra_options=()):
117
100
 
118
101
        # We get a working branch
119
102
        branch = BzrDir.open_from_transport(transport).open_branch()
120
 
        self.make_read_requests(branch)
 
103
        branch.repository.get_revision_graph()
 
104
        self.assertEqual(None, branch.last_revision())
121
105
        self.assertInetServerShutsdownCleanly(process)
122
106
 
123
107
    def test_bzr_serve_port_readonly(self):
135
119
 
136
120
        # Connect to the server
137
121
        branch = Branch.open(url)
138
 
        self.make_read_requests(branch)
 
122
 
 
123
        # We get a working branch
 
124
        branch.repository.get_revision_graph()
 
125
        self.assertEqual(None, branch.last_revision())
 
126
 
139
127
        self.assertServerFinishesCleanly(process)
140
128
 
 
129
    def test_bzr_serve_no_args(self):
 
130
        """'bzr serve' with no arguments or options should not traceback."""
 
131
        out, err = self.run_bzr_error(
 
132
            ['bzr serve requires one of --inet or --port'], 'serve')
 
133
 
141
134
    def test_bzr_connect_to_bzr_ssh(self):
142
135
        """User acceptance that get_transport of a bzr+ssh:// behaves correctly.
143
136
 
199
192
 
200
193
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
201
194
        # variable is used to tell bzr what command to run on the remote end.
202
 
        path_to_branch = osutils.abspath('a_branch')
 
195
        path_to_branch = os.path.abspath('a_branch')
203
196
        
204
197
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
205
 
        bzr_remote_path = self.get_bzr_path()
206
 
        if sys.platform == 'win32':
207
 
            bzr_remote_path = sys.executable + ' ' + self.get_bzr_path()
208
 
        os.environ['BZR_REMOTE_PATH'] = bzr_remote_path
 
198
        os.environ['BZR_REMOTE_PATH'] = self.get_bzr_path()
209
199
        try:
210
 
            if sys.platform == 'win32':
211
 
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
212
200
            branch = Branch.open(
213
201
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
214
 
            self.make_read_requests(branch)
 
202
            
 
203
            branch.repository.get_revision_graph()
 
204
            self.assertEqual(None, branch.last_revision())
215
205
            # Check we can perform write operations
216
206
            branch.bzrdir.root_transport.mkdir('foo')
217
207
        finally:
224
214
 
225
215
        self.assertEqual(
226
216
            ['%s serve --inet --directory=/ --allow-writes'
227
 
             % bzr_remote_path],
 
217
             % self.get_bzr_path()],
228
218
            self.command_executed)
229
219