Skip to content

Commit 4bef473

Browse files
TimKnight-DWPnejch
authored andcommitted
test: update api tests for GL 16.10
- 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>
1 parent b81da2e commit 4bef473

27 files changed

+140
-216
lines changed

tests/functional/api/test_boards.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ def test_project_boards(project):
55
board = project.boards.get(board.id)
66

77
project.boards.delete(board.id)
8-
assert not project.boards.list()
98

109

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

1716
group.boards.delete(board.id)
18-
assert not group.boards.list()

tests/functional/api/test_bulk_imports.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
23
import pytest
34

45
import gitlab
@@ -15,14 +16,16 @@ def bulk_import_enabled(gl: gitlab.Gitlab):
1516
# todo: why so fussy with feature flag timing?
1617
time.sleep(5)
1718
get_settings = gl.settings.get()
18-
assert get_settings.bulk_import_enabled == True
19+
assert get_settings.bulk_import_enabled is True
1920

2021
yield settings
2122

2223
settings.bulk_import_enabled = bulk_import_default
2324
settings.save()
2425

2526

27+
# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
28+
@pytest.mark.xfail(reason="Bulk Imports to be worked on in a follow up")
2629
def test_bulk_imports(gl, group, bulk_import_enabled):
2730
destination = f"{group.full_path}-import"
2831
configuration = {

tests/functional/api/test_current_user.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ def test_current_user_email(gl):
44
assert mail in gl.user.emails.list()
55

66
mail.delete()
7-
assert mail not in gl.user.emails.list()
87

98

109
def test_current_user_gpg_keys(gl, GPG_KEY):
@@ -14,8 +13,8 @@ def test_current_user_gpg_keys(gl, GPG_KEY):
1413

1514
# Seems broken on the gitlab side
1615
gkey = gl.user.gpgkeys.get(gkey.id)
16+
1717
gkey.delete()
18-
assert gkey not in gl.user.gpgkeys.list()
1918

2019

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

2625
key.delete()
27-
assert key not in gl.user.keys.list()
2826

2927

3028
def test_current_user_status(gl):

tests/functional/api/test_deploy_keys.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ def test_project_deploy_keys(gl, project, DEPLOY_KEY):
77
assert deploy_key in project2.keys.list()
88

99
project2.keys.delete(deploy_key.id)
10-
assert deploy_key not in project2.keys.list()
10+
1111
project2.delete()

tests/functional/api/test_deploy_tokens.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from datetime import date
1+
import datetime
22

33

44
def test_project_deploy_tokens(gl, project):
5-
today = date.today().isoformat()
5+
today = datetime.date.today().isoformat()
66
deploy_token = project.deploytokens.create(
77
{
88
"name": "foo",
@@ -21,8 +21,6 @@ def test_project_deploy_tokens(gl, project):
2121
assert deploy_token.username == "bar"
2222

2323
deploy_token.delete()
24-
assert deploy_token not in project.deploytokens.list()
25-
assert deploy_token not in gl.deploytokens.list()
2624

2725

2826
def test_group_deploy_tokens(gl, group):
@@ -41,5 +39,3 @@ def test_group_deploy_tokens(gl, group):
4139
assert deploy_token.scopes == ["read_registry"]
4240

4341
deploy_token.delete()
44-
assert deploy_token not in group.deploytokens.list()
45-
assert deploy_token not in gl.deploytokens.list()

tests/functional/api/test_epics.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def test_epic_issues(epic, issue):
2323
assert epic.issues.list()
2424

2525
epic_issue.delete()
26-
assert not epic.issues.list()
2726

2827

2928
def test_epic_notes(epic):

tests/functional/api/test_gitlab.py

-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def test_broadcast_messages(gl, get_all_kwargs):
5353
assert msg.color == "#444444"
5454

5555
msg.delete()
56-
assert msg not in gl.broadcastmessages.list()
5756

5857

5958
def test_markdown(gl):
@@ -151,7 +150,6 @@ def test_hooks(gl):
151150
assert hook in gl.hooks.list()
152151

153152
hook.delete()
154-
assert hook not in gl.hooks.list()
155153

156154

157155
def test_namespaces(gl, get_all_kwargs):
@@ -202,7 +200,6 @@ def test_features(gl):
202200
assert feat in gl.features.list()
203201

204202
feat.delete()
205-
assert feat not in gl.features.list()
206203

207204

208205
def test_pagination(gl, project):

tests/functional/api/test_groups.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ def test_groups(gl):
105105
assert result[0].id == user.id
106106

107107
group1.members.delete(user.id)
108-
assert user not in group1.members.list()
108+
109109
assert group1.members_all.list()
110+
110111
member = group1.members.get(user2.id)
111112
member.access_level = gitlab.const.AccessLevel.OWNER
112113
member.save()
@@ -135,7 +136,6 @@ def test_group_labels(group):
135136
assert label.name == "Label:that requires:encoding"
136137

137138
label.delete()
138-
assert label not in group.labels.list()
139139

140140

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

196196
badge.delete()
197-
assert badge not in group.badges.list()
198197

199198

200199
def test_group_milestones(group):
@@ -228,7 +227,6 @@ def test_group_custom_attributes(gl, group):
228227
assert attr in group.customattributes.list()
229228

230229
attr.delete()
231-
assert attr not in group.customattributes.list()
232230

233231

234232
def test_group_subgroups_projects(gl, user):
@@ -270,7 +268,6 @@ def test_group_wiki(group):
270268
wiki.save()
271269

272270
wiki.delete()
273-
assert wiki not in group.wikis.list()
274271

275272

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

287284
hook.delete()
288-
assert hook not in group.hooks.list()
289285

290286

291287
def test_group_transfer(gl, group):

tests/functional/api/test_import_export.py

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gitlab
66

77

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

3334

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

7073

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

8287

88+
# https://github.com/python-gitlab/python-gitlab/pull/2790#pullrequestreview-1873617123
89+
@pytest.mark.xfail(
90+
reason="test_project_remote_import_s3 to be worked on in a follow up"
91+
)
8392
def test_project_remote_import_s3(gl):
8493
gl.features.set("import_project_from_remote_file_s3", True)
8594
with pytest.raises(gitlab.exceptions.GitlabImportError) as err_info:

tests/functional/api/test_issues.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def test_create_issue(project):
1818
assert issue in project.issues.list(state="opened")
1919
assert issue2 in project.issues.list(state="closed")
2020

21-
assert isinstance(issue.user_agent_detail(), dict)
22-
assert issue.user_agent_detail()["user_agent"]
2321
assert issue.participants()
2422
assert type(issue.closed_by()) == list
2523
assert type(issue.related_merge_requests()) == list
@@ -33,10 +31,7 @@ def test_issue_notes(issue):
3331
assert emoji in note.awardemojis.list()
3432

3533
emoji.delete()
36-
assert emoji not in note.awardemojis.list()
37-
3834
note.delete()
39-
assert note not in issue.notes.list()
4035

4136

4237
def test_issue_labels(project, issue):
@@ -62,8 +57,8 @@ def test_issue_links(project, issue):
6257
assert links
6358

6459
link_id = links[0].issue_link_id
60+
6561
issue.links.delete(link_id)
66-
assert not issue.links.list()
6762

6863

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

116111
d_note_from_get.delete()
117-
discussion = issue.discussions.get(discussion.id)
118-
assert len(discussion.attributes["notes"]) == 1

tests/functional/api/test_lazy_objects.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import pytest
24

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

2931

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

0 commit comments

Comments
 (0)