Skip to content

Commit f8283ae

Browse files
TimKnight-DWPnejch
authored andcommitted
test: update tests for gitlab 16.8 functionality
- use programmatic dates for expires_at in tokens tests - set PAT for 16.8 into tests Signed-off-by: Tim Knight <tim.knight1@engineering.digital.dwp.gov.uk>
1 parent ea8c4c2 commit f8283ae

12 files changed

+153
-79
lines changed

docs/cli-examples.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ CLI examples
99
CI Lint
1010
-------
1111

12+
**ci-lint has been Removed in Gitlab 16, use project-ci-lint instead**
13+
1214
Lint a CI YAML configuration from a string:
1315

14-
.. note::
16+
.. note::
1517

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

@@ -39,6 +41,9 @@ Validate a CI YAML configuration from a file (lints and exits with non-zero on f
3941
4042
$ gitlab ci-lint validate --content @.gitlab-ci.yml
4143
44+
Project CI Lint
45+
---------------
46+
4247
Lint a project's CI YAML configuration:
4348

4449
.. code-block:: console

tests/functional/api/test_deploy_tokens.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
from datetime import date
2+
3+
14
def test_project_deploy_tokens(gl, project):
5+
today = date.today().isoformat()
26
deploy_token = project.deploytokens.create(
37
{
48
"name": "foo",
59
"username": "bar",
6-
"expires_at": "2022-01-01",
10+
"expires_at": today,
711
"scopes": ["read_registry"],
812
}
913
)
@@ -12,7 +16,7 @@ def test_project_deploy_tokens(gl, project):
1216

1317
deploy_token = project.deploytokens.get(deploy_token.id)
1418
assert deploy_token.name == "foo"
15-
assert deploy_token.expires_at == "2022-01-01T00:00:00.000Z"
19+
assert deploy_token.expires_at == today + "T00:00:00.000Z"
1620
assert deploy_token.scopes == ["read_registry"]
1721
assert deploy_token.username == "bar"
1822

tests/functional/api/test_groups.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ def test_groups(gl):
1010
"email": "user@test.com",
1111
"username": "user",
1212
"name": "user",
13-
"password": "user_pass",
13+
"password": "E4596f8be406Bc3a14a4ccdb1df80587",
1414
}
1515
)
1616
user2 = gl.users.create(
1717
{
1818
"email": "user2@test.com",
1919
"username": "user2",
2020
"name": "user2",
21-
"password": "user2_pass",
21+
"password": "E4596f8be406Bc3a14a4ccdb1df80587$2",
2222
}
2323
)
2424
group1 = gl.groups.create(

tests/functional/api/test_merge_requests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_merge_requests(project):
1616
}
1717
)
1818

19-
source_branch = "branch1"
19+
source_branch = "branch-merge-request-api"
2020
project.branches.create({"branch": source_branch, "ref": "main"})
2121

2222
project.files.create(
@@ -28,7 +28,7 @@ def test_merge_requests(project):
2828
}
2929
)
3030
project.mergerequests.create(
31-
{"source_branch": "branch1", "target_branch": "main", "title": "MR readme2"}
31+
{"source_branch": source_branch, "target_branch": "main", "title": "MR readme2"}
3232
)
3333

3434

tests/functional/api/test_users.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_create_user(gl, fixture_dir):
1313
"email": "foo@bar.com",
1414
"username": "foo",
1515
"name": "foo",
16-
"password": "foo_password",
16+
"password": "E4596f8be406Bc3a14a4ccdb1df80587$3",
1717
"avatar": open(fixture_dir / "avatar.png", "rb"),
1818
}
1919
)

tests/functional/cli/test_cli_repository.py

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

45

@@ -31,9 +32,13 @@ def test_list_all_commits(gitlab_cli, project):
3132
data = {
3233
"branch": "new-branch",
3334
"start_branch": "main",
34-
"commit_message": "New commit on new branch",
35+
"commit_message": "chore: test commit on new branch",
3536
"actions": [
36-
{"action": "create", "file_path": "new-file", "content": "new content"}
37+
{
38+
"action": "create",
39+
"file_path": "test-cli-repo.md",
40+
"content": "new content",
41+
}
3742
],
3843
}
3944
commit = project.commits.create(data)
@@ -76,6 +81,19 @@ def test_commit_merge_requests(gitlab_cli, project, merge_request, wait_for_side
7681
"""This tests the `project-commit merge-requests` command and also tests
7782
that we can print the result using the `json` formatter"""
7883
# Merge the MR first
84+
wait_for_sidekiq(timeout=60)
85+
86+
logging.info(f"MR status: {merge_request.state}")
87+
logging.info(f"MR merge status: {merge_request.detailed_merge_status}")
88+
89+
if merge_request.detailed_merge_status == "not_approved":
90+
logging.info("Approving Merge Request")
91+
92+
merge_request.approve()
93+
94+
logging.info(f"MR merge status: {merge_request.detailed_merge_status}")
95+
time.sleep(5)
96+
7997
merge_result = merge_request.merge(should_remove_source_branch=True)
8098
wait_for_sidekiq(timeout=60)
8199

tests/functional/cli/test_cli_resource_access_tokens.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pytest
1+
from datetime import date
22

33

44
def test_list_project_access_tokens(gitlab_cli, project):
@@ -18,13 +18,14 @@ def test_create_project_access_token_with_scopes(gitlab_cli, project):
1818
"test-token",
1919
"--scopes",
2020
"api,read_repository",
21+
"--expires-at",
22+
date.today().isoformat(),
2123
]
2224
ret = gitlab_cli(cmd)
2325

2426
assert ret.success
2527

2628

27-
@pytest.mark.skip(reason="Requires GitLab 14.7")
2829
def test_list_group_access_tokens(gitlab_cli, group):
2930
cmd = ["group-access-token", "list", "--group-id", group.id]
3031
ret = gitlab_cli(cmd)
@@ -42,6 +43,8 @@ def test_create_group_access_token_with_scopes(gitlab_cli, group):
4243
"test-token",
4344
"--scopes",
4445
"api,read_repository",
46+
"--expires-at",
47+
date.today().isoformat(),
4548
]
4649
ret = gitlab_cli(cmd)
4750

tests/functional/cli/test_cli_users.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from datetime import date
2+
3+
14
def test_create_user_impersonation_token_with_scopes(gitlab_cli, user):
25
cmd = [
36
"user-impersonation-token",
@@ -8,6 +11,8 @@ def test_create_user_impersonation_token_with_scopes(gitlab_cli, user):
811
"test-token",
912
"--scopes",
1013
"api,read_user",
14+
"--expires-at",
15+
date.today().isoformat(),
1116
]
1217
ret = gitlab_cli(cmd)
1318

tests/functional/cli/test_cli_v4.py

+32-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import logging
12
import os
23
import time
4+
from datetime import date
5+
6+
branch = "branch-cli-v4"
37

48

59
def test_create_project(gitlab_cli):
@@ -22,28 +26,6 @@ def test_update_project(gitlab_cli, project):
2226
assert description in ret.stdout
2327

2428

25-
def test_create_ci_lint(gitlab_cli, valid_gitlab_ci_yml):
26-
cmd = ["ci-lint", "create", "--content", valid_gitlab_ci_yml]
27-
ret = gitlab_cli(cmd)
28-
29-
assert ret.success
30-
31-
32-
def test_validate_ci_lint(gitlab_cli, valid_gitlab_ci_yml):
33-
cmd = ["ci-lint", "validate", "--content", valid_gitlab_ci_yml]
34-
ret = gitlab_cli(cmd)
35-
36-
assert ret.success
37-
38-
39-
def test_validate_ci_lint_invalid_exits_non_zero(gitlab_cli, invalid_gitlab_ci_yml):
40-
cmd = ["ci-lint", "validate", "--content", invalid_gitlab_ci_yml]
41-
ret = gitlab_cli(cmd)
42-
43-
assert not ret.success
44-
assert "CI YAML Lint failed (Invalid configuration format)" in ret.stderr
45-
46-
4729
def test_validate_project_ci_lint(gitlab_cli, project, valid_gitlab_ci_yml):
4830
cmd = [
4931
"project-ci-lint",
@@ -103,7 +85,7 @@ def test_create_user(gitlab_cli, gl):
10385
email = "fake@email.com"
10486
username = "user1"
10587
name = "User One"
106-
password = "fakepassword"
88+
password = "E4596f8be406Bc3a14a4ccdb1df80587"
10789

10890
cmd = [
10991
"user",
@@ -215,8 +197,6 @@ def test_create_issue_note(gitlab_cli, issue):
215197

216198

217199
def test_create_branch(gitlab_cli, project):
218-
branch = "branch1"
219-
220200
cmd = [
221201
"project-branch",
222202
"create",
@@ -233,7 +213,6 @@ def test_create_branch(gitlab_cli, project):
233213

234214

235215
def test_create_merge_request(gitlab_cli, project):
236-
branch = "branch1"
237216

238217
cmd = [
239218
"project-merge-request",
@@ -257,23 +236,43 @@ def test_accept_request_merge(gitlab_cli, project, wait_for_sidekiq):
257236
mr = project.mergerequests.list()[0]
258237
file_data = {
259238
"branch": mr.source_branch,
260-
"file_path": "README2",
239+
"file_path": "test-cli-v4.md",
261240
"content": "Content",
262-
"commit_message": "Pre-merge commit",
241+
"commit_message": "chore: test-cli-v4 change",
263242
}
264243
project.files.create(file_data)
265-
time.sleep(2)
244+
time.sleep(30)
266245
wait_for_sidekiq(timeout=60)
267246

268-
cmd = [
247+
logging.info(f"MR status: {mr.state}")
248+
logging.info(f"MR merge status: {mr.detailed_merge_status}")
249+
250+
if mr.detailed_merge_status == "not_approved":
251+
logging.info("Approving Merge Request")
252+
253+
approve_cmd = [
254+
"project-merge-request",
255+
"approve",
256+
"--project-id",
257+
project.id,
258+
"--iid",
259+
mr.iid,
260+
]
261+
gitlab_cli(approve_cmd)
262+
263+
time.sleep(5)
264+
logging.info(f"MR merge status: {mr.detailed_merge_status}")
265+
266+
time.sleep(0.5)
267+
approve_cmd = [
269268
"project-merge-request",
270269
"merge",
271270
"--project-id",
272271
project.id,
273272
"--iid",
274273
mr.iid,
275274
]
276-
ret = gitlab_cli(cmd)
275+
ret = gitlab_cli(approve_cmd)
277276

278277
assert ret.success
279278

@@ -501,9 +500,6 @@ def test_delete_project_variable(gitlab_cli, variable):
501500

502501

503502
def test_delete_branch(gitlab_cli, project):
504-
# TODO: branch fixture
505-
branch = "branch1"
506-
507503
cmd = ["project-branch", "delete", "--project-id", project.id, "--name", branch]
508504
ret = gitlab_cli(cmd)
509505

@@ -590,7 +586,7 @@ def test_create_project_with_values_at_prefixed(gitlab_cli, tmpdir):
590586
def test_create_project_deploy_token(gitlab_cli, project):
591587
name = "project-token"
592588
username = "root"
593-
expires_at = "2021-09-09"
589+
expires_at = date.today().isoformat()
594590
scopes = "read_registry"
595591

596592
cmd = [
@@ -666,7 +662,7 @@ def test_delete_project_deploy_token(gitlab_cli, deploy_token):
666662
def test_create_group_deploy_token(gitlab_cli, group):
667663
name = "group-token"
668664
username = "root"
669-
expires_at = "2021-09-09"
665+
expires_at = date.today().isoformat()
670666
scopes = "read_registry"
671667

672668
cmd = [

0 commit comments

Comments
 (0)