1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# Copyright (C) 2006 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""Tests for the smart wire/domain protococl."""
from bzrlib import smart, tests
from bzrlib.smart.request import SmartServerResponse
import bzrlib.smart.bzrdir
class TestSmartServerResponse(tests.TestCase):
def test__eq__(self):
self.assertEqual(SmartServerResponse(('ok', )),
SmartServerResponse(('ok', )))
self.assertEqual(SmartServerResponse(('ok', ), 'body'),
SmartServerResponse(('ok', ), 'body'))
self.assertNotEqual(SmartServerResponse(('ok', )),
SmartServerResponse(('notok', )))
self.assertNotEqual(SmartServerResponse(('ok', ), 'body'),
SmartServerResponse(('ok', )))
class TestSmartServerRequestFindRepository(tests.TestCaseWithTransport):
def test_no_repository(self):
"""When there is no repository to be found, ('norepository', ) is returned."""
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
self.make_bzrdir('.')
self.assertEqual(SmartServerResponse(('norepository', )),
request.execute(backing.local_abspath('')))
def test_nonshared_repository(self):
# nonshared repositorys only allow 'find' to return a handle when the
# path the repository is being searched on is the same as that that
# the repository is at.
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
self.make_repository('.')
self.assertEqual(SmartServerResponse(('ok', '')),
request.execute(backing.local_abspath('')))
self.make_bzrdir('subdir')
self.assertEqual(SmartServerResponse(('norepository', )),
request.execute(backing.local_abspath('subdir')))
def test_shared_repository(self):
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestFindRepository(backing)
self.make_repository('.', shared=True)
self.assertEqual(SmartServerResponse(('ok', '')),
request.execute(backing.local_abspath('')))
self.make_bzrdir('subdir')
self.assertEqual(SmartServerResponse(('ok', '..')),
request.execute(backing.local_abspath('subdir')))
self.make_bzrdir('subdir/deeper')
self.assertEqual(SmartServerResponse(('ok', '../..')),
request.execute(backing.local_abspath('subdir/deeper')))
class TestSmartServerRequestOpenBranch(tests.TestCaseWithTransport):
def test_no_branch(self):
"""When there is no branch, ('nobranch', ) is returned."""
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
self.make_bzrdir('.')
self.assertEqual(SmartServerResponse(('nobranch', )),
request.execute(backing.local_abspath('')))
def test_branch(self):
"""When there is a branch, 'ok' is returned."""
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
self.make_branch('.')
self.assertEqual(SmartServerResponse(('ok', '')),
request.execute(backing.local_abspath('')))
def test_branch_reference(self):
"""When there is a branch reference, the reference URL is returned."""
backing = self.get_transport()
request = smart.bzrdir.SmartServerRequestOpenBranch(backing)
branch = self.make_branch('branch')
checkout = branch.create_checkout('reference',lightweight=True)
# TODO: once we have an API to probe for references of any sort, we
# can use it here.
reference_url = backing.abspath('branch') + '/'
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
self.assertEqual(SmartServerResponse(('ok', reference_url)),
request.execute(backing.local_abspath('reference')))
class TestHandlers(tests.TestCase):
"""Tests for the request.request_handlers object."""
def test_registered_methods(self):
"""Test that known methods are registered to the correct object."""
self.assertEqual(
smart.request.request_handlers.get('BzrDir.find_repository'),
smart.bzrdir.SmartServerRequestFindRepository)
self.assertEqual(
smart.request.request_handlers.get('BzrDir.open_branch'),
smart.bzrdir.SmartServerRequestOpenBranch)
|