~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Aaron Bentley
  • Date: 2008-03-03 16:52:41 UTC
  • mfrom: (3144.3.11 fix-conflict-handling)
  • mto: This revision was merged to the branch mainline in revision 3250.
  • Revision ID: aaron@aaronbentley.com-20080303165241-0k2c7ggs6kr9q6hf
Merge with fix-conflict-handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
Tests for low-level protocol encoding are found in test_smart_transport.
25
25
"""
26
26
 
 
27
import bz2
27
28
from StringIO import StringIO
28
29
import tempfile
29
30
import tarfile
37
38
import bzrlib.smart.bzrdir
38
39
import bzrlib.smart.branch
39
40
import bzrlib.smart.repository
 
41
from bzrlib.tests import (
 
42
    iter_suite_tests,
 
43
    split_suite_by_re,
 
44
    TestScenarioApplier,
 
45
    )
40
46
from bzrlib.util import bencode
41
47
 
42
48
 
 
49
def load_tests(standard_tests, module, loader):
 
50
    """Multiply tests version and protocol consistency."""
 
51
    # FindRepository tests.
 
52
    bzrdir_mod = bzrlib.smart.bzrdir
 
53
    applier = TestScenarioApplier()
 
54
    applier.scenarios = [
 
55
        ("find_repository", {
 
56
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
 
57
        ("find_repositoryV2", {
 
58
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
 
59
        ]
 
60
    to_adapt, result = split_suite_by_re(standard_tests,
 
61
        "TestSmartServerRequestFindRepository")
 
62
    v2_only, v1_and_2 = split_suite_by_re(to_adapt,
 
63
        "_v2")
 
64
    for test in iter_suite_tests(v1_and_2):
 
65
        result.addTests(applier.adapt(test))
 
66
    del applier.scenarios[0]
 
67
    for test in iter_suite_tests(v2_only):
 
68
        result.addTests(applier.adapt(test))
 
69
    return result
 
70
 
 
71
 
43
72
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
44
73
 
45
74
    def setUp(self):
76
105
    def test_no_repository(self):
77
106
        """When there is no repository to be found, ('norepository', ) is returned."""
78
107
        backing = self.get_transport()
79
 
        request = smart.bzrdir.SmartServerRequestFindRepository(backing)
 
108
        request = self._request_class(backing)
80
109
        self.make_bzrdir('.')
81
110
        self.assertEqual(SmartServerResponse(('norepository', )),
82
111
            request.execute(backing.local_abspath('')))
86
115
        # path the repository is being searched on is the same as that that 
87
116
        # the repository is at.
88
117
        backing = self.get_transport()
89
 
        request = smart.bzrdir.SmartServerRequestFindRepository(backing)
 
118
        request = self._request_class(backing)
90
119
        result = self._make_repository_and_result()
91
120
        self.assertEqual(result, request.execute(backing.local_abspath('')))
92
121
        self.make_bzrdir('subdir')
107
136
            subtrees = 'yes'
108
137
        else:
109
138
            subtrees = 'no'
110
 
        return SmartServerResponse(('ok', '', rich_root, subtrees))
 
139
        if (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
 
140
            self._request_class):
 
141
            # All tests so far are on formats, and for non-external
 
142
            # repositories.
 
143
            return SuccessfulSmartServerResponse(
 
144
                ('ok', '', rich_root, subtrees, 'no'))
 
145
        else:
 
146
            return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
111
147
 
112
148
    def test_shared_repository(self):
113
149
        """When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
114
150
        backing = self.get_transport()
115
 
        request = smart.bzrdir.SmartServerRequestFindRepository(backing)
 
151
        request = self._request_class(backing)
116
152
        result = self._make_repository_and_result(shared=True)
117
153
        self.assertEqual(result, request.execute(backing.local_abspath('')))
118
154
        self.make_bzrdir('subdir')
127
163
    def test_rich_root_and_subtree_encoding(self):
128
164
        """Test for the format attributes for rich root and subtree support."""
129
165
        backing = self.get_transport()
130
 
        request = smart.bzrdir.SmartServerRequestFindRepository(backing)
 
166
        request = self._request_class(backing)
131
167
        result = self._make_repository_and_result(format='dirstate-with-subtree')
132
168
        # check the test will be valid
133
169
        self.assertEqual('yes', result.args[2])
134
170
        self.assertEqual('yes', result.args[3])
135
171
        self.assertEqual(result, request.execute(backing.local_abspath('')))
136
172
 
 
173
    def test_supports_external_lookups_no_v2(self):
 
174
        """Test for the supports_external_lookups attribute."""
 
175
        backing = self.get_transport()
 
176
        request = self._request_class(backing)
 
177
        result = self._make_repository_and_result(format='dirstate-with-subtree')
 
178
        # check the test will be valid
 
179
        self.assertEqual('no', result.args[4])
 
180
        self.assertEqual(result, request.execute(backing.local_abspath('')))
 
181
 
137
182
 
138
183
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithTransport):
139
184
 
529
574
            request.execute, backing.local_abspath('subdir'))
530
575
 
531
576
 
 
577
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithTransport):
 
578
 
 
579
    def test_trivial_bzipped(self):
 
580
        # This tests that the wire encoding is actually bzipped
 
581
        backing = self.get_transport()
 
582
        request = smart.repository.SmartServerRepositoryGetParentMap(backing)
 
583
        tree = self.make_branch_and_memory_tree('.')
 
584
 
 
585
        self.assertEqual(None,
 
586
            request.execute(backing.local_abspath(''), 'missing-id'))
 
587
        # Note that it returns a body (of '' bzipped).
 
588
        self.assertEqual(
 
589
            SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
 
590
            request.do_body('\n\n0\n'))
 
591
 
 
592
 
532
593
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
533
594
 
534
595
    def test_none_argument(self):
905
966
            smart.branch.SmartServerBranchRequestUnlock)
906
967
        self.assertEqual(
907
968
            smart.request.request_handlers.get('BzrDir.find_repository'),
908
 
            smart.bzrdir.SmartServerRequestFindRepository)
 
969
            smart.bzrdir.SmartServerRequestFindRepositoryV1)
 
970
        self.assertEqual(
 
971
            smart.request.request_handlers.get('BzrDir.find_repositoryV2'),
 
972
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
909
973
        self.assertEqual(
910
974
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
911
975
            smart.bzrdir.SmartServerRequestInitializeBzrDir)