def test_banned():
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        banned_specs=[
            '^jupyterhub.*'
        ]
    )
    assert provider.is_banned()
def test_github_ref():
    provider = GitHubRepoProvider(spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4')
    slug = provider.get_build_slug()
    assert slug == 'jupyterhub-zero-to-jupyterhub-k8s'
    full_url = provider.get_repo_url()
    assert full_url == 'https://github.com/jupyterhub/zero-to-jupyterhub-k8s'
    ref = IOLoop().run_sync(provider.get_resolved_ref)
    assert ref == 'f7f3ff6d1bf708bdc12e5f10e18b2a90a4795603'
Beispiel #3
0
def test_not_higher_quota():
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        high_quota_specs=[
            '^jupyterhub.*'
        ]
    )
    assert provider.has_higher_quota()
def test_github_ref():
    namespace = 'jupyterhub/zero-to-jupyterhub-k8s'
    spec = f'{namespace}/v0.4'
    provider = GitHubRepoProvider(spec=spec)
    slug = provider.get_build_slug()
    assert slug == 'jupyterhub-zero-to-jupyterhub-k8s'
    full_url = provider.get_repo_url()
    assert full_url == f'https://github.com/{namespace}'
    ref = IOLoop().run_sync(provider.get_resolved_ref)
    assert ref == 'f7f3ff6d1bf708bdc12e5f10e18b2a90a4795603'
    ref_url = IOLoop().run_sync(provider.get_resolved_ref_url)
    assert ref_url == f'https://github.com/{namespace}/tree/{ref}'
    resolved_spec = IOLoop().run_sync(provider.get_resolved_spec)
    assert resolved_spec == f'{namespace}/{ref}'
def test_github_ref(repo, unresolved_ref, resolved_ref):
    spec = f"{repo}/{unresolved_ref}"
    provider = GitHubRepoProvider(spec=spec)
    slug = provider.get_build_slug()
    assert slug == repo.replace("/", "-")
    full_url = provider.get_repo_url()
    assert full_url == f"https://github.com/{repo}"
    ref = IOLoop().run_sync(provider.get_resolved_ref)
    if resolved_ref is True:
        # True means it should resolve, but don't check value
        assert ref is not None
        assert is_valid_sha1(ref)
    else:
        assert ref == resolved_ref
    if not resolved_ref:
        # we are done here if we don't expect to resolve
        return
    ref_url = IOLoop().run_sync(provider.get_resolved_ref_url)
    assert ref_url == f"https://github.com/{repo}/tree/{ref}"
    resolved_spec = IOLoop().run_sync(provider.get_resolved_spec)
    assert resolved_spec == f"{repo}/{ref}"
def test_github_missing_ref():
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.1.2.3.4.5.6')
    ref = IOLoop().run_sync(provider.get_resolved_ref)
    assert ref is None
def test_ban_is_case_insensitive(ban_spec):
    provider = GitHubRepoProvider(spec='AABBCcc/DDeeFF/v0.4',
                                  banned_specs=[ban_spec])
    assert provider.is_banned()
def test_custom_config():
    base_config = {
        "pattern": '^jupyterhub.*',
        "config": {
            "key1": "val1",
            "quota": 999
        }
    }
    settings = {"per_repo_quota": 10}

    # If the spec matches nothing, we should just keep defaults
    provider = GitHubRepoProvider(
        spec='totallynotjupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[base_config])
    assert provider.repo_config(settings)['quota'] == 10

    # Updating should happen w/ the base config
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[base_config])
    assert provider.repo_config(settings)['key1'] == "val1"
    assert provider.repo_config(settings)['quota'] == 999

    # Not giving a string for the pattern should raise an error
    config_err_pattern = base_config.copy()
    config_err_pattern['pattern'] = 100
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[config_err_pattern])
    with pytest.raises(ValueError):
        provider.repo_config(settings)

    # Not giving a dictionary for configuration should raise an error
    config_err_config = base_config.copy()
    config_err_config['config'] = "not a dictionary"
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[config_err_config])
    with pytest.raises(ValueError):
        provider.repo_config(settings)

    # Not providing one of `pattern` or `config` should raise an error
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[base_config, {
            "pattern": "mypattern"
        }])
    with pytest.raises(ValueError):
        provider.repo_config(settings)

    # Two regexes that both match should result in the *last* one being in the config
    base_config_second = {
        "pattern": '^jupyterh.*',
        "config": {
            "key1": "newvalue",
        }
    }
    provider = GitHubRepoProvider(
        spec='jupyterhub/zero-to-jupyterhub-k8s/v0.4',
        spec_config=[base_config, base_config_second])
    assert provider.repo_config(settings)['key1'] == "newvalue"
    assert provider.repo_config(settings)['quota'] == 999
Beispiel #9
0
def test_not_higher_quota():
    provider = GitHubRepoProvider(
        spec="jupyterhub/zero-to-jupyterhub-k8s/v0.4",
        high_quota_specs=["^jupyterhub.*"],
    )
    assert provider.has_higher_quota()
Beispiel #10
0
def test_banned():
    provider = GitHubRepoProvider(
        spec="jupyterhub/zero-to-jupyterhub-k8s/v0.4",
        banned_specs=["^jupyterhub.*"])
    assert provider.is_banned()