| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,7 +178,7 @@ def _parse_value(v: Any) -> Any: | |||
| 178 | 178 | return v | |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | - def docs() -> argparse.ArgumentParser: | ||
| 181 | + def docs() -> argparse.ArgumentParser: # pragma: no cover | ||
| 182 | 182 | """ | |
| 183 | 183 | Provide a statically generated parser for sphinx only, so we don't need | |
| 184 | 184 | to provide dummy gitlab config for readthedocs. | |
@@ -208,15 +208,15 @@ def main() -> None: | |||
| 208 | 208 | sys.exit(0) | |
| 209 | 209 | sys.exit(e) | |
| 210 | 210 | # We only support v4 API at this time | |
| 211 | - if config.api_version not in ("4",): | ||
| 211 | + if config.api_version not in ("4",): # dead code # pragma: no cover | ||
| 212 | 212 | raise ModuleNotFoundError(name=f"gitlab.v{config.api_version}.cli") | |
| 213 | 213 | ||
| 214 | 214 | # Now we build the entire set of subcommands and do the complete parsing | |
| 215 | 215 | parser = _get_parser() | |
| 216 | 216 | try: | |
| 217 | 217 | import argcomplete # type: ignore | |
| 218 | 218 | ||
| 219 | - argcomplete.autocomplete(parser) | ||
| 219 | + argcomplete.autocomplete(parser) # pragma: no cover | ||
| 220 | 220 | except Exception: | |
| 221 | 221 | pass | |
| 222 | 222 | args = parser.parse_args() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ files = "." | |||
| 12 | 12 | module = [ | |
| 13 | 13 | "docs.*", | |
| 14 | 14 | "docs.ext.*", | |
| 15 | + "tests.*", | ||
| 15 | 16 | "tests.functional.*", | |
| 16 | 17 | "tests.functional.api.*", | |
| 17 | 18 | "tests.unit.*", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | 1 | -r requirements.txt | |
| 2 | 2 | -r requirements-test.txt | |
| 3 | 3 | docker-compose==1.29.2 # prevent inconsistent .env behavior from system install | |
| 4 | - pytest-console-scripts | ||
| 5 | 4 | pytest-docker | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | coverage | |
| 2 | 2 | httmock | |
| 3 | - mock | ||
| 4 | 3 | pytest | |
| 4 | + pytest-console-scripts==1.2.1 | ||
| 5 | 5 | pytest-cov | |
| 6 | 6 | responses | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + import pytest | ||
| 2 | + | ||
| 3 | + | ||
| 4 | + @pytest.fixture(scope="session") | ||
| 5 | + def test_dir(pytestconfig): | ||
| 6 | + return pytestconfig.rootdir / "tests" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,23 +3,17 @@ | |||
| 3 | 3 | https://docs.gitlab.com/ee/api/users.html | |
| 4 | 4 | https://docs.gitlab.com/ee/api/users.html#delete-authentication-identity-from-user | |
| 5 | 5 | """ | |
| 6 | - import pytest | ||
| 7 | 6 | import requests | |
| 8 | 7 | ||
| 9 | 8 | ||
| 10 | - @pytest.fixture(scope="session") | ||
| 11 | - def avatar_path(test_dir): | ||
| 12 | - return test_dir / "fixtures" / "avatar.png" | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - def test_create_user(gl, avatar_path): | ||
| 9 | + def test_create_user(gl, fixture_dir): | ||
| 16 | 10 | user = gl.users.create( | |
| 17 | 11 | { | |
| 18 | 12 | "email": "foo@bar.com", | |
| 19 | 13 | "username": "foo", | |
| 20 | 14 | "name": "foo", | |
| 21 | 15 | "password": "foo_password", | |
| 22 | - "avatar": open(avatar_path, "rb"), | ||
| 16 | + "avatar": open(fixture_dir / "avatar.png", "rb"), | ||
| 23 | 17 | } | |
| 24 | 18 | ) | |
| 25 | 19 | ||
@@ -29,7 +23,7 @@ def test_create_user(gl, avatar_path): | |||
| 29 | 23 | ||
| 30 | 24 | avatar_url = user.avatar_url.replace("gitlab.test", "localhost:8080") | |
| 31 | 25 | uploaded_avatar = requests.get(avatar_url).content | |
| 32 | - assert uploaded_avatar == open(avatar_path, "rb").read() | ||
| 26 | + assert uploaded_avatar == open(fixture_dir / "avatar.png", "rb").read() | ||
| 33 | 27 | ||
| 34 | 28 | ||
| 35 | 29 | def test_block_user(gl, user): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + import json | ||
| 2 | + | ||
| 3 | + from gitlab import __version__ | ||
| 4 | + | ||
| 5 | + | ||
| 6 | + def test_main_entrypoint(script_runner, gitlab_config): | ||
| 7 | + ret = script_runner.run("python", "-m", "gitlab", "--config-file", gitlab_config) | ||
| 8 | + assert ret.returncode == 2 | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + def test_version(script_runner): | ||
| 12 | + ret = script_runner.run("gitlab", "--version") | ||
| 13 | + assert ret.stdout.strip() == __version__ | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + def test_invalid_config(script_runner): | ||
| 17 | + ret = script_runner.run("gitlab", "--gitlab", "invalid") | ||
| 18 | + assert not ret.success | ||
| 19 | + assert not ret.stdout | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + def test_invalid_config_prints_help(script_runner): | ||
| 23 | + ret = script_runner.run("gitlab", "--gitlab", "invalid", "--help") | ||
| 24 | + assert ret.success | ||
| 25 | + assert ret.stdout | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + def test_invalid_api_version(script_runner, monkeypatch, fixture_dir): | ||
| 29 | + monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_version.cfg")) | ||
| 30 | + ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
| 31 | + assert not ret.success | ||
| 32 | + assert ret.stderr.startswith("Unsupported API version:") | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + def test_invalid_auth_config(script_runner, monkeypatch, fixture_dir): | ||
| 36 | + monkeypatch.setenv("PYTHON_GITLAB_CFG", str(fixture_dir / "invalid_auth.cfg")) | ||
| 37 | + ret = script_runner.run("gitlab", "--gitlab", "test", "project", "list") | ||
| 38 | + assert not ret.success | ||
| 39 | + assert "401" in ret.stderr | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + def test_fields(gitlab_cli, project_file): | ||
| 43 | + cmd = "-o", "json", "--fields", "default_branch", "project", "list" | ||
| 44 | + | ||
| 45 | + ret = gitlab_cli(cmd) | ||
| 46 | + assert ret.success | ||
| 47 | + | ||
| 48 | + content = json.loads(ret.stdout.strip()) | ||
| 49 | + assert ["default_branch" in item for item in content] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,11 @@ | |||
| 9 | 9 | import gitlab | |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | + @pytest.fixture(scope="session") | ||
| 13 | + def fixture_dir(test_dir): | ||
| 14 | + return test_dir / "functional" / "fixtures" | ||
| 15 | + | ||
| 16 | + | ||
| 12 | 17 | def reset_gitlab(gl): | |
| 13 | 18 | # previously tools/reset_gitlab.py | |
| 14 | 19 | for project in gl.projects.list(): | |
@@ -26,8 +31,8 @@ def reset_gitlab(gl): | |||
| 26 | 31 | user.delete(hard_delete=True) | |
| 27 | 32 | ||
| 28 | 33 | ||
| 29 | - def set_token(container, rootdir): | ||
| 30 | - set_token_rb = rootdir / "fixtures" / "set_token.rb" | ||
| 34 | + def set_token(container, fixture_dir): | ||
| 35 | + set_token_rb = fixture_dir / "set_token.rb" | ||
| 31 | 36 | ||
| 32 | 37 | with open(set_token_rb, "r") as f: | |
| 33 | 38 | set_token_command = f.read().strip() | |
@@ -68,13 +73,8 @@ def temp_dir(): | |||
| 68 | 73 | ||
| 69 | 74 | ||
| 70 | 75 | @pytest.fixture(scope="session") | |
| 71 | - def test_dir(pytestconfig): | ||
| 72 | - return pytestconfig.rootdir / "tests" / "functional" | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - @pytest.fixture(scope="session") | ||
| 76 | - def docker_compose_file(test_dir): | ||
| 77 | - return test_dir / "fixtures" / "docker-compose.yml" | ||
| 76 | + def docker_compose_file(fixture_dir): | ||
| 77 | + return fixture_dir / "docker-compose.yml" | ||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | 80 | @pytest.fixture(scope="session") | |
@@ -129,15 +129,15 @@ def _wait(timeout=30, step=0.5): | |||
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | 131 | @pytest.fixture(scope="session") | |
| 132 | - def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, test_dir): | ||
| 132 | + def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_dir): | ||
| 133 | 133 | config_file = temp_dir / "python-gitlab.cfg" | |
| 134 | 134 | port = docker_services.port_for("gitlab", 80) | |
| 135 | 135 | ||
| 136 | 136 | docker_services.wait_until_responsive( | |
| 137 | 137 | timeout=200, pause=5, check=lambda: check_is_alive("gitlab-test") | |
| 138 | 138 | ) | |
| 139 | 139 | ||
| 140 | - token = set_token("gitlab-test", rootdir=test_dir) | ||
| 140 | + token = set_token("gitlab-test", fixture_dir=fixture_dir) | ||
| 141 | 141 | ||
| 142 | 142 | config = f"""[global] | |
| 143 | 143 | default = local | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + [test] | ||
| 2 | + url = https://gitlab.com | ||
| 3 | + private_token = abc123 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + [test] | ||
| 2 | + api_version = 3 | ||
| 3 | + url = https://gitlab.example.com | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments