Skip to content

Commit

Permalink
test(functional): do not require config file
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch authored and JohnVillalovos committed Dec 18, 2022
1 parent 5f8b8f5 commit 43c2dda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 2 additions & 4 deletions tests/functional/api/test_gitlab.py
Expand Up @@ -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)

Expand Down
19 changes: 11 additions & 8 deletions tests/functional/conftest.py
Expand Up @@ -236,15 +236,13 @@ def _wait(timeout: int = 30, step: float = 0.5, allow_fail: bool = False) -> boo


@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.")
Expand All @@ -263,15 +261,20 @@ 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
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:
Expand All @@ -281,11 +284,11 @@ def gitlab_config(


@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)
Expand Down

0 comments on commit 43c2dda

Please sign in to comment.