Skip to content

Commit

Permalink
Test repoprovider UI regexs
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Dec 11, 2023
1 parent 70d6b5b commit b11712e
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions binderhub/tests/test_repoproviders.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,38 @@ def test_github_ref(repo, unresolved_ref, resolved_ref):
assert resolved_spec == f"{repo}/{ref}"


@pytest.mark.parametrize(
"url,groupdict",
[
(
"https://github.com/binder-examples/conda",
{"repo": "binder-examples/conda", "filepath": None, "ref": None},
),
(
"https://github.com/binder-examples/conda/blob/main/index.ipynb",
{"repo": "binder-examples/conda", "ref": "main", "filepath": "index.ipynb"},
),
(
"https://github.com/binder-examples/conda/tree/main/.github/workflows",
{
"repo": "binder-examples/conda",
"ref": "main",
"urlpath": ".github/workflows",
},
),
("https://github.com/binder-examples/conda/pulls", None),
],
)
def test_github_regex_detect(url, groupdict):
regex_js = GitHubRepoProvider.regex_detect
regex_py = [r.replace("(?<", "(?P<") for r in regex_js]
m = re.match(regex_py[0], url) or re.match(regex_py[1], url)
if groupdict:
assert m.groupdict() == groupdict
else:
assert not m


def test_not_banned():
provider = GitHubRepoProvider(
spec="jupyterhub/zero-to-jupyterhub-k8s/v0.4", banned_specs=["^yuvipanda.*"]
Expand Down Expand Up @@ -488,6 +520,67 @@ def test_gitlab_ref(unresolved_ref, resolved_ref):
assert resolved_spec == quote(namespace, safe="") + f"/{ref}"


@pytest.mark.parametrize(
"url,groupdict",
[
(
"https://gitlab.com/owner/repo",
{
"repo": "owner/repo",
"ref": None,
"filepath": None,
},
),
(
"https://gitlab.com/owner/repo/-/tree/branch/folder?ref_type=heads",
{"repo": "owner/repo", "ref": "branch", "urlpath": "folder?ref_type=heads"},
),
(
"https://gitlab.com/owner/repo/-/blob/branch/README.md?ref_type=heads",
{
"repo": "owner/repo",
"ref": "branch",
"filepath": "README.md?ref_type=heads",
},
),
(
"https://gitlab.com/owner/project/repo",
{
"repo": "owner/project/repo",
"ref": None,
"filepath": None,
},
),
(
"https://gitlab.com/owner/project/repo/-/tree/branch/folder?ref_type=heads",
{
"repo": "owner/project/repo",
"ref": "branch",
"urlpath": "folder?ref_type=heads",
},
),
(
"https://gitlab.com/owner/project/repo/-/blob/branch/README.md?ref_type=heads",
{
"repo": "owner/project/repo",
"ref": "branch",
"filepath": "README.md?ref_type=heads",
},
),
("https://gitlab.com/owner/repo/-/merge_requests/123", None),
],
)
def test_gitlab_regex_detect(url, groupdict):
regex_js = GitLabRepoProvider.regex_detect
regex_py = [r.replace("(?<", "(?P<") for r in regex_js]
assert [r.replace("(?P<", "(?<") for r in regex_py] == regex_js
m = re.match(regex_py[0], url) or re.match(regex_py[1], url)
if groupdict:
assert m.groupdict() == groupdict
else:
assert not m


@pytest.mark.github_api
@pytest.mark.parametrize(
"owner, gist_id, unresolved_ref, resolved_ref",
Expand Down Expand Up @@ -529,6 +622,37 @@ def test_gist_ref(owner, gist_id, unresolved_ref, resolved_ref):
assert resolved_spec == f"{owner}/{gist_id}/{ref}"


@pytest.mark.parametrize(
"url,groupdict",
[
(
"https://gist.github.com/owner/0123456789abcde0123456789abcde01",
{
"repo": "owner/0123456789abcde0123456789abcde01",
"ref": None,
},
),
(
"https://gist.github.com/owner/0123456789abcde0123456789abcde01/sha",
{
"repo": "owner/0123456789abcde0123456789abcde01",
"ref": "sha",
},
),
("https://gist.github.com/owner", None),
],
)
def test_gist_regex_detect(url, groupdict):
regex_js = GistRepoProvider.regex_detect
regex_py = [r.replace("(?<", "(?P<") for r in regex_js]
assert [r.replace("(?P<", "(?<") for r in regex_py] == regex_js
m = re.match(regex_py[0], url)
if groupdict:
assert m.groupdict() == groupdict
else:
assert not m


@pytest.mark.github_api
def test_gist_secret():
spec = "{}/{}".format("mariusvniekerk", "bd01411ea4bf4eb8135893ef237398ba")
Expand Down

0 comments on commit b11712e

Please sign in to comment.