diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-11-26 19:04:20 +0100 |
---|---|---|
committer | John Villalovos <john@sodarock.com> | 2022-12-18 01:16:28 -0600 |
commit | 43c2dda7aa8b167a451b966213e83d88d1baa1df (patch) | |
tree | 12546f44c707ffa28358fb94ca9652c5ae2d6b91 | |
parent | 5f8b8f5be901e944dfab2257f9e0cc4b2b1d2cd5 (diff) | |
download | gitlab-43c2dda7aa8b167a451b966213e83d88d1baa1df.tar.gz |
test(functional): do not require config file
-rw-r--r-- | tests/functional/api/test_gitlab.py | 6 | ||||
-rw-r--r-- | tests/functional/conftest.py | 19 |
2 files changed, 13 insertions, 12 deletions
diff --git a/tests/functional/api/test_gitlab.py b/tests/functional/api/test_gitlab.py index c2aba09..ced77c2 100644 --- a/tests/functional/api/test_gitlab.py +++ b/tests/functional/api/test_gitlab.py @@ -15,11 +15,9 @@ def get_all_kwargs(request): return request.param -def test_auth_from_config(gl, temp_dir): +def test_auth_from_config(gl, gitlab_config, temp_dir): """Test token authentication from config file""" - test_gitlab = gitlab.Gitlab.from_config( - config_files=[temp_dir / "python-gitlab.cfg"] - ) + test_gitlab = gitlab.Gitlab.from_config(config_files=[gitlab_config]) test_gitlab.auth() assert isinstance(test_gitlab.user, gitlab.v4.objects.CurrentUser) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index d2ff5e0..c85b172 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -236,15 +236,13 @@ def wait_for_sidekiq(gl): @pytest.fixture(scope="session") -def gitlab_config( +def gitlab_token( check_is_alive, gitlab_container_name: str, gitlab_url: str, docker_services, - temp_dir: pathlib.Path, fixture_dir: pathlib.Path, -): - config_file = temp_dir / "python-gitlab.cfg" +) -> str: start_time = time.perf_counter() logging.info("Waiting for GitLab container to become ready.") @@ -263,7 +261,12 @@ def gitlab_config( f"GitLab container is now ready after {minutes} minute(s), {seconds} seconds" ) - token = set_token(gitlab_container_name, fixture_dir=fixture_dir) + return set_token(gitlab_container_name, fixture_dir=fixture_dir) + + +@pytest.fixture(scope="session") +def gitlab_config(gitlab_url: str, gitlab_token: str, temp_dir: pathlib.Path): + config_file = temp_dir / "python-gitlab.cfg" config = f"""[global] default = local @@ -271,7 +274,7 @@ timeout = 60 [local] url = {gitlab_url} -private_token = {token} +private_token = {gitlab_token} api_version = 4""" with open(config_file, "w", encoding="utf-8") as f: @@ -281,11 +284,11 @@ api_version = 4""" @pytest.fixture(scope="session") -def gl(gitlab_config): +def gl(gitlab_url: str, gitlab_token: str) -> gitlab.Gitlab: """Helper instance to make fixtures and asserts directly via the API.""" logging.info("Instantiating python-gitlab gitlab.Gitlab instance") - instance = gitlab.Gitlab.from_config("local", [gitlab_config]) + instance = gitlab.Gitlab(gitlab_url, private_token=gitlab_token) logging.info("Reset GitLab") reset_gitlab(instance) |