summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-07-26 00:51:58 +0200
committerJohn Villalovos <john@sodarock.com>2022-07-25 22:31:22 -0700
commit67ab24fe5ae10a9f8cc9122b1a08848e8927635d (patch)
treed25bad4aa4de51ca5515c34b27b2b6584ab23fa3
parent346cf76b381ab1ea0c2c42885fedc41f8c5716b0 (diff)
downloadgitlab-67ab24fe5ae10a9f8cc9122b1a08848e8927635d.tar.gz
test(functional): simplify token creation
-rw-r--r--tests/functional/conftest.py27
-rw-r--r--tests/functional/fixtures/docker-compose.yml6
-rw-r--r--tox.ini2
3 files changed, 9 insertions, 26 deletions
diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py
index 38d245f..6cab31c 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_for_sidekiq(gl):
@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 ae1d776..ec93272 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 5228315..aafef8e 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