# HG changeset patch # User Martin Bornhold # Date 2016-09-28 11:26:30 # Node ID f10baf564c75079a3002496a10a0bb9debfd3f87 # Parent 30123d50f33369c190f5f75e7937897681dbf8f7 tests: Add tests to check the shadow-repo regular expression. diff --git a/rhodecode/tests/lib/middleware/test_simplevcs.py b/rhodecode/tests/lib/middleware/test_simplevcs.py --- a/rhodecode/tests/lib/middleware/test_simplevcs.py +++ b/rhodecode/tests/lib/middleware/test_simplevcs.py @@ -173,8 +173,42 @@ def test_should_check_locking(query_stri assert result == expected +class TestShadowRepoRegularExpression(object): + @pytest.mark.parametrize('url, expected', [ + # repo with/without groups + ('My-Repo/pull-request/1/repository', True), + ('Group/My-Repo/pull-request/2/repository', True), + ('Group/Sub-Group/My-Repo/pull-request/3/repository', True), + ('Group/Sub-Group1/Sub-Group2/My-Repo/pull-request/3/repository', True), + + # pull request ID + ('MyRepo/pull-request/1/repository', True), + ('MyRepo/pull-request/1234567890/repository', True), + ('MyRepo/pull-request/-1/repository', False), + ('MyRepo/pull-request/invalid/repository', False), + + # unicode + (u'Sp€çîál-Repö/pull-request/1/repository', True), + (u'Sp€çîál-Gröüp/Sp€çîál-Repö/pull-request/1/repository', True), + + # trailing/leading slash + ('/My-Repo/pull-request/1/repository', False), + ('My-Repo/pull-request/1/repository/', False), + ('/My-Repo/pull-request/1/repository/', False), + + # misc + ('My-Repo/pull-request/1/repository/extra', False), + ('My-Repo/pull-request/1/repositoryextra', False), + ]) + def test_shadow_repo_regular_expression(self, url, expected): + from rhodecode.lib.middleware.simplevcs import SimpleVCS + match_obj = SimpleVCS.shadow_repo_re.match(url) + assert (match_obj is not None) == expected + + @pytest.mark.backends('git', 'hg') class TestShadowRepoExposure(object): + def test_pull_on_shadow_repo_propagates_to_wsgi_app(self, pylonsapp): """ Check that a pull action to a shadow repo is propagated to the