Skip to content

Commit 7c46e4d

Browse files
committed
Merge branch 'issue-2264-add-application-statistics' of https://github.com/Shreya-7/python-gitlab into issue-2264-add-application-statistics
2 parents 153e53b + 08b9502 commit 7c46e4d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

tests/functional/api/test_statistics.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
GitLab API: https://docs.gitlab.com/ee/api/statistics.html
33
"""
44

5+
from tests.functional.conftest import reset_gitlab
6+
57

68
def test_get_statistics(gl):
7-
gl.projects.create({"name": "projecttruffles"})
9+
10+
# delete resources created from other functional tests to reset application statistics
11+
reset_gitlab(gl)
12+
813
gl.users.create(
914
{
1015
"email": "veryuniqueemail@test.com",

tests/functional/conftest.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None:
9494
helpers.safe_delete(deploy_token)
9595
logging.info(f"Deleting project: {project.path_with_namespace!r}")
9696
helpers.safe_delete(project)
97+
9798
for group in gl.groups.list():
99+
100+
# skip deletion of a descendant group to prevent scenarios where parent group gets deleted leaving a dangling descendant whose deletion will throw 404s.
101+
# descendant groups cannot contain the `/` special character: https://docs.gitlab.com/ee/user/reserved_names.html#limitations-on-project-and-group-names
102+
if "/" in group.full_path:
103+
logging.info(
104+
f"Skipping deletion of {group.full_path} as it is a descendant group and will be removed when the parent group is deleted"
105+
)
106+
continue
107+
98108
for deploy_token in group.deploytokens.list():
99109
logging.info(
100110
f"Deleting deploy token: {deploy_token.username!r} in "
@@ -110,7 +120,7 @@ def reset_gitlab(gl: gitlab.Gitlab) -> None:
110120
logging.info(f"Deleting variable: {variable.key!r}")
111121
helpers.safe_delete(variable)
112122
for user in gl.users.list():
113-
if user.username != "root":
123+
if user.username not in ["root", "ghost"]:
114124
logging.info(f"Deleting user: {user.username!r}")
115125
helpers.safe_delete(user, hard_delete=True)
116126

0 commit comments

Comments
 (0)