~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-08-09 15:19:06 UTC
  • mfrom: (2681.1.7 send-bundle)
  • Revision ID: pqm@pqm.ubuntu.com-20070809151906-hdn9oyslf2qib2op
Allow omitting -o for bundle, add --format

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."""
48
48
        result = self.finish_bzr_subprocess(process)
49
49
        self.assertEqual('', result[0])
50
50
        self.assertEqual('', result[1])
51
 
 
 
51
    
52
52
    def assertServerFinishesCleanly(self, process):
53
53
        """Shutdown the bzr serve instance process looking for errors."""
54
54
        # Shutdown the server
57
57
        self.assertEqual('', result[0])
58
58
        self.assertEqual('bzr: interrupted\n', result[1])
59
59
 
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
60
    def start_server_inet(self, extra_options=()):
71
61
        """Start a bzr server subprocess using the --inet option.
72
62
 
80
70
        # Connect to the server
81
71
        # We use this url because while this is no valid URL to connect to this
82
72
        # server instance, the transport needs a URL.
83
 
        url = 'bzr://localhost/'
84
73
        client_medium = medium.SmartSimplePipesClientMedium(
85
 
            process.stdout, process.stdin, url)
86
 
        transport = remote.RemoteTransport(url, medium=client_medium)
 
74
            process.stdout, process.stdin)
 
75
        transport = remote.RemoteTransport(
 
76
            'bzr://localhost/', medium=client_medium)
87
77
        return process, transport
88
78
 
89
79
    def start_server_port(self, extra_options=()):
97
87
        args = ['serve', '--port', 'localhost:0']
98
88
        args.extend(extra_options)
99
89
        process = self.start_bzr_subprocess(args, skip_if_plan_to_signal=True)
100
 
        port_line = process.stderr.readline()
 
90
        port_line = process.stdout.readline()
101
91
        prefix = 'listening on port: '
102
92
        self.assertStartsWith(port_line, prefix)
103
93
        port = int(port_line[len(prefix):])
117
107
 
118
108
        # We get a working branch
119
109
        branch = BzrDir.open_from_transport(transport).open_branch()
120
 
        self.make_read_requests(branch)
 
110
        branch.repository.get_revision_graph()
 
111
        self.assertEqual(_mod_revision.NULL_REVISION,
 
112
                         _mod_revision.ensure_null(branch.last_revision()))
121
113
        self.assertInetServerShutsdownCleanly(process)
122
114
 
123
115
    def test_bzr_serve_port_readonly(self):
135
127
 
136
128
        # Connect to the server
137
129
        branch = Branch.open(url)
138
 
        self.make_read_requests(branch)
 
130
 
 
131
        # We get a working branch
 
132
        branch.repository.get_revision_graph()
 
133
        self.assertEqual(_mod_revision.NULL_REVISION,
 
134
                         _mod_revision.ensure_null(branch.last_revision()))
 
135
 
139
136
        self.assertServerFinishesCleanly(process)
140
137
 
141
138
    def test_bzr_connect_to_bzr_ssh(self):
148
145
        except ParamikoNotPresent:
149
146
            raise TestSkipped('Paramiko not installed')
150
147
        from bzrlib.tests.stub_sftp import StubServer
151
 
 
 
148
        
152
149
        # Make a branch
153
150
        self.make_branch('a_branch')
154
151
 
167
164
                proc = subprocess.Popen(
168
165
                    command, shell=True, stdin=subprocess.PIPE,
169
166
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
170
 
 
 
167
                
171
168
                # XXX: horribly inefficient, not to mention ugly.
172
169
                # Start a thread for each of stdin/out/err, and relay bytes from
173
170
                # the subprocess to channel and vice versa.
200
197
        # Access the branch via a bzr+ssh URL.  The BZR_REMOTE_PATH environment
201
198
        # variable is used to tell bzr what command to run on the remote end.
202
199
        path_to_branch = osutils.abspath('a_branch')
203
 
 
 
200
        
204
201
        orig_bzr_remote_path = os.environ.get('BZR_REMOTE_PATH')
205
202
        bzr_remote_path = self.get_bzr_path()
206
203
        if sys.platform == 'win32':
211
208
                path_to_branch = os.path.splitdrive(path_to_branch)[1]
212
209
            branch = Branch.open(
213
210
                'bzr+ssh://fred:secret@localhost:%d%s' % (port, path_to_branch))
214
 
            self.make_read_requests(branch)
 
211
            
 
212
            branch.repository.get_revision_graph()
 
213
            self.assertEqual(_mod_revision.NULL_REVISION,
 
214
                             _mod_revision.ensure_null(branch.last_revision()))
215
215
            # Check we can perform write operations
216
216
            branch.bzrdir.root_transport.mkdir('foo')
217
217
        finally:
226
226
            ['%s serve --inet --directory=/ --allow-writes'
227
227
             % bzr_remote_path],
228
228
            self.command_executed)
229
 
 
 
229