FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: integrate pytest-gitlab by ptalbert · Pull Request #3313 · python-gitlab/python-gitlab · GitHub

Repository navigation

Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ini  (1) .py  (9) .rb  (2) .sh  (1) .toml  (1) .txt  (2) .yml  (1) dotfile  (1) All 8 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Empty file.
4 changes: 4 additions & 0 deletions gitlab/testing/docker/.env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GITLAB_IMAGE=gitlab/gitlab-ee
GITLAB_TAG=18.7.0-ee.0
GITLAB_RUNNER_IMAGE=gitlab/gitlab-runner
GITLAB_RUNNER_TAG=96856197
Empty file.
51 changes: 51 additions & 0 deletions gitlab/testing/docker/create_license.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# NOTE: As of 2022-06-01 the GitLab Enterprise Edition License has the following
# section:
# Notwithstanding the foregoing, you may copy and modify the Software for development
# and testing purposes, without requiring a subscription.
#
# https://gitlab.com/gitlab-org/gitlab/-/blob/29503bc97b96af8d4876dc23fc8996e3dab7d211/ee/LICENSE
#
# This code is strictly intended for use in the testing framework of python-gitlab

# Code inspired by MIT licensed code at: https://github.com/CONIGUERO/gitlab-license.git

require 'openssl'
require 'gitlab/license'

# Generate a 2048 bit key pair.
license_encryption_key = OpenSSL::PKey::RSA.generate(2048)

# Save the private key
File.open("/.license_encryption_key", "w") { |f| f.write(license_encryption_key.to_pem) }
# Save the public key
public_key = license_encryption_key.public_key
File.open("/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) }
File.open("/opt/gitlab/embedded/service/gitlab-rails/.license_encryption_key.pub", "w") { |f| f.write(public_key.to_pem) }

Gitlab::License.encryption_key = license_encryption_key

# Build a new license.
license = Gitlab::License.new

license.licensee = {
"Name" => "python-gitlab-ci",
"Company" => "python-gitlab-ci",
"Email" => "python-gitlab-ci@example.com",
}

# The date the license starts.
license.starts_at = Date.today
# Want to make sure we get at least 1 day of usage. Do two days after because if CI
# started at 23:59 we could be expired in one minute if we only did one next_day.
license.expires_at = Date.today.next_day.next_day

# Use 'ultimate' plan so that we can test all features in the CI
license.restrictions = {
:plan => "ultimate",
:id => rand(1000..99999999)
}

# Export the license, which encrypts and encodes it.
data = license.export

File.open("/python-gitlab-ci.gitlab-license", 'w') { |file| file.write(data) }
52 changes: 52 additions & 0 deletions gitlab/testing/docker/docker-compose.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.5'

networks:
gitlab-network:
name: gitlab-network

services:
gitlab:
image: '${GITLAB_IMAGE:-gitlab/gitlab-ee}:${GITLAB_TAG:-latest}'
container_name: 'gitlab-test'
hostname: 'gitlab.test'
privileged: true # Just in case https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/1350
environment:
GITLAB_ROOT_PASSWORD: 5iveL!fe
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://127.0.0.1:8080'
registry['enable'] = false
nginx['redirect_http_to_https'] = false
nginx['listen_port'] = 80
nginx['listen_https'] = false
pages_external_url 'http://pages.gitlab.lxd'
gitlab_pages['enable'] = true
gitlab_pages['inplace_chroot'] = true
prometheus['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
pgbouncer_exporter['enable'] = false
gitlab_exporter['enable'] = false
letsencrypt['enable'] = false
gitlab_rails['initial_license_file'] = '/python-gitlab-ci.gitlab-license'
gitlab_rails['monitoring_whitelist'] = ['0.0.0.0/0']
entrypoint:
- /bin/sh
- -c
- ruby /create_license.rb && /assets/init-container
volumes:
- ${PWD}/tests/functional/fixtures/create_license.rb:/create_license.rb
ports:
- '8080:80'
- '2222:22'
networks:
- gitlab-network

gitlab-runner:
image: '${GITLAB_RUNNER_IMAGE:-gitlab/gitlab-runner}:${GITLAB_RUNNER_TAG:-latest}'
container_name: 'gitlab-runner-test'
depends_on:
- gitlab
networks:
- gitlab-network
26 changes: 26 additions & 0 deletions gitlab/testing/docker/docker.py
Show comments Show annotations View file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
pytest-docker fixture overrides.
See https://github.com/avast/pytest-docker#available-fixtures.
"""

import pytest

Check warning on line 6 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L6

Added line #L6 was not covered by tests


@pytest.fixture(scope="session")
def docker_compose_project_name():

Check warning on line 10 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L9-L10

Added lines #L9 - L10 were not covered by tests
"""Set a consistent project name to enable optional reuse of containers."""
return "pytest-python-gitlab"

Check warning on line 12 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L12

Added line #L12 was not covered by tests


@pytest.fixture(scope="session")
def docker_compose_file(docker_assets_dir):
return docker_assets_dir / "docker-compose.yml"

Check warning on line 17 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L15-L17

Added lines #L15 - L17 were not covered by tests


@pytest.fixture(scope="session")
def docker_cleanup(request):

Check warning on line 21 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L20-L21

Added lines #L20 - L21 were not covered by tests
"""Conditionally keep containers around by overriding the cleanup command."""
if request.config.getoption("--keep-containers"):

Check warning on line 23 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L23

Added line #L23 was not covered by tests
# Print version and exit.
return "-v"
return "down -v"

Check warning on line 26 in gitlab/testing/docker/docker.py

View check run for this annotation

Codecov / codecov/patch

gitlab/testing/docker/docker.py#L25-L26

Added lines #L25 - L26 were not covered by tests
11 changes: 11 additions & 0 deletions gitlab/testing/docker/install_docker.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apt-get update
apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
apt-get update
echo \
"deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install -y docker-ce docker-compose
usermod -aG docker gitlab-runner
9 changes: 9 additions & 0 deletions gitlab/testing/docker/set_token.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#programmatically-creating-a-personal-access-token

user = User.find_by_username('root')

token = user.personal_access_tokens.first_or_create(scopes: ['api', 'sudo'], name: 'default', expires_at: 365.days.from_now);
token.set_token('glpat-python-gitlab-token_');
token.save!

puts token.token
Empty file.
Loading

Back | FazBrowse Home | New Git URL