~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2007-07-11 01:55:33 UTC
  • mto: This revision was merged to the branch mainline in revision 2599.
  • Revision ID: mbp@sourcefrog.net-20070711015533-dzcxkjg0ujh8yuhl
Option help improvements (thanks jamesw)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
18
"""Tests of the bzr serve command."""
26
26
from bzrlib import (
27
27
    errors,
28
28
    osutils,
29
 
    revision as _mod_revision,
30
29
    )
31
30
from bzrlib.branch import Branch
32
31
from bzrlib.bzrdir import BzrDir
48
47
        result = self.finish_bzr_subprocess(process)
49
48
        self.assertEqual('', result[0])
50
49
        self.assertEqual('', result[1])
51
 
 
 
50
    
52
51
    def assertServerFinishesCleanly(self, process):
53
52
        """Shutdown the bzr serve instance process looking for errors."""
54
53
        # Shutdown the server
57
56
        self.assertEqual('', result[0])
58
57
        self.assertEqual('bzr: interrupted\n', result[1])
59
58
 
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
59
    def start_server_inet(self, extra_options=()):
71
60
        """Start a bzr server subprocess using the --inet option.
72
61
 
80
69
        # Connect to the server
81
70
        # We use this url because while this is no valid URL to connect to this
82
71
        # server instance, the transport needs a URL.
83
 
        url = 'bzr://localhost/'
84
72
        client_medium = medium.SmartSimplePipesClientMedium(
85
 
            process.stdout, process.stdin, url)
86
 
        transport = remote.RemoteTransport(url, medium=client_medium)
 
73
            process.stdout, process.stdin)
 
74
        transport = remote.RemoteTransport(
 
75
            'bzr://localhost/', medium=client_medium)
87
76
        return process, transport
88
77
 
89
78
    def start_server_port(self, extra_options=()):
97
86
        args = ['serve', '--port', 'localhost:0']
98
87
        args.extend(extra_options)
99
88
        process = self.start_bzr_subprocess(args, skip_if_plan_to_signal=True)
100
 
        port_line = process.stderr.readline()
 
89
        port_line = process.stdout.readline()
101
90
        prefix = 'listening on port: '
102
91
        self.assertStartsWith(port_line, prefix)
103
92
        port = int(port_line[len(prefix):])
117
106
 
118
107
        # We get a working branch
119
108
        branch = BzrDir.open_from_transport(transport).open_branch()
120
 
        self.make_read_requests(branch)
 
109
        branch.repository.get_revision_graph()
 
110
        self.assertEqual(None, branch.last_revision())
121
111
        self.assertInetServerShutsdownCleanly(process)
122
112
 
123
113
    def test_bzr_serve_port_readonly(self):
135
125
 
136
126
        # Connect to the server
137
127
        branch = Branch.open(url)
138
 
        self.make_read_requests(branch)
139
 
        self.assertServerFinishesCleanly(process)
140
 
 
141
 
    def test_bzr_serve_supports_protocol(self):
142
 
        # Make a branch
143
 
        self.make_branch('.')
144
 
 
145
 
        process, url = self.start_server_port(['--allow-writes',
146
 
                                               '--protocol=bzr'])
147
 
 
148
 
        # Connect to the server
149
 
        branch = Branch.open(url)
150
 
        self.make_read_requests(branch)
 
128
 
 
129
        # We get a working branch
 
130
        branch.repository.get_revision_graph()
 
131
        self.assertEqual(None, branch.last_revision())
 
132
 
151
133
        self.assertServerFinishesCleanly(process)
152
134
 
153
135
    def test_bzr_connect_to_bzr_ssh(self):
160
142
        except ParamikoNotPresent:
161
143
            raise TestSkipped('Paramiko not installed')
162
144
        from bzrlib.tests.stub_sftp import StubServer
163
 
 
 
145
        
164
146
        # Make a branch
165
147
        self.make_branch('a_branch')
166
148
 
179
161
                proc = subprocess.Popen(
180
162
                    command, shell=True, stdin=subprocess.PIPE,
181
163
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
182
 
 
 
164
                
183
165
                # XXX: horribly inefficient, not to mention ugly.
184
166
                # Start a thread for each of stdin/out/err, and relay bytes from
185
167
                # the subprocess to channel and vice versa.
212
194
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
213
195
        # variable is used to tell bzr what command to run on the remote end.
214
196
        path_to_branch = osutils.abspath('a_branch')
215
 
 
 
197
        
216
198
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
217
199
        bzr_remote_path = self.get_bzr_path()
218
200
        if sys.platform == 'win32':
223
205
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
224
206
            branch = Branch.open(
225
207
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
226
 
            self.make_read_requests(branch)
 
208
            
 
209
            branch.repository.get_revision_graph()
 
210
            self.assertEqual(None, branch.last_revision())
227
211
            # Check we can perform write operations
228
212
            branch.bzrdir.root_transport.mkdir('foo')
229
213
        finally:
238
222
            ['%s serve --inet --directory=/ --allow-writes'
239
223
             % bzr_remote_path],
240
224
            self.command_executed)
241
 
 
 
225