Skip to content

Commit

Permalink
test: update api tests for GL 16.10
Browse files Browse the repository at this point in the history
- Make sure we're testing python-gitlab functionality,
make sure we're not awaiting on Gitlab Async functions
- Decouple and improve test stability

Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk>
  • Loading branch information
TimKnight-DWP authored and nejch committed Apr 25, 2024
1 parent b81da2e commit 4bef473
Show file tree
Hide file tree
Showing 27 changed files with 140 additions and 216 deletions.
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()
5 changes: 4 additions & 1 deletion tests/functional/api/test_bulk_imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time

import pytest

import gitlab
Expand All @@ -15,14 +16,16 @@ def bulk_import_enabled(gl: gitlab.Gitlab):
# todo: why so fussy with feature flag timing?
time.sleep(5)
get_settings = gl.settings.get()
assert get_settings.bulk_import_enabled == True
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 = {
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()
8 changes: 2 additions & 6 deletions tests/functional/api/test_deploy_tokens.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from datetime import date
import datetime


def test_project_deploy_tokens(gl, project):
today = date.today().isoformat()
today = datetime.date.today().isoformat()
deploy_token = project.deploytokens.create(
{
"name": "foo",
Expand All @@ -21,8 +21,6 @@ def test_project_deploy_tokens(gl, project):
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 @@ -41,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
8 changes: 2 additions & 6 deletions tests/functional/api/test_groups.py
Original file line number Diff line number Diff line change
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

0 comments on commit 4bef473

Please sign in to comment.