-
Notifications
You must be signed in to change notification settings - Fork 674
feat: integrate pytest-gitlab #3313
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
Draft
ptalbert
wants to merge
5
commits into
python-gitlab:main
Choose a base branch
from
ptalbert:add_pytest-gitlab
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
591ca65
chore(flake8): set extend-exclude option in lieu of exclude and add .…
ptalbert c650edb
feat(testing): incorporate pytest-gitlab plugin framework
ptalbert c2aecc4
chore(pytest-gitlab): rename fixture_dir to docker_assets_dir
ptalbert 0f114d5
test: add a basic test to confirm the expected pytest `gitlab` plugin…
ptalbert 5414694
fix(tests): exclude new pytest-gitlab plugin when running tests via tox
ptalbert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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.
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" => "[email protected]", | ||
| } | ||
|
|
||
| # 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) } |
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 | ||
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 | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def docker_compose_project_name(): | ||
| """Set a consistent project name to enable optional reuse of containers.""" | ||
| return "pytest-python-gitlab" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def docker_compose_file(docker_assets_dir): | ||
| return docker_assets_dir / "docker-compose.yml" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def docker_cleanup(request): | ||
| """Conditionally keep containers around by overriding the cleanup command.""" | ||
| if request.config.getoption("--keep-containers"): | ||
| # Print version and exit. | ||
| return "-v" | ||
| return "down -v" | ||
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 |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we maybe extract the preparation changes (everything that can be applied without moving the plugin) into a separate PR that we merge first? Just so we can focus on integration aspects here. Let me know otherwise I can also try that on my end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize there was so much drift between the fixtures in pytest-gitlab and python-gitlab fixtures.
To hopefully simplify things, I've redone this PR using the current python-gitlab fixtures as the starting point. It adds the pytest-gitlab plugin but stops short of having the existing tests use any of it. A follow up PR can switch the tests over.
Hopefully this makes more sense. Let me know.