~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

Various hopefully improvements, but wsgi is broken, handing over to spiv :).

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the smart wire/domain protococl."""
18
18
 
19
 
from bzrlib import errors, smart, tests
 
19
from bzrlib import bzrdir, errors, smart, tests
20
20
from bzrlib.smart.request import SmartServerResponse
21
21
import bzrlib.smart.bzrdir
22
22
import bzrlib.smart.branch
112
112
                u'\xc8abc'.encode('utf8')))
113
113
 
114
114
 
 
115
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
 
116
 
 
117
    def test_empty_dir(self):
 
118
        """Initializing an empty dir should succeed and do it."""
 
119
        backing = self.get_transport()
 
120
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
 
121
        self.assertEqual(SmartServerResponse(('ok', )),
 
122
            request.execute(backing.local_abspath('.')))
 
123
        made_dir = bzrdir.BzrDir.open_from_transport(backing)
 
124
        # no branch, tree or repository is expected with the current 
 
125
        # default formart.
 
126
        self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
 
127
        self.assertRaises(errors.NotBranchError, made_dir.open_branch)
 
128
        self.assertRaises(errors.NoRepositoryPresent, made_dir.open_repository)
 
129
 
 
130
    def test_missing_dir(self):
 
131
        """Initializing a missing directory should fail like the bzrdir api."""
 
132
        backing = self.get_transport()
 
133
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
 
134
        self.assertRaises(errors.NoSuchFile,
 
135
            request.execute, backing.local_abspath('subdir'))
 
136
 
 
137
    def test_initialized_dir(self):
 
138
        """Initializing an extant bzrdir should fail like the bzrdir api."""
 
139
        backing = self.get_transport()
 
140
        request = smart.bzrdir.SmartServerRequestInitializeBzrDir(backing)
 
141
        self.make_bzrdir('subdir')
 
142
        self.assertRaises(errors.FileExists,
 
143
            request.execute, backing.local_abspath('subdir'))
 
144
 
 
145
 
115
146
class TestSmartServerRequestOpenBranch(tests.TestCaseWithTransport):
116
147
 
117
148
    def test_no_branch(self):
198
229
            smart.request.request_handlers.get('BzrDir.find_repository'),
199
230
            smart.bzrdir.SmartServerRequestFindRepository)
200
231
        self.assertEqual(
 
232
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
 
233
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
 
234
        self.assertEqual(
201
235
            smart.request.request_handlers.get('BzrDir.open_branch'),
202
236
            smart.bzrdir.SmartServerRequestOpenBranch)
203
237
        self.assertEqual(