From 8cc98c1c9ac0d6b940405f5536b2f6ff7d135530 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Tue, 26 Jul 2022 00:51:58 +0200 Subject: [PATCH] test(functional): simplify token creation --- tests/functional/conftest.py | 27 ++------------------ tests/functional/fixtures/docker-compose.yml | 6 +++++ tox.ini | 2 +- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 38d245ff7..6cab31c62 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -50,27 +50,6 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None: helpers.safe_delete(user, hard_delete=True) -def set_token(container, fixture_dir): - logging.info("Creating API token.") - set_token_rb = fixture_dir / "set_token.rb" - - with open(set_token_rb, "r", encoding="utf-8") as f: - set_token_command = f.read().strip() - - rails_command = [ - "docker", - "exec", - container, - "gitlab-rails", - "runner", - set_token_command, - ] - output = check_output(rails_command).decode().strip() - logging.info("Finished creating API token.") - - return output - - def pytest_report_collectionfinish(config, startdir, items): return [ "", @@ -157,7 +136,7 @@ def _wait(timeout=30, step=0.5): @pytest.fixture(scope="session") -def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_dir): +def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir): config_file = temp_dir / "python-gitlab.cfg" port = docker_services.port_for("gitlab", 80) @@ -174,15 +153,13 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_ f"GitLab container is now ready after {minutes} minute(s), {seconds} seconds" ) - token = set_token("gitlab-test", fixture_dir=fixture_dir) - config = f"""[global] default = local timeout = 60 [local] url = http://{docker_ip}:{port} -private_token = {token} +private_token = python-gitlab-token api_version = 4""" with open(config_file, "w", encoding="utf-8") as f: diff --git a/tests/functional/fixtures/docker-compose.yml b/tests/functional/fixtures/docker-compose.yml index ae1d77655..ec932727f 100644 --- a/tests/functional/fixtures/docker-compose.yml +++ b/tests/functional/fixtures/docker-compose.yml @@ -31,6 +31,12 @@ services: gitlab_exporter['enable'] = false grafana['enable'] = false letsencrypt['enable'] = false + entrypoint: + - /bin/sh + - -c + - chmod 644 /opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/* && /assets/wrapper + volumes: + - ${PWD}/tests/functional/fixtures/set_token.rb:/opt/gitlab/embedded/service/gitlab-rails/db/fixtures/production/003_set_token.rb ports: - '8080:80' - '2222:22' diff --git a/tox.ini b/tox.ini index 52283151b..aafef8eeb 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,7 @@ skip_missing_interpreters = True envlist = py310,py39,py38,py37,flake8,black,twine-check,mypy,isort,cz,pylint [testenv] -passenv = GITLAB_IMAGE GITLAB_TAG PY_COLORS NO_COLOR FORCE_COLOR DOCKER_HOST +passenv = GITLAB_IMAGE GITLAB_TAG PY_COLORS NO_COLOR FORCE_COLOR DOCKER_HOST PWD setenv = VIRTUAL_ENV={envdir} whitelist_externals = true usedevelop = True