Skip to content

test(functional): simplify token creation #2186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 2 additions & 25 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
"",
Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/fixtures/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down