##// END OF EJS Templates
tests: Use only one place to define pr and shadow URL segments.
Martin Bornhold -
r920:c4b5ba79 default
parent child Browse files
Show More
@@ -174,34 +174,40 b' def test_should_check_locking(query_stri'
174
174
175
175
176 class TestShadowRepoRegularExpression(object):
176 class TestShadowRepoRegularExpression(object):
177 pr_segment = 'pull-request'
178 shadow_segment = 'repository'
179
177 @pytest.mark.parametrize('url, expected', [
180 @pytest.mark.parametrize('url, expected', [
178 # repo with/without groups
181 # repo with/without groups
179 ('My-Repo/pull-request/1/repository', True),
182 ('My-Repo/{pr_segment}/1/{shadow_segment}', True),
180 ('Group/My-Repo/pull-request/2/repository', True),
183 ('Group/My-Repo/{pr_segment}/2/{shadow_segment}', True),
181 ('Group/Sub-Group/My-Repo/pull-request/3/repository', True),
184 ('Group/Sub-Group/My-Repo/{pr_segment}/3/{shadow_segment}', True),
182 ('Group/Sub-Group1/Sub-Group2/My-Repo/pull-request/3/repository', True),
185 ('Group/Sub-Group1/Sub-Group2/My-Repo/{pr_segment}/3/{shadow_segment}', True),
183
186
184 # pull request ID
187 # pull request ID
185 ('MyRepo/pull-request/1/repository', True),
188 ('MyRepo/{pr_segment}/1/{shadow_segment}', True),
186 ('MyRepo/pull-request/1234567890/repository', True),
189 ('MyRepo/{pr_segment}/1234567890/{shadow_segment}', True),
187 ('MyRepo/pull-request/-1/repository', False),
190 ('MyRepo/{pr_segment}/-1/{shadow_segment}', False),
188 ('MyRepo/pull-request/invalid/repository', False),
191 ('MyRepo/{pr_segment}/invalid/{shadow_segment}', False),
189
192
190 # unicode
193 # unicode
191 (u'Sp€çîál-Repö/pull-request/1/repository', True),
194 (u'Sp€çîál-Repö/{pr_segment}/1/{shadow_segment}', True),
192 (u'Sp€çîál-Gröüp/Sp€çîál-Repö/pull-request/1/repository', True),
195 (u'Sp€çîál-Gröüp/Sp€çîál-Repö/{pr_segment}/1/{shadow_segment}', True),
193
196
194 # trailing/leading slash
197 # trailing/leading slash
195 ('/My-Repo/pull-request/1/repository', False),
198 ('/My-Repo/{pr_segment}/1/{shadow_segment}', False),
196 ('My-Repo/pull-request/1/repository/', False),
199 ('My-Repo/{pr_segment}/1/{shadow_segment}/', False),
197 ('/My-Repo/pull-request/1/repository/', False),
200 ('/My-Repo/{pr_segment}/1/{shadow_segment}/', False),
198
201
199 # misc
202 # misc
200 ('My-Repo/pull-request/1/repository/extra', False),
203 ('My-Repo/{pr_segment}/1/{shadow_segment}/extra', False),
201 ('My-Repo/pull-request/1/repositoryextra', False),
204 ('My-Repo/{pr_segment}/1/{shadow_segment}extra', False),
202 ])
205 ])
203 def test_shadow_repo_regular_expression(self, url, expected):
206 def test_shadow_repo_regular_expression(self, url, expected):
204 from rhodecode.lib.middleware.simplevcs import SimpleVCS
207 from rhodecode.lib.middleware.simplevcs import SimpleVCS
208 url = url.format(
209 pr_segment=self.pr_segment,
210 shadow_segment=self.shadow_segment)
205 match_obj = SimpleVCS.shadow_repo_re.match(url)
211 match_obj = SimpleVCS.shadow_repo_re.match(url)
206 assert (match_obj is not None) == expected
212 assert (match_obj is not None) == expected
207
213
@@ -276,9 +282,11 b' class TestShadowRepoExposure(object):'
276 from rhodecode.model.pull_request import PullRequestModel
282 from rhodecode.model.pull_request import PullRequestModel
277
283
278 pull_request = pr_util.create_pull_request()
284 pull_request = pr_util.create_pull_request()
279 shadow_url = '{target}/pull-request/{pr_id}/repository'.format(
285 shadow_url = '{target}/{pr_segment}/{pr_id}/{shadow_segment}'.format(
280 target=pull_request.target_repo.repo_name,
286 target=pull_request.target_repo.repo_name,
281 pr_id=pull_request.pull_request_id)
287 pr_id=pull_request.pull_request_id,
288 pr_segment=TestShadowRepoRegularExpression.pr_segment,
289 shadow_segment=TestShadowRepoRegularExpression.shadow_segment)
282 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
290 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
283 controller._name = shadow_url
291 controller._name = shadow_url
284 controller.set_repo_names({})
292 controller.set_repo_names({})
@@ -301,9 +309,11 b' class TestShadowRepoExposure(object):'
301 and pull request IDs.
309 and pull request IDs.
302 """
310 """
303 pull_request = pr_util.create_pull_request()
311 pull_request = pr_util.create_pull_request()
304 shadow_url = '{target}/pull-request/{pr_id}/repository'.format(
312 shadow_url = '{target}/{pr_segment}/{pr_id}/{shadow_segment}'.format(
305 target=pull_request.target_repo.repo_name,
313 target=pull_request.target_repo.repo_name,
306 pr_id=999999999)
314 pr_id=999999999,
315 pr_segment=TestShadowRepoRegularExpression.pr_segment,
316 shadow_segment=TestShadowRepoRegularExpression.shadow_segment)
307 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
317 controller = StubVCSController(pylonsapp, pylonsapp.config, None)
308 controller._name = shadow_url
318 controller._name = shadow_url
309 controller.set_repo_names({})
319 controller.set_repo_names({})
General Comments 0
You need to be logged in to leave comments. Login now