Show More
@@ -20,38 +20,62 b'' | |||
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 | from mock import patch | |
|
23 | from mock import call, patch | |
|
24 | 24 | |
|
25 | 25 | from rhodecode.lib.vcs.backends.base import Reference |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | class TestMercurialRemoteRepoInvalidation(object): |
|
29 |
ref |
|
|
30 | ||
|
31 | @pytest.mark.parametrize('method_name', [ | |
|
29 | default_ref = Reference('branch', 'default', None) | |
|
30 | writing_methods = [ | |
|
32 | 31 | 'bookmark', |
|
33 | 32 | 'commit', |
|
33 | 'merge', | |
|
34 | 34 | 'pull', |
|
35 | 35 | 'pull_cmd', |
|
36 | 'push', | |
|
37 | 36 | 'rebase', |
|
38 | 37 | 'strip', |
|
39 |
' |
|
|
38 | 'tag', | |
|
39 | ] | |
|
40 | ||
|
41 | @pytest.mark.parametrize('method_name, method_args', [ | |
|
42 | ('_local_merge', [default_ref, None, None, None, default_ref]), | |
|
43 | ('_local_pull', ['', default_ref]), | |
|
44 | ('bookmark', [None]), | |
|
45 | ('pull', ['', default_ref]), | |
|
46 | ('remove_tag', ['mytag', None]), | |
|
47 | ('strip', [None]), | |
|
48 | ('tag', ['newtag', None]), | |
|
40 | 49 | ]) |
|
41 | 50 | def test_method_invokes_invalidate_on_remote_repo( |
|
42 | self, method_name, backend_hg): | |
|
51 | self, method_name, method_args, backend_hg): | |
|
52 | """ | |
|
53 | Check that the listed methods are invalidating the VCSServer cache | |
|
54 | after invoking a writing method of their remote repository object. | |
|
43 | 55 |
|
|
44 | Check that the listed methods call invalidate_vcs_cache on their remote | |
|
45 | repo instance. | |
|
46 | """ | |
|
47 | from rhodecode.lib.vcs import client_http | |
|
56 | tags = {'mytag': 'mytag-id'} | |
|
57 | ||
|
58 | def add_tag(name, raw_id, *args, **kwds): | |
|
59 | tags[name] = raw_id | |
|
60 | ||
|
48 | 61 | repo = backend_hg.repo.scm_instance() |
|
49 | remote = repo._remote | |
|
50 | with patch.object(remote, 'invalidate_vcs_cache') as invalidate_cache: | |
|
51 | with patch.object(client_http, '_remote_call'): | |
|
52 | method = getattr(remote, method_name) | |
|
53 | method() | |
|
54 | assert invalidate_cache.called | |
|
62 | with patch.object(repo, '_remote') as remote: | |
|
63 | remote.lookup.return_value = ('commit-id', 'commit-idx') | |
|
64 | remote.tags.return_value = tags | |
|
65 | remote._get_tags.return_value = tags | |
|
66 | remote.tag.side_effect = add_tag | |
|
67 | ||
|
68 | # Invoke method. | |
|
69 | method = getattr(repo, method_name) | |
|
70 | method(*method_args) | |
|
71 | ||
|
72 | # Assert that every "writing" method is followed by an invocation | |
|
73 | # of the cache invalidation method. | |
|
74 | for counter, method_call in enumerate(remote.method_calls): | |
|
75 | call_name = method_call[0] | |
|
76 | if call_name in self.writing_methods: | |
|
77 | next_call = remote.method_calls[counter + 1] | |
|
78 | assert next_call == call.invalidate_vcs_cache() | |
|
55 | 79 | |
|
56 | 80 | def _prepare_shadow_repo(self, pull_request): |
|
57 | 81 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now