Show More
@@ -32,7 +32,7 b' use = egg:waitress#main' | |||||
32 | ### LOGGING CONFIGURATION #### |
|
32 | ### LOGGING CONFIGURATION #### | |
33 | ################################ |
|
33 | ################################ | |
34 | [loggers] |
|
34 | [loggers] | |
35 |
keys = root, vcsserver, |
|
35 | keys = root, vcsserver, beaker | |
36 |
|
36 | |||
37 | [handlers] |
|
37 | [handlers] | |
38 | keys = console |
|
38 | keys = console | |
@@ -59,12 +59,6 b' handlers =' | |||||
59 | qualname = beaker |
|
59 | qualname = beaker | |
60 | propagate = 1 |
|
60 | propagate = 1 | |
61 |
|
61 | |||
62 | [logger_pyro4] |
|
|||
63 | level = DEBUG |
|
|||
64 | handlers = |
|
|||
65 | qualname = Pyro4 |
|
|||
66 | propagate = 1 |
|
|||
67 |
|
||||
68 |
|
62 | |||
69 | ############## |
|
63 | ############## | |
70 | ## HANDLERS ## |
|
64 | ## HANDLERS ## |
@@ -56,7 +56,7 b' beaker.cache.repo_object.enabled = true' | |||||
56 | ### LOGGING CONFIGURATION #### |
|
56 | ### LOGGING CONFIGURATION #### | |
57 | ################################ |
|
57 | ################################ | |
58 | [loggers] |
|
58 | [loggers] | |
59 |
keys = root, vcsserver, |
|
59 | keys = root, vcsserver, beaker | |
60 |
|
60 | |||
61 | [handlers] |
|
61 | [handlers] | |
62 | keys = console |
|
62 | keys = console | |
@@ -83,12 +83,6 b' handlers =' | |||||
83 | qualname = beaker |
|
83 | qualname = beaker | |
84 | propagate = 1 |
|
84 | propagate = 1 | |
85 |
|
85 | |||
86 | [logger_pyro4] |
|
|||
87 | level = DEBUG |
|
|||
88 | handlers = |
|
|||
89 | qualname = Pyro4 |
|
|||
90 | propagate = 1 |
|
|||
91 |
|
||||
92 |
|
86 | |||
93 | ############## |
|
87 | ############## | |
94 | ## HANDLERS ## |
|
88 | ## HANDLERS ## |
@@ -67,19 +67,6 b'' | |||||
67 | license = [ pkgs.lib.licenses.mit ]; |
|
67 | license = [ pkgs.lib.licenses.mit ]; | |
68 | }; |
|
68 | }; | |
69 | }; |
|
69 | }; | |
70 | Pyro4 = super.buildPythonPackage { |
|
|||
71 | name = "Pyro4-4.41"; |
|
|||
72 | buildInputs = with self; []; |
|
|||
73 | doCheck = false; |
|
|||
74 | propagatedBuildInputs = with self; [serpent]; |
|
|||
75 | src = fetchurl { |
|
|||
76 | url = "https://pypi.python.org/packages/56/2b/89b566b4bf3e7f8ba790db2d1223852f8cb454c52cab7693dd41f608ca2a/Pyro4-4.41.tar.gz"; |
|
|||
77 | md5 = "ed69e9bfafa9c06c049a87cb0c4c2b6c"; |
|
|||
78 | }; |
|
|||
79 | meta = { |
|
|||
80 | license = [ pkgs.lib.licenses.mit ]; |
|
|||
81 | }; |
|
|||
82 | }; |
|
|||
83 | WebOb = super.buildPythonPackage { |
|
70 | WebOb = super.buildPythonPackage { | |
84 | name = "WebOb-1.3.1"; |
|
71 | name = "WebOb-1.3.1"; | |
85 | buildInputs = with self; []; |
|
72 | buildInputs = with self; []; | |
@@ -591,25 +578,12 b'' | |||||
591 | name = "rhodecode-vcsserver-4.8.0"; |
|
578 | name = "rhodecode-vcsserver-4.8.0"; | |
592 | buildInputs = with self; [pytest py pytest-cov pytest-sugar pytest-runner pytest-catchlog pytest-profiling gprof2dot pytest-timeout mock WebTest cov-core coverage configobj]; |
|
579 | buildInputs = with self; [pytest py pytest-cov pytest-sugar pytest-runner pytest-catchlog pytest-profiling gprof2dot pytest-timeout mock WebTest cov-core coverage configobj]; | |
593 | doCheck = true; |
|
580 | doCheck = true; | |
594 |
propagatedBuildInputs = with self; [Beaker configobj decorator dulwich hgsubversion infrae.cache mercurial msgpack-python pyramid pyramid-jinja2 pyramid-mako repoze.lru simplejson subprocess32 subvertpy six translationstring WebOb wheel zope.deprecation zope.interface ipdb ipython gevent greenlet gunicorn waitress |
|
581 | propagatedBuildInputs = with self; [Beaker configobj decorator dulwich hgsubversion infrae.cache mercurial msgpack-python pyramid pyramid-jinja2 pyramid-mako repoze.lru simplejson subprocess32 subvertpy six translationstring WebOb wheel zope.deprecation zope.interface ipdb ipython gevent greenlet gunicorn waitress pytest py pytest-cov pytest-sugar pytest-runner pytest-catchlog pytest-profiling gprof2dot pytest-timeout mock WebTest cov-core coverage]; | |
595 | src = ./.; |
|
582 | src = ./.; | |
596 | meta = { |
|
583 | meta = { | |
597 | license = [ { fullName = "GPL V3"; } { fullName = "GNU General Public License v3 or later (GPLv3+)"; } ]; |
|
584 | license = [ { fullName = "GPL V3"; } { fullName = "GNU General Public License v3 or later (GPLv3+)"; } ]; | |
598 | }; |
|
585 | }; | |
599 | }; |
|
586 | }; | |
600 | serpent = super.buildPythonPackage { |
|
|||
601 | name = "serpent-1.15"; |
|
|||
602 | buildInputs = with self; []; |
|
|||
603 | doCheck = false; |
|
|||
604 | propagatedBuildInputs = with self; []; |
|
|||
605 | src = fetchurl { |
|
|||
606 | url = "https://pypi.python.org/packages/7b/38/b2b27673a882ff2ea5871bb3e3e6b496ebbaafd1612e51990ffb158b9254/serpent-1.15.tar.gz"; |
|
|||
607 | md5 = "e27b1aad5c218e16442f52abb7c7053a"; |
|
|||
608 | }; |
|
|||
609 | meta = { |
|
|||
610 | license = [ pkgs.lib.licenses.mit ]; |
|
|||
611 | }; |
|
|||
612 | }; |
|
|||
613 | setuptools = super.buildPythonPackage { |
|
587 | setuptools = super.buildPythonPackage { | |
614 | name = "setuptools-30.1.0"; |
|
588 | name = "setuptools-30.1.0"; | |
615 | buildInputs = with self; []; |
|
589 | buildInputs = with self; []; |
@@ -35,9 +35,5 b' greenlet==0.4.10' | |||||
35 | gunicorn==19.6.0 |
|
35 | gunicorn==19.6.0 | |
36 | waitress==1.0.1 |
|
36 | waitress==1.0.1 | |
37 |
|
37 | |||
38 | # Pyro/Deprecated TODO(Marcink): remove in 4.7 release. |
|
|||
39 | Pyro4==4.41 |
|
|||
40 | serpent==1.15 |
|
|||
41 |
|
||||
42 | ## test related requirements |
|
38 | ## test related requirements | |
43 | -r requirements_test.txt |
|
39 | -r requirements_test.txt |
@@ -26,7 +26,7 b' beaker.cache.repo_object.enabled = true' | |||||
26 | ### LOGGING CONFIGURATION #### |
|
26 | ### LOGGING CONFIGURATION #### | |
27 | ################################ |
|
27 | ################################ | |
28 | [loggers] |
|
28 | [loggers] | |
29 |
keys = root, vcsserver, |
|
29 | keys = root, vcsserver, beaker | |
30 |
|
30 | |||
31 | [handlers] |
|
31 | [handlers] | |
32 | keys = console |
|
32 | keys = console | |
@@ -53,12 +53,6 b' handlers =' | |||||
53 | qualname = beaker |
|
53 | qualname = beaker | |
54 | propagate = 1 |
|
54 | propagate = 1 | |
55 |
|
55 | |||
56 | [logger_pyro4] |
|
|||
57 | level = DEBUG |
|
|||
58 | handlers = |
|
|||
59 | qualname = Pyro4 |
|
|||
60 | propagate = 1 |
|
|||
61 |
|
||||
62 |
|
56 | |||
63 | ############## |
|
57 | ############## | |
64 | ## HANDLERS ## |
|
58 | ## HANDLERS ## |
@@ -298,7 +298,7 b' class HgRemote(object):' | |||||
298 | ctx = repo[revision] |
|
298 | ctx = repo[revision] | |
299 | status = repo[ctx.p1().node()].status(other=ctx.node()) |
|
299 | status = repo[ctx.p1().node()].status(other=ctx.node()) | |
300 | # object of status (odd, custom named tuple in mercurial) is not |
|
300 | # object of status (odd, custom named tuple in mercurial) is not | |
301 |
# correctly serializable |
|
301 | # correctly serializable, we make it a list, as the underling | |
302 | # API expects this to be a list |
|
302 | # API expects this to be a list | |
303 | return list(status) |
|
303 | return list(status) | |
304 |
|
304 |
@@ -30,7 +30,6 b' from httplib import HTTPConnection' | |||||
30 |
|
30 | |||
31 | import mercurial.scmutil |
|
31 | import mercurial.scmutil | |
32 | import mercurial.node |
|
32 | import mercurial.node | |
33 | import Pyro4 |
|
|||
34 | import simplejson as json |
|
33 | import simplejson as json | |
35 |
|
34 | |||
36 | from vcsserver import exceptions |
|
35 | from vcsserver import exceptions | |
@@ -68,15 +67,6 b' class HooksDummyClient(object):' | |||||
68 | return getattr(hooks, hook_name)(extras) |
|
67 | return getattr(hooks, hook_name)(extras) | |
69 |
|
68 | |||
70 |
|
69 | |||
71 | class HooksPyro4Client(object): |
|
|||
72 | def __init__(self, hooks_uri): |
|
|||
73 | self.hooks_uri = hooks_uri |
|
|||
74 |
|
||||
75 | def __call__(self, hook_name, extras): |
|
|||
76 | with Pyro4.Proxy(self.hooks_uri) as hooks: |
|
|||
77 | return getattr(hooks, hook_name)(extras) |
|
|||
78 |
|
||||
79 |
|
||||
80 | class RemoteMessageWriter(object): |
|
70 | class RemoteMessageWriter(object): | |
81 | """Writer base class.""" |
|
71 | """Writer base class.""" | |
82 | def write(message): |
|
72 | def write(message): | |
@@ -126,11 +116,7 b' def _handle_exception(result):' | |||||
126 | def _get_hooks_client(extras): |
|
116 | def _get_hooks_client(extras): | |
127 | if 'hooks_uri' in extras: |
|
117 | if 'hooks_uri' in extras: | |
128 | protocol = extras.get('hooks_protocol') |
|
118 | protocol = extras.get('hooks_protocol') | |
129 | return ( |
|
119 | return HooksHttpClient(extras['hooks_uri']) | |
130 | HooksHttpClient(extras['hooks_uri']) |
|
|||
131 | if protocol == 'http' |
|
|||
132 | else HooksPyro4Client(extras['hooks_uri']) |
|
|||
133 | ) |
|
|||
134 | else: |
|
120 | else: | |
135 | return HooksDummyClient(extras['hooks_module']) |
|
121 | return HooksDummyClient(extras['hooks_module']) | |
136 |
|
122 |
@@ -15,16 +15,5 b'' | |||||
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 |
|
||||
19 | PYRO_PORT = 9900 |
|
|||
20 |
|
||||
21 | PYRO_GIT = 'git_remote' |
|
|||
22 | PYRO_HG = 'hg_remote' |
|
|||
23 | PYRO_SVN = 'svn_remote' |
|
|||
24 | PYRO_VCSSERVER = 'vcs_server' |
|
|||
25 | PYRO_GIT_REMOTE_WSGI = 'git_remote_wsgi' |
|
|||
26 | PYRO_HG_REMOTE_WSGI = 'hg_remote_wsgi' |
|
|||
27 |
|
||||
28 | WIRE_ENCODING = 'UTF-8' |
|
18 | WIRE_ENCODING = 'UTF-8' | |
29 |
|
||||
30 | GIT_EXECUTABLE = 'git' |
|
19 | GIT_EXECUTABLE = 'git' |
@@ -29,46 +29,6 b' import simplejson as json' | |||||
29 | from vcsserver import hooks |
|
29 | from vcsserver import hooks | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | class HooksStub(object): |
|
|||
33 | """ |
|
|||
34 | Simulates a Proy4.Proxy object. |
|
|||
35 |
|
||||
36 | Will always return `result`, no matter which hook has been called on it. |
|
|||
37 | """ |
|
|||
38 |
|
||||
39 | def __init__(self, result): |
|
|||
40 | self._result = result |
|
|||
41 |
|
||||
42 | def __call__(self, hooks_uri): |
|
|||
43 | return self |
|
|||
44 |
|
||||
45 | def __enter__(self): |
|
|||
46 | return self |
|
|||
47 |
|
||||
48 | def __exit__(self, exc_type, exc_value, traceback): |
|
|||
49 | pass |
|
|||
50 |
|
||||
51 | def __getattr__(self, name): |
|
|||
52 | return mock.Mock(return_value=self._result) |
|
|||
53 |
|
||||
54 |
|
||||
55 | @contextlib.contextmanager |
|
|||
56 | def mock_hook_response( |
|
|||
57 | status=0, output='', exception=None, exception_args=None): |
|
|||
58 | response = { |
|
|||
59 | 'status': status, |
|
|||
60 | 'output': output, |
|
|||
61 | } |
|
|||
62 | if exception: |
|
|||
63 | response.update({ |
|
|||
64 | 'exception': exception, |
|
|||
65 | 'exception_args': exception_args, |
|
|||
66 | }) |
|
|||
67 |
|
||||
68 | with mock.patch('Pyro4.Proxy', HooksStub(response)): |
|
|||
69 | yield |
|
|||
70 |
|
||||
71 |
|
||||
72 | def get_hg_ui(extras=None): |
|
32 | def get_hg_ui(extras=None): | |
73 | """Create a Config object with a valid RC_SCM_DATA entry.""" |
|
33 | """Create a Config object with a valid RC_SCM_DATA entry.""" | |
74 | extras = extras or {} |
|
34 | extras = extras or {} | |
@@ -89,126 +49,6 b' def get_hg_ui(extras=None):' | |||||
89 | return hg_ui |
|
49 | return hg_ui | |
90 |
|
50 | |||
91 |
|
51 | |||
92 | def test_call_hook_no_error(capsys): |
|
|||
93 | extras = { |
|
|||
94 | 'hooks_uri': 'fake_hook_uri', |
|
|||
95 | } |
|
|||
96 | expected_output = 'My mock outptut' |
|
|||
97 | writer = mock.Mock() |
|
|||
98 |
|
||||
99 | with mock_hook_response(status=1, output=expected_output): |
|
|||
100 | hooks._call_hook('hook_name', extras, writer) |
|
|||
101 |
|
||||
102 | out, err = capsys.readouterr() |
|
|||
103 |
|
||||
104 | writer.write.assert_called_with(expected_output) |
|
|||
105 | assert err == '' |
|
|||
106 |
|
||||
107 |
|
||||
108 | def test_call_hook_with_exception(capsys): |
|
|||
109 | extras = { |
|
|||
110 | 'hooks_uri': 'fake_hook_uri', |
|
|||
111 | } |
|
|||
112 | expected_output = 'My mock outptut' |
|
|||
113 | writer = mock.Mock() |
|
|||
114 |
|
||||
115 | with mock_hook_response(status=1, output=expected_output, |
|
|||
116 | exception='TypeError', |
|
|||
117 | exception_args=('Mock exception', )): |
|
|||
118 | with pytest.raises(Exception) as excinfo: |
|
|||
119 | hooks._call_hook('hook_name', extras, writer) |
|
|||
120 |
|
||||
121 | assert excinfo.type == Exception |
|
|||
122 | assert 'Mock exception' in str(excinfo.value) |
|
|||
123 |
|
||||
124 | out, err = capsys.readouterr() |
|
|||
125 |
|
||||
126 | writer.write.assert_called_with(expected_output) |
|
|||
127 | assert err == '' |
|
|||
128 |
|
||||
129 |
|
||||
130 | def test_call_hook_with_locked_exception(capsys): |
|
|||
131 | extras = { |
|
|||
132 | 'hooks_uri': 'fake_hook_uri', |
|
|||
133 | } |
|
|||
134 | expected_output = 'My mock outptut' |
|
|||
135 | writer = mock.Mock() |
|
|||
136 |
|
||||
137 | with mock_hook_response(status=1, output=expected_output, |
|
|||
138 | exception='HTTPLockedRC', |
|
|||
139 | exception_args=('message',)): |
|
|||
140 | with pytest.raises(Exception) as excinfo: |
|
|||
141 | hooks._call_hook('hook_name', extras, writer) |
|
|||
142 |
|
||||
143 | assert excinfo.value._vcs_kind == 'repo_locked' |
|
|||
144 | assert 'message' == str(excinfo.value) |
|
|||
145 |
|
||||
146 | out, err = capsys.readouterr() |
|
|||
147 |
|
||||
148 | writer.write.assert_called_with(expected_output) |
|
|||
149 | assert err == '' |
|
|||
150 |
|
||||
151 |
|
||||
152 | def test_call_hook_with_stdout(): |
|
|||
153 | extras = { |
|
|||
154 | 'hooks_uri': 'fake_hook_uri', |
|
|||
155 | } |
|
|||
156 | expected_output = 'My mock outptut' |
|
|||
157 |
|
||||
158 | stdout = io.BytesIO() |
|
|||
159 | with mock_hook_response(status=1, output=expected_output): |
|
|||
160 | hooks._call_hook('hook_name', extras, stdout) |
|
|||
161 |
|
||||
162 | assert stdout.getvalue() == expected_output |
|
|||
163 |
|
||||
164 |
|
||||
165 | def test_repo_size(): |
|
|||
166 | hg_ui = get_hg_ui() |
|
|||
167 |
|
||||
168 | with mock_hook_response(status=1): |
|
|||
169 | assert hooks.repo_size(hg_ui, None) == 1 |
|
|||
170 |
|
||||
171 |
|
||||
172 | def test_pre_pull(): |
|
|||
173 | hg_ui = get_hg_ui() |
|
|||
174 |
|
||||
175 | with mock_hook_response(status=1): |
|
|||
176 | assert hooks.pre_pull(hg_ui, None) == 1 |
|
|||
177 |
|
||||
178 |
|
||||
179 | def test_post_pull(): |
|
|||
180 | hg_ui = get_hg_ui() |
|
|||
181 |
|
||||
182 | with mock_hook_response(status=1): |
|
|||
183 | assert hooks.post_pull(hg_ui, None) == 1 |
|
|||
184 |
|
||||
185 |
|
||||
186 | def test_pre_push(): |
|
|||
187 | hg_ui = get_hg_ui() |
|
|||
188 |
|
||||
189 | with mock_hook_response(status=1): |
|
|||
190 | assert hooks.pre_push(hg_ui, None) == 1 |
|
|||
191 |
|
||||
192 |
|
||||
193 | def test_post_push(): |
|
|||
194 | hg_ui = get_hg_ui() |
|
|||
195 |
|
||||
196 | with mock_hook_response(status=1): |
|
|||
197 | with mock.patch('vcsserver.hooks._rev_range_hash', return_value=[]): |
|
|||
198 | assert hooks.post_push(hg_ui, None, None) == 1 |
|
|||
199 |
|
||||
200 |
|
||||
201 | def test_git_pre_receive(): |
|
|||
202 | extras = { |
|
|||
203 | 'hooks': ['push'], |
|
|||
204 | 'hooks_uri': 'fake_hook_uri', |
|
|||
205 | } |
|
|||
206 | with mock_hook_response(status=1): |
|
|||
207 | response = hooks.git_pre_receive(None, None, |
|
|||
208 | {'RC_SCM_DATA': json.dumps(extras)}) |
|
|||
209 | assert response == 1 |
|
|||
210 |
|
||||
211 |
|
||||
212 | def test_git_pre_receive_is_disabled(): |
|
52 | def test_git_pre_receive_is_disabled(): | |
213 | extras = {'hooks': ['pull']} |
|
53 | extras = {'hooks': ['pull']} | |
214 | response = hooks.git_pre_receive(None, None, |
|
54 | response = hooks.git_pre_receive(None, None, | |
@@ -217,18 +57,6 b' def test_git_pre_receive_is_disabled():' | |||||
217 | assert response == 0 |
|
57 | assert response == 0 | |
218 |
|
58 | |||
219 |
|
59 | |||
220 | def test_git_post_receive_no_subprocess_call(): |
|
|||
221 | extras = { |
|
|||
222 | 'hooks': ['push'], |
|
|||
223 | 'hooks_uri': 'fake_hook_uri', |
|
|||
224 | } |
|
|||
225 | # Setting revision_lines to '' avoid all subprocess_calls |
|
|||
226 | with mock_hook_response(status=1): |
|
|||
227 | response = hooks.git_post_receive(None, '', |
|
|||
228 | {'RC_SCM_DATA': json.dumps(extras)}) |
|
|||
229 | assert response == 1 |
|
|||
230 |
|
||||
231 |
|
||||
232 | def test_git_post_receive_is_disabled(): |
|
60 | def test_git_post_receive_is_disabled(): | |
233 | extras = {'hooks': ['pull']} |
|
61 | extras = {'hooks': ['pull']} | |
234 | response = hooks.git_post_receive(None, '', |
|
62 | response = hooks.git_post_receive(None, '', | |
@@ -279,122 +107,16 b' def test_repo_size_exception_does_not_af' | |||||
279 | assert result == status |
|
107 | assert result == status | |
280 |
|
108 | |||
281 |
|
109 | |||
282 | @mock.patch('vcsserver.hooks._run_command') |
|
|||
283 | def test_git_post_receive_first_commit_sub_branch(cmd_mock): |
|
|||
284 | def cmd_mock_returns(args): |
|
|||
285 | if args == ['git', 'show', 'HEAD']: |
|
|||
286 | raise |
|
|||
287 | if args == ['git', 'for-each-ref', '--format=%(refname)', |
|
|||
288 | 'refs/heads/*']: |
|
|||
289 | return 'refs/heads/test-branch2/sub-branch' |
|
|||
290 | if args == ['git', 'log', '--reverse', '--pretty=format:%H', '--', |
|
|||
291 | '9695eef57205c17566a3ae543be187759b310bb7', '--not', |
|
|||
292 | 'refs/heads/test-branch2/sub-branch']: |
|
|||
293 | return '' |
|
|||
294 |
|
||||
295 | cmd_mock.side_effect = cmd_mock_returns |
|
|||
296 |
|
||||
297 | extras = { |
|
|||
298 | 'hooks': ['push'], |
|
|||
299 | 'hooks_uri': 'fake_hook_uri' |
|
|||
300 | } |
|
|||
301 | rev_lines = ['0000000000000000000000000000000000000000 ' |
|
|||
302 | '9695eef57205c17566a3ae543be187759b310bb7 ' |
|
|||
303 | 'refs/heads/feature/sub-branch\n'] |
|
|||
304 | with mock_hook_response(status=0): |
|
|||
305 | response = hooks.git_post_receive(None, rev_lines, |
|
|||
306 | {'RC_SCM_DATA': json.dumps(extras)}) |
|
|||
307 |
|
||||
308 | calls = [ |
|
|||
309 | mock.call(['git', 'show', 'HEAD']), |
|
|||
310 | mock.call(['git', 'symbolic-ref', 'HEAD', |
|
|||
311 | 'refs/heads/feature/sub-branch']), |
|
|||
312 | ] |
|
|||
313 | cmd_mock.assert_has_calls(calls, any_order=True) |
|
|||
314 | assert response == 0 |
|
|||
315 |
|
||||
316 |
|
||||
317 | @mock.patch('vcsserver.hooks._run_command') |
|
|||
318 | def test_git_post_receive_first_commit_revs(cmd_mock): |
|
|||
319 | extras = { |
|
|||
320 | 'hooks': ['push'], |
|
|||
321 | 'hooks_uri': 'fake_hook_uri' |
|
|||
322 | } |
|
|||
323 | rev_lines = [ |
|
|||
324 | '0000000000000000000000000000000000000000 ' |
|
|||
325 | '9695eef57205c17566a3ae543be187759b310bb7 refs/heads/master\n'] |
|
|||
326 | with mock_hook_response(status=0): |
|
|||
327 | response = hooks.git_post_receive( |
|
|||
328 | None, rev_lines, {'RC_SCM_DATA': json.dumps(extras)}) |
|
|||
329 |
|
||||
330 | calls = [ |
|
|||
331 | mock.call(['git', 'show', 'HEAD']), |
|
|||
332 | mock.call(['git', 'for-each-ref', '--format=%(refname)', |
|
|||
333 | 'refs/heads/*']), |
|
|||
334 | mock.call(['git', 'log', '--reverse', '--pretty=format:%H', |
|
|||
335 | '--', '9695eef57205c17566a3ae543be187759b310bb7', '--not', |
|
|||
336 | '']) |
|
|||
337 | ] |
|
|||
338 | cmd_mock.assert_has_calls(calls, any_order=True) |
|
|||
339 |
|
||||
340 | assert response == 0 |
|
|||
341 |
|
||||
342 |
|
||||
343 | def test_git_pre_pull(): |
|
|||
344 | extras = { |
|
|||
345 | 'hooks': ['pull'], |
|
|||
346 | 'hooks_uri': 'fake_hook_uri', |
|
|||
347 | } |
|
|||
348 | with mock_hook_response(status=1, output='foo'): |
|
|||
349 | assert hooks.git_pre_pull(extras) == hooks.HookResponse(1, 'foo') |
|
|||
350 |
|
||||
351 |
|
||||
352 | def test_git_pre_pull_exception_is_caught(): |
|
|||
353 | extras = { |
|
|||
354 | 'hooks': ['pull'], |
|
|||
355 | 'hooks_uri': 'fake_hook_uri', |
|
|||
356 | } |
|
|||
357 | with mock_hook_response(status=2, exception=Exception('foo')): |
|
|||
358 | assert hooks.git_pre_pull(extras).status == 128 |
|
|||
359 |
|
||||
360 |
|
||||
361 | def test_git_pre_pull_is_disabled(): |
|
110 | def test_git_pre_pull_is_disabled(): | |
362 | assert hooks.git_pre_pull({'hooks': ['push']}) == hooks.HookResponse(0, '') |
|
111 | assert hooks.git_pre_pull({'hooks': ['push']}) == hooks.HookResponse(0, '') | |
363 |
|
112 | |||
364 |
|
113 | |||
365 | def test_git_post_pull(): |
|
|||
366 | extras = { |
|
|||
367 | 'hooks': ['pull'], |
|
|||
368 | 'hooks_uri': 'fake_hook_uri', |
|
|||
369 | } |
|
|||
370 | with mock_hook_response(status=1, output='foo'): |
|
|||
371 | assert hooks.git_post_pull(extras) == hooks.HookResponse(1, 'foo') |
|
|||
372 |
|
||||
373 |
|
||||
374 | def test_git_post_pull_exception_is_caught(): |
|
|||
375 | extras = { |
|
|||
376 | 'hooks': ['pull'], |
|
|||
377 | 'hooks_uri': 'fake_hook_uri', |
|
|||
378 | } |
|
|||
379 | with mock_hook_response(status=2, exception='Exception', |
|
|||
380 | exception_args=('foo',)): |
|
|||
381 | assert hooks.git_post_pull(extras).status == 128 |
|
|||
382 |
|
||||
383 |
|
||||
384 | def test_git_post_pull_is_disabled(): |
|
114 | def test_git_post_pull_is_disabled(): | |
385 | assert ( |
|
115 | assert ( | |
386 | hooks.git_post_pull({'hooks': ['push']}) == hooks.HookResponse(0, '')) |
|
116 | hooks.git_post_pull({'hooks': ['push']}) == hooks.HookResponse(0, '')) | |
387 |
|
117 | |||
388 |
|
118 | |||
389 | class TestGetHooksClient(object): |
|
119 | class TestGetHooksClient(object): | |
390 | def test_returns_pyro_client_when_protocol_matches(self): |
|
|||
391 | hooks_uri = 'localhost:8000' |
|
|||
392 | result = hooks._get_hooks_client({ |
|
|||
393 | 'hooks_uri': hooks_uri, |
|
|||
394 | 'hooks_protocol': 'pyro4' |
|
|||
395 | }) |
|
|||
396 | assert isinstance(result, hooks.HooksPyro4Client) |
|
|||
397 | assert result.hooks_uri == hooks_uri |
|
|||
398 |
|
120 | |||
399 | def test_returns_http_client_when_protocol_matches(self): |
|
121 | def test_returns_http_client_when_protocol_matches(self): | |
400 | hooks_uri = 'localhost:8000' |
|
122 | hooks_uri = 'localhost:8000' | |
@@ -405,14 +127,6 b' class TestGetHooksClient(object):' | |||||
405 | assert isinstance(result, hooks.HooksHttpClient) |
|
127 | assert isinstance(result, hooks.HooksHttpClient) | |
406 | assert result.hooks_uri == hooks_uri |
|
128 | assert result.hooks_uri == hooks_uri | |
407 |
|
129 | |||
408 | def test_returns_pyro4_client_when_no_protocol_is_specified(self): |
|
|||
409 | hooks_uri = 'localhost:8000' |
|
|||
410 | result = hooks._get_hooks_client({ |
|
|||
411 | 'hooks_uri': hooks_uri |
|
|||
412 | }) |
|
|||
413 | assert isinstance(result, hooks.HooksPyro4Client) |
|
|||
414 | assert result.hooks_uri == hooks_uri |
|
|||
415 |
|
||||
416 | def test_returns_dummy_client_when_hooks_uri_not_specified(self): |
|
130 | def test_returns_dummy_client_when_hooks_uri_not_specified(self): | |
417 | fake_module = mock.Mock() |
|
131 | fake_module = mock.Mock() | |
418 | import_patcher = mock.patch.object( |
|
132 | import_patcher = mock.patch.object( | |
@@ -487,30 +201,6 b' class TestHooksDummyClient(object):' | |||||
487 | assert result == hooks_module.Hooks().__enter__().post_push() |
|
201 | assert result == hooks_module.Hooks().__enter__().post_push() | |
488 |
|
202 | |||
489 |
|
203 | |||
490 | class TestHooksPyro4Client(object): |
|
|||
491 | def test_init_sets_hooks_uri(self): |
|
|||
492 | uri = 'localhost:3000' |
|
|||
493 | client = hooks.HooksPyro4Client(uri) |
|
|||
494 | assert client.hooks_uri == uri |
|
|||
495 |
|
||||
496 | def test_call_returns_hook_value(self): |
|
|||
497 | hooks_uri = 'localhost:3000' |
|
|||
498 | client = hooks.HooksPyro4Client(hooks_uri) |
|
|||
499 | hooks_module = mock.Mock() |
|
|||
500 | context_manager = mock.MagicMock() |
|
|||
501 | context_manager.__enter__.return_value = hooks_module |
|
|||
502 | pyro4_patcher = mock.patch.object( |
|
|||
503 | hooks.Pyro4, 'Proxy', return_value=context_manager) |
|
|||
504 | extras = { |
|
|||
505 | 'test': 'test' |
|
|||
506 | } |
|
|||
507 | with pyro4_patcher as pyro4_mock: |
|
|||
508 | result = client('post_push', extras) |
|
|||
509 | pyro4_mock.assert_called_once_with(hooks_uri) |
|
|||
510 | hooks_module.post_push.assert_called_once_with(extras) |
|
|||
511 | assert result == hooks_module.post_push.return_value |
|
|||
512 |
|
||||
513 |
|
||||
514 | @pytest.fixture |
|
204 | @pytest.fixture | |
515 | def http_mirror(request): |
|
205 | def http_mirror(request): | |
516 | server = MirrorHttpServer() |
|
206 | server = MirrorHttpServer() |
@@ -18,24 +18,24 b'' | |||||
18 | import mock |
|
18 | import mock | |
19 | import pytest |
|
19 | import pytest | |
20 |
|
20 | |||
21 | from vcsserver import main |
|
21 | from vcsserver import http_main | |
22 | from vcsserver.base import obfuscate_qs |
|
22 | from vcsserver.base import obfuscate_qs | |
23 |
|
23 | |||
24 |
|
24 | |||
25 |
@mock.patch('vcsserver.main.V |
|
25 | @mock.patch('vcsserver.http_main.VCS', mock.Mock()) | |
26 | @mock.patch('vcsserver.hgpatches.patch_largefiles_capabilities') |
|
26 | @mock.patch('vcsserver.hgpatches.patch_largefiles_capabilities') | |
27 | def test_applies_largefiles_patch(patch_largefiles_capabilities): |
|
27 | def test_applies_largefiles_patch(patch_largefiles_capabilities): | |
28 | main.main([]) |
|
28 | http_main.main([]) | |
29 | patch_largefiles_capabilities.assert_called_once_with() |
|
29 | patch_largefiles_capabilities.assert_called_once_with() | |
30 |
|
30 | |||
31 |
|
31 | |||
32 |
@mock.patch('vcsserver.main.V |
|
32 | @mock.patch('vcsserver.http_main.VCS', mock.Mock()) | |
33 | @mock.patch('vcsserver.main.MercurialFactory', None) |
|
33 | @mock.patch('vcsserver.http_main.MercurialFactory', None) | |
34 | @mock.patch( |
|
34 | @mock.patch( | |
35 | 'vcsserver.hgpatches.patch_largefiles_capabilities', |
|
35 | 'vcsserver.hgpatches.patch_largefiles_capabilities', | |
36 | mock.Mock(side_effect=Exception("Must not be called"))) |
|
36 | mock.Mock(side_effect=Exception("Must not be called"))) | |
37 | def test_applies_largefiles_patch_only_if_mercurial_is_available(): |
|
37 | def test_applies_largefiles_patch_only_if_mercurial_is_available(): | |
38 | main.main([]) |
|
38 | http_main.main([]) | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | @pytest.mark.parametrize('given, expected', [ |
|
41 | @pytest.mark.parametrize('given, expected', [ |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed | ||
This diff has been collapsed as it changes many lines, (508 lines changed) Show them Hide them |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now