Skip to content

Commit 43c2dda

Browse files
nejchJohnVillalovos
authored andcommitted
test(functional): do not require config file
1 parent 5f8b8f5 commit 43c2dda

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

tests/functional/api/test_gitlab.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ def get_all_kwargs(request):
1515
return request.param
1616

1717

18-
def test_auth_from_config(gl, temp_dir):
18+
def test_auth_from_config(gl, gitlab_config, temp_dir):
1919
"""Test token authentication from config file"""
20-
test_gitlab = gitlab.Gitlab.from_config(
21-
config_files=[temp_dir / "python-gitlab.cfg"]
22-
)
20+
test_gitlab = gitlab.Gitlab.from_config(config_files=[gitlab_config])
2321
test_gitlab.auth()
2422
assert isinstance(test_gitlab.user, gitlab.v4.objects.CurrentUser)
2523

tests/functional/conftest.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,13 @@ def _wait(timeout: int = 30, step: float = 0.5, allow_fail: bool = False) -> boo
236236

237237

238238
@pytest.fixture(scope="session")
239-
def gitlab_config(
239+
def gitlab_token(
240240
check_is_alive,
241241
gitlab_container_name: str,
242242
gitlab_url: str,
243243
docker_services,
244-
temp_dir: pathlib.Path,
245244
fixture_dir: pathlib.Path,
246-
):
247-
config_file = temp_dir / "python-gitlab.cfg"
245+
) -> str:
248246

249247
start_time = time.perf_counter()
250248
logging.info("Waiting for GitLab container to become ready.")
@@ -263,15 +261,20 @@ def gitlab_config(
263261
f"GitLab container is now ready after {minutes} minute(s), {seconds} seconds"
264262
)
265263

266-
token = set_token(gitlab_container_name, fixture_dir=fixture_dir)
264+
return set_token(gitlab_container_name, fixture_dir=fixture_dir)
265+
266+
267+
@pytest.fixture(scope="session")
268+
def gitlab_config(gitlab_url: str, gitlab_token: str, temp_dir: pathlib.Path):
269+
config_file = temp_dir / "python-gitlab.cfg"
267270

268271
config = f"""[global]
269272
default = local
270273
timeout = 60
271274
272275
[local]
273276
url = {gitlab_url}
274-
private_token = {token}
277+
private_token = {gitlab_token}
275278
api_version = 4"""
276279

277280
with open(config_file, "w", encoding="utf-8") as f:
@@ -281,11 +284,11 @@ def gitlab_config(
281284

282285

283286
@pytest.fixture(scope="session")
284-
def gl(gitlab_config):
287+
def gl(gitlab_url: str, gitlab_token: str) -> gitlab.Gitlab:
285288
"""Helper instance to make fixtures and asserts directly via the API."""
286289

287290
logging.info("Instantiating python-gitlab gitlab.Gitlab instance")
288-
instance = gitlab.Gitlab.from_config("local", [gitlab_config])
291+
instance = gitlab.Gitlab(gitlab_url, private_token=gitlab_token)
289292

290293
logging.info("Reset GitLab")
291294
reset_gitlab(instance)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy