~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

(andrew) Add Repository.get_rev_id_for_revno HPSS verb (and API).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2018
2018
        self.assertEqual(('AnUnexpectedError',), e.error_tuple)
2019
2019
 
2020
2020
 
 
2021
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
 
2022
 
 
2023
    def test_ok(self):
 
2024
        repo, client = self.setup_fake_client_and_repository('quack')
 
2025
        client.add_expected_call(
 
2026
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
 
2027
            'success', ('ok', 'rev-five'))
 
2028
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
 
2029
        self.assertEqual((True, 'rev-five'), result)
 
2030
        client.finished_test()
 
2031
 
 
2032
    def test_history_incomplete(self):
 
2033
        repo, client = self.setup_fake_client_and_repository('quack')
 
2034
        client.add_expected_call(
 
2035
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
 
2036
            'success', ('history-incomplete', 10, 'rev-ten'))
 
2037
        result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
 
2038
        self.assertEqual((False, (10, 'rev-ten')), result)
 
2039
        client.finished_test()
 
2040
 
 
2041
    def test_history_incomplete_with_fallback(self):
 
2042
        """A 'history-incomplete' response causes the fallback repository to be
 
2043
        queried too, if one is set.
 
2044
        """
 
2045
        # Make a repo with a fallback repo, both using a FakeClient.
 
2046
        format = remote.response_tuple_to_repo_format(
 
2047
            ('yes', 'no', 'yes', 'fake-network-name'))
 
2048
        repo, client = self.setup_fake_client_and_repository('quack')
 
2049
        repo._format = format
 
2050
        fallback_repo, ignored = self.setup_fake_client_and_repository(
 
2051
            'fallback')
 
2052
        fallback_repo._client = client
 
2053
        repo.add_fallback_repository(fallback_repo)
 
2054
        # First the client should ask the primary repo
 
2055
        client.add_expected_call(
 
2056
            'Repository.get_rev_id_for_revno', ('quack/', 1, (42, 'rev-foo')),
 
2057
            'success', ('history-incomplete', 2, 'rev-two'))
 
2058
        # Then it should ask the fallback, using revno/revid from the
 
2059
        # history-incomplete response as the known revno/revid.
 
2060
        client.add_expected_call(
 
2061
            'Repository.get_rev_id_for_revno',('fallback/', 1, (2, 'rev-two')),
 
2062
            'success', ('ok', 'rev-one'))
 
2063
        result = repo.get_rev_id_for_revno(1, (42, 'rev-foo'))
 
2064
        self.assertEqual((True, 'rev-one'), result)
 
2065
        client.finished_test()
 
2066
 
 
2067
    def test_nosuchrevision(self):
 
2068
        # 'nosuchrevision' is returned when the known-revid is not found in the
 
2069
        # remote repo.  The client translates that response to NoSuchRevision.
 
2070
        repo, client = self.setup_fake_client_and_repository('quack')
 
2071
        client.add_expected_call(
 
2072
            'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
 
2073
            'error', ('nosuchrevision', 'rev-foo'))
 
2074
        self.assertRaises(
 
2075
            errors.NoSuchRevision,
 
2076
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
 
2077
        client.finished_test()
 
2078
 
 
2079
 
2021
2080
class TestRepositoryIsShared(TestRemoteRepository):
2022
2081
 
2023
2082
    def test_is_shared(self):