##// END OF EJS Templates
tests: Add tests to check the shadow repo exposure of the simplevcs class.
Martin Bornhold -
r913:41b97db8 default
parent child Browse files
Show More
@@ -173,6 +173,113 b' def test_should_check_locking(query_stri'
173 assert result == expected
173 assert result == expected
174
174
175
175
176 @pytest.mark.backends('git', 'hg')
177 class TestShadowRepoExposure(object):
178 def test_pull_on_shadow_repo_propagates_to_wsgi_app(self, pylonsapp):
179 """
180 Check that a pull action to a shadow repo is propagated to the
181 underlying wsgi app.
182 """
183 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
184 controller._check_ssl = mock.Mock()
185 controller.is_shadow_repo = True
186 controller._action = 'pull'
187 controller.stub_response_body = 'dummy body value'
188 environ_stub = {
189 'HTTP_HOST': 'test.example.com',
190 'REQUEST_METHOD': 'GET',
191 'wsgi.url_scheme': 'http',
192 }
193
194 response = controller(environ_stub, mock.Mock())
195 response_body = ''.join(response)
196
197 # Assert that we got the response from the wsgi app.
198 assert response_body == controller.stub_response_body
199
200 def test_push_on_shadow_repo_raises(self, pylonsapp):
201 """
202 Check that a push action to a shadow repo is aborted.
203 """
204 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
205 controller._check_ssl = mock.Mock()
206 controller.is_shadow_repo = True
207 controller._action = 'push'
208 controller.stub_response_body = 'dummy body value'
209 environ_stub = {
210 'HTTP_HOST': 'test.example.com',
211 'REQUEST_METHOD': 'GET',
212 'wsgi.url_scheme': 'http',
213 }
214
215 response = controller(environ_stub, mock.Mock())
216 response_body = ''.join(response)
217
218 assert response_body != controller.stub_response_body
219 # Assert that a 406 error is returned.
220 assert '406 Not Acceptable' in response_body
221
222 def test_set_repo_names_no_shadow(self, pylonsapp):
223 """
224 Check that the set_repo_names method sets all names to the one returned
225 by the _get_repository_name method on a request to a non shadow repo.
226 """
227 environ_stub = {}
228 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
229 controller._name = 'RepoGroup/MyRepo'
230 controller.set_repo_names(environ_stub)
231 assert not controller.is_shadow_repo
232 assert (controller.url_repo_name ==
233 controller.acl_repo_name ==
234 controller.vcs_repo_name ==
235 controller._get_repository_name(environ_stub))
236
237 def test_set_repo_names_with_shadow(self, pylonsapp, pr_util):
238 """
239 Check that the set_repo_names method sets correct names on a request
240 to a shadow repo.
241 """
242 from rhodecode.model.pull_request import PullRequestModel
243
244 pull_request = pr_util.create_pull_request()
245 shadow_url = '{target}/pull-request/{pr_id}/repository'.format(
246 target=pull_request.target_repo.repo_name,
247 pr_id=pull_request.pull_request_id)
248 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
249 controller._name = shadow_url
250 controller.set_repo_names({})
251
252 # Get file system path to shadow repo for assertions.
253 workspace_id = PullRequestModel()._workspace_id(pull_request)
254 target_vcs = pull_request.target_repo.scm_instance()
255 vcs_repo_name = target_vcs._get_shadow_repository_path(
256 workspace_id)
257
258 assert controller.vcs_repo_name == vcs_repo_name
259 assert controller.url_repo_name == shadow_url
260 assert controller.acl_repo_name == pull_request.target_repo.repo_name
261 assert controller.is_shadow_repo
262
263 def test_set_repo_names_with_shadow_but_missing_pr(
264 self, pylonsapp, pr_util):
265 """
266 Checks that the set_repo_names method enforces matching target repos
267 and pull request IDs.
268 """
269 pull_request = pr_util.create_pull_request()
270 shadow_url = '{target}/pull-request/{pr_id}/repository'.format(
271 target=pull_request.target_repo.repo_name,
272 pr_id=999999999)
273 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
274 controller._name = shadow_url
275 controller.set_repo_names({})
276
277 assert not controller.is_shadow_repo
278 assert (controller.url_repo_name ==
279 controller.acl_repo_name ==
280 controller.vcs_repo_name)
281
282
176 @mock.patch.multiple(
283 @mock.patch.multiple(
177 'Pyro4.config', SERVERTYPE='multiplex', POLLTIMEOUT=0.01)
284 'Pyro4.config', SERVERTYPE='multiplex', POLLTIMEOUT=0.01)
178 class TestGenerateVcsResponse:
285 class TestGenerateVcsResponse:
General Comments 0
You need to be logged in to leave comments. Login now