Skip to content

test: update integration tests to run using Gitlab 16 #2790

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 8 commits into from
Apr 25, 2024
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
3 changes: 3 additions & 0 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ You need to install ``tox`` (``pip3 install tox``) to run tests and lint checks
# run unit tests in one python environment only (useful for quick testing during development):
tox -e py311

# run unit and smoke tests in one python environment only
tox -e py312,smoke

# build the documentation - the result will be generated in build/sphinx/html/:
tox -e docs

Expand Down
7 changes: 6 additions & 1 deletion docs/cli-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ CLI examples
CI Lint
-------

**ci-lint has been Removed in Gitlab 16, use project-ci-lint instead**

Lint a CI YAML configuration from a string:

.. note::
.. note::

To see output, you will need to use the ``-v``/``--verbose`` flag.

Expand Down Expand Up @@ -39,6 +41,9 @@ Validate a CI YAML configuration from a file (lints and exits with non-zero on f

$ gitlab ci-lint validate --content @.gitlab-ci.yml

Project CI Lint
---------------

Lint a project's CI YAML configuration:

.. code-block:: console
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/api/test_boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ def test_project_boards(project):
board = project.boards.get(board.id)

project.boards.delete(board.id)
assert not project.boards.list()


def test_group_boards(group):
Expand All @@ -15,4 +14,3 @@ def test_group_boards(group):
board = group.boards.get(board.id)

group.boards.delete(board.id)
assert not group.boards.list()
30 changes: 29 additions & 1 deletion tests/functional/api/test_bulk_imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
def test_bulk_imports(gl, group):
import time

import pytest

import gitlab


@pytest.fixture
def bulk_import_enabled(gl: gitlab.Gitlab):
settings = gl.settings.get()
bulk_import_default = settings.bulk_import_enabled

settings.bulk_import_enabled = True
settings.save()

# todo: why so fussy with feature flag timing?
time.sleep(5)
get_settings = gl.settings.get()
assert get_settings.bulk_import_enabled is True

yield settings

settings.bulk_import_enabled = bulk_import_default
settings.save()


# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
@pytest.mark.xfail(reason="Bulk Imports to be worked on in a follow up")
def test_bulk_imports(gl, group, bulk_import_enabled):
destination = f"{group.full_path}-import"
configuration = {
"url": gl.url,
Expand Down
4 changes: 1 addition & 3 deletions tests/functional/api/test_current_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ def test_current_user_email(gl):
assert mail in gl.user.emails.list()

mail.delete()
assert mail not in gl.user.emails.list()


def test_current_user_gpg_keys(gl, GPG_KEY):
Expand All @@ -14,8 +13,8 @@ def test_current_user_gpg_keys(gl, GPG_KEY):

# Seems broken on the gitlab side
gkey = gl.user.gpgkeys.get(gkey.id)

gkey.delete()
assert gkey not in gl.user.gpgkeys.list()


def test_current_user_ssh_keys(gl, SSH_KEY):
Expand All @@ -24,7 +23,6 @@ def test_current_user_ssh_keys(gl, SSH_KEY):
assert key in gl.user.keys.list()

key.delete()
assert key not in gl.user.keys.list()


def test_current_user_status(gl):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/api/test_deploy_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ def test_project_deploy_keys(gl, project, DEPLOY_KEY):
assert deploy_key in project2.keys.list()

project2.keys.delete(deploy_key.id)
assert deploy_key not in project2.keys.list()

project2.delete()
12 changes: 6 additions & 6 deletions tests/functional/api/test_deploy_tokens.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import datetime


def test_project_deploy_tokens(gl, project):
today = datetime.date.today().isoformat()
deploy_token = project.deploytokens.create(
{
"name": "foo",
"username": "bar",
"expires_at": "2022-01-01",
"expires_at": today,
"scopes": ["read_registry"],
}
)
Expand All @@ -12,13 +16,11 @@ def test_project_deploy_tokens(gl, project):

deploy_token = project.deploytokens.get(deploy_token.id)
assert deploy_token.name == "foo"
assert deploy_token.expires_at == "2022-01-01T00:00:00.000Z"
assert deploy_token.expires_at == f"{today}T00:00:00.000Z"
assert deploy_token.scopes == ["read_registry"]
assert deploy_token.username == "bar"

deploy_token.delete()
assert deploy_token not in project.deploytokens.list()
assert deploy_token not in gl.deploytokens.list()


def test_group_deploy_tokens(gl, group):
Expand All @@ -37,5 +39,3 @@ def test_group_deploy_tokens(gl, group):
assert deploy_token.scopes == ["read_registry"]

deploy_token.delete()
assert deploy_token not in group.deploytokens.list()
assert deploy_token not in gl.deploytokens.list()
1 change: 0 additions & 1 deletion tests/functional/api/test_epics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def test_epic_issues(epic, issue):
assert epic.issues.list()

epic_issue.delete()
assert not epic.issues.list()


def test_epic_notes(epic):
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/api/test_gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def test_broadcast_messages(gl, get_all_kwargs):
assert msg.color == "#444444"

msg.delete()
assert msg not in gl.broadcastmessages.list()


def test_markdown(gl):
Expand Down Expand Up @@ -151,7 +150,6 @@ def test_hooks(gl):
assert hook in gl.hooks.list()

hook.delete()
assert hook not in gl.hooks.list()


def test_namespaces(gl, get_all_kwargs):
Expand Down Expand Up @@ -202,7 +200,6 @@ def test_features(gl):
assert feat in gl.features.list()

feat.delete()
assert feat not in gl.features.list()


def test_pagination(gl, project):
Expand Down
12 changes: 4 additions & 8 deletions tests/functional/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ def test_groups(gl):
"email": "user@test.com",
"username": "user",
"name": "user",
"password": "user_pass",
"password": "E4596f8be406Bc3a14a4ccdb1df80587#!1",
}
)
user2 = gl.users.create(
{
"email": "user2@test.com",
"username": "user2",
"name": "user2",
"password": "user2_pass",
"password": "E4596f8be406Bc3a14a4ccdb1df80587#!#2",
}
)
group1 = gl.groups.create(
Expand Down Expand Up @@ -105,8 +105,9 @@ def test_groups(gl):
assert result[0].id == user.id

group1.members.delete(user.id)
assert user not in group1.members.list()

assert group1.members_all.list()

member = group1.members.get(user2.id)
member.access_level = gitlab.const.AccessLevel.OWNER
member.save()
Expand Down Expand Up @@ -135,7 +136,6 @@ def test_group_labels(group):
assert label.name == "Label:that requires:encoding"

label.delete()
assert label not in group.labels.list()


@pytest.mark.gitlab_premium
Expand Down Expand Up @@ -194,7 +194,6 @@ def test_group_badges(group):
assert badge.image_url == "http://another.example.com"

badge.delete()
assert badge not in group.badges.list()


def test_group_milestones(group):
Expand Down Expand Up @@ -228,7 +227,6 @@ def test_group_custom_attributes(gl, group):
assert attr in group.customattributes.list()

attr.delete()
assert attr not in group.customattributes.list()


def test_group_subgroups_projects(gl, user):
Expand Down Expand Up @@ -270,7 +268,6 @@ def test_group_wiki(group):
wiki.save()

wiki.delete()
assert wiki not in group.wikis.list()


@pytest.mark.gitlab_premium
Expand All @@ -285,7 +282,6 @@ def test_group_hooks(group):
assert hook.note_events is True

hook.delete()
assert hook not in group.hooks.list()


def test_group_transfer(gl, group):
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/api/test_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import gitlab


# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
def test_group_import_export(gl, group, temp_dir):
export = group.exports.create()
assert export.message == "202 Accepted"
Expand All @@ -31,6 +32,8 @@ def test_group_import_export(gl, group, temp_dir):
assert group_import.name == import_name


# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
@pytest.mark.xfail(reason="test_project_import_export to be worked on in a follow up")
def test_project_import_export(gl, project, temp_dir):
export = project.exports.create()
assert export.message == "202 Accepted"
Expand Down Expand Up @@ -68,6 +71,8 @@ def test_project_import_export(gl, project, temp_dir):
raise Exception("Project import taking too much time")


# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
@pytest.mark.xfail(reason="test_project_remote_import to be worked on in a follow up")
def test_project_remote_import(gl):
with pytest.raises(gitlab.exceptions.GitlabImportError) as err_info:
gl.projects.remote_import(
Expand All @@ -80,6 +85,10 @@ def test_project_remote_import(gl):
)


# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
@pytest.mark.xfail(
reason="test_project_remote_import_s3 to be worked on in a follow up"
)
def test_project_remote_import_s3(gl):
gl.features.set("import_project_from_remote_file_s3", True)
with pytest.raises(gitlab.exceptions.GitlabImportError) as err_info:
Expand Down
9 changes: 1 addition & 8 deletions tests/functional/api/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def test_create_issue(project):
assert issue in project.issues.list(state="opened")
assert issue2 in project.issues.list(state="closed")

assert isinstance(issue.user_agent_detail(), dict)
assert issue.user_agent_detail()["user_agent"]
assert issue.participants()
assert type(issue.closed_by()) == list
assert type(issue.related_merge_requests()) == list
Expand All @@ -33,10 +31,7 @@ def test_issue_notes(issue):
assert emoji in note.awardemojis.list()

emoji.delete()
assert emoji not in note.awardemojis.list()

note.delete()
assert note not in issue.notes.list()


def test_issue_labels(project, issue):
Expand All @@ -62,8 +57,8 @@ def test_issue_links(project, issue):
assert links

link_id = links[0].issue_link_id

issue.links.delete(link_id)
assert not issue.links.list()


def test_issue_label_events(issue):
Expand Down Expand Up @@ -114,5 +109,3 @@ def test_issue_discussions(issue):
assert discussion.attributes["notes"][-1]["body"] == "updated body"

d_note_from_get.delete()
discussion = issue.discussions.get(discussion.id)
assert len(discussion.attributes["notes"]) == 1
7 changes: 5 additions & 2 deletions tests/functional/api/test_lazy_objects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

import pytest

import gitlab
Expand Down Expand Up @@ -27,9 +29,10 @@ def test_save_after_lazy_get_with_path(project, lazy_project):
assert lazy_project.description == "A new description"


def test_delete_after_lazy_get_with_path(gl, group, wait_for_sidekiq):
def test_delete_after_lazy_get_with_path(gl, group):
project = gl.projects.create({"name": "lazy_project", "namespace_id": group.id})
wait_for_sidekiq(timeout=60)
# Pause to let GL catch up (happens on hosted too, sometimes takes a while for server to be ready to merge)
time.sleep(5)
lazy_project = gl.projects.get(project.path_with_namespace, lazy=True)
lazy_project.delete()

Expand Down
Loading