~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

Implement a remote Repository.has_revision method.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib.smart.request import SmartServerResponse
21
21
import bzrlib.smart.bzrdir
22
22
import bzrlib.smart.branch
 
23
import bzrlib.smart.repository
23
24
 
24
25
 
25
26
class TestSmartServerResponse(tests.TestCase):
73
74
            request.execute(backing.local_abspath('subdir/deeper')))
74
75
 
75
76
 
 
77
class TestSmartServerRequestHasRevision(tests.TestCaseWithTransport):
 
78
 
 
79
    def test_no_repository(self):
 
80
        """NoRepositoryPresent is raised when there is no repository."""
 
81
        # we test this using a shared repository above the named path,
 
82
        # thus checking the right search logic is used.
 
83
        backing = self.get_transport()
 
84
        request = smart.repository.SmartServerRequestHasRevision(backing)
 
85
        self.make_repository('.', shared=True)
 
86
        self.make_bzrdir('subdir')
 
87
        self.assertRaises(errors.NoRepositoryPresent,
 
88
            request.execute, backing.local_abspath('subdir'), 'revid')
 
89
 
 
90
    def test_missing_revision(self):
 
91
        """For a missing revision, ('no', ) is returned."""
 
92
        backing = self.get_transport()
 
93
        request = smart.repository.SmartServerRequestHasRevision(backing)
 
94
        self.make_repository('.')
 
95
        self.assertEqual(SmartServerResponse(('no', )),
 
96
            request.execute(backing.local_abspath(''), 'revid'))
 
97
 
 
98
    def test_present_revision(self):
 
99
        """For a present revision, ('ok', ) is returned."""
 
100
        backing = self.get_transport()
 
101
        request = smart.repository.SmartServerRequestHasRevision(backing)
 
102
        tree = self.make_branch_and_memory_tree('.')
 
103
        tree.lock_write()
 
104
        tree.add('')
 
105
        r1 = tree.commit('a commit', rev_id=u'\xc8abc')
 
106
        tree.unlock()
 
107
        self.assertTrue(tree.branch.repository.has_revision(u'\xc8abc'))
 
108
        self.assertEqual(SmartServerResponse(('ok', )),
 
109
            request.execute(backing.local_abspath(''),
 
110
                u'\xc8abc'.encode('utf8')))
 
111
 
 
112
 
76
113
class TestSmartServerRequestOpenBranch(tests.TestCaseWithTransport):
77
114
 
78
115
    def test_no_branch(self):
161
198
        self.assertEqual(
162
199
            smart.request.request_handlers.get('BzrDir.open_branch'),
163
200
            smart.bzrdir.SmartServerRequestOpenBranch)
 
201
        self.assertEqual(
 
202
            smart.request.request_handlers.get('Repository.has_revision'),
 
203
            smart.repository.SmartServerRequestHasRevision)