17
17
"""Tests for the smart wire/domain protococl."""
19
from bzrlib import smart, tests
19
from bzrlib import errors, smart, tests
20
20
from bzrlib.smart.request import SmartServerResponse
21
21
import bzrlib.smart.bzrdir
22
import bzrlib.smart.branch
24
25
class TestSmartServerResponse(tests.TestCase):
103
104
self.assertEqual(SmartServerResponse(('ok', reference_url)),
104
105
request.execute(backing.local_abspath('reference')))
108
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithTransport):
110
def test_no_branch(self):
111
"""When there is a bzrdir and no branch, NotBranchError is raised."""
112
backing = self.get_transport()
113
request = smart.branch.SmartServerRequestRevisionHistory(backing)
114
self.make_bzrdir('.')
115
self.assertRaises(errors.NotBranchError,
116
request.execute, backing.local_abspath(''))
118
def test_empty(self):
119
"""For an empty branch, the body is empty."""
120
backing = self.get_transport()
121
request = smart.branch.SmartServerRequestRevisionHistory(backing)
122
self.make_branch('.')
123
self.assertEqual(SmartServerResponse(('ok', ), ''),
124
request.execute(backing.local_abspath('')))
126
def test_not_empty(self):
127
"""For a non-empty branch, the body is empty."""
128
backing = self.get_transport()
129
request = smart.branch.SmartServerRequestRevisionHistory(backing)
130
tree = self.make_branch_and_memory_tree('.')
133
r1 = tree.commit('1st commit')
134
r2 = tree.commit('2nd commit', rev_id=u'\xc8')
136
self.assertEqual(SmartServerResponse(('ok', ),
137
('\x00'.join([r1, r2])).encode('utf8')),
138
request.execute(backing.local_abspath('')))
140
def test_branch_reference(self):
141
"""When there is a branch reference, NotBranchError is raised."""
142
backing = self.get_transport()
143
request = smart.branch.SmartServerRequestRevisionHistory(backing)
144
branch = self.make_branch('branch')
145
checkout = branch.create_checkout('reference',lightweight=True)
146
self.assertRaises(errors.NotBranchError,
147
request.execute, backing.local_abspath('checkout'))
106
150
class TestHandlers(tests.TestCase):
107
151
"""Tests for the request.request_handlers object."""
109
153
def test_registered_methods(self):
110
154
"""Test that known methods are registered to the correct object."""
111
155
self.assertEqual(
156
smart.request.request_handlers.get('Branch.revision_history'),
157
smart.branch.SmartServerRequestRevisionHistory)
112
159
smart.request.request_handlers.get('BzrDir.find_repository'),
113
160
smart.bzrdir.SmartServerRequestFindRepository)
114
161
self.assertEqual(