Skip to content

Commit 323ab3c

Browse files
nejchJohnVillalovos
authored andcommitted
test: add tests and clean up usage for new enums
1 parent d652133 commit 323ab3c

File tree

12 files changed

+84
-45
lines changed

12 files changed

+84
-45
lines changed

docs/gl_objects/access_requests.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Create an access request::
4343
Approve an access request::
4444

4545
ar.approve() # defaults to DEVELOPER level
46-
ar.approve(access_level=gitlab.const.AccessLevel.MAINTAINER.value) # explicitly set access level
46+
ar.approve(access_level=gitlab.const.AccessLevel.MAINTAINER) # explicitly set access level
4747

4848
Deny (delete) an access request::
4949

docs/gl_objects/groups.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Remove a group::
8080

8181
Share/unshare the group with a group::
8282

83-
group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER.value)
83+
group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER)
8484
group.unshare(group2.id)
8585

8686
Import / Export
@@ -284,11 +284,11 @@ Get a member of a group, including members inherited through ancestor groups::
284284
Add a member to the group::
285285

286286
member = group.members.create({'user_id': user_id,
287-
'access_level': gitlab.const.AccessLevel.GUEST.value})
287+
'access_level': gitlab.const.AccessLevel.GUEST})
288288

289289
Update a member (change the access level)::
290290

291-
member.access_level = gitlab.const.AccessLevel.DEVELOPER.value
291+
member.access_level = gitlab.const.AccessLevel.DEVELOPER
292292
member.save()
293293

294294
Remove a member from the group::
@@ -316,7 +316,7 @@ LDAP group links
316316

317317
Add an LDAP group link to an existing GitLab group::
318318

319-
group.add_ldap_group_link(ldap_group_cn, gitlab.const.AccessLevel.DEVELOPER.value, 'ldapmain')
319+
group.add_ldap_group_link(ldap_group_cn, gitlab.const.AccessLevel.DEVELOPER, 'ldapmain')
320320

321321
Remove a link::
322322

docs/gl_objects/notifications.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ Get the notifications settings::
4747
Update the notifications settings::
4848

4949
# use a predefined level
50-
settings.level = gitlab.const.NotificationLevel.WATCH.value
50+
settings.level = gitlab.const.NotificationLevel.WATCH
5151

5252
# create a custom setup
53-
settings.level = gitlab.const.NotificationLevel.CUSTOM.value
53+
settings.level = gitlab.const.NotificationLevel.CUSTOM
5454
settings.save() # will create additional attributes, but not mandatory
5555

5656
settings.new_merge_request = True

docs/gl_objects/projects.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ Create a snippet::
511511
'file_name': 'foo.py',
512512
'code': 'import gitlab',
513513
'visibility_level':
514-
gitlab.const.Visibility.PRIVATE.value})
514+
gitlab.const.Visibility.PRIVATE})
515515

516516
Update a snippet::
517517

@@ -577,11 +577,11 @@ Get a member of a project, including members inherited through ancestor groups::
577577
Add a project member::
578578

579579
member = project.members.create({'user_id': user.id, 'access_level':
580-
gitlab.const.AccessLevel.DEVELOPER.value})
580+
gitlab.const.AccessLevel.DEVELOPER})
581581

582582
Modify a project member (change the access level)::
583583

584-
member.access_level = gitlab.const.AccessLevel.MAINTAINER.value
584+
member.access_level = gitlab.const.AccessLevel.MAINTAINER
585585
member.save()
586586

587587
Remove a member from the project team::
@@ -592,7 +592,7 @@ Remove a member from the project team::
592592

593593
Share/unshare the project with a group::
594594

595-
project.share(group.id, gitlab.const.AccessLevel.DEVELOPER.value)
595+
project.share(group.id, gitlab.const.AccessLevel.DEVELOPER)
596596
project.unshare(group.id)
597597

598598
Project hooks

docs/gl_objects/protected_branches.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Create a protected branch::
3131

3232
p_branch = project.protectedbranches.create({
3333
'name': '*-stable',
34-
'merge_access_level': gitlab.const.AccessLevel.DEVELOPER.value,
35-
'push_access_level': gitlab.const.AccessLevel.MAINTAINER.value
34+
'merge_access_level': gitlab.const.AccessLevel.DEVELOPER,
35+
'push_access_level': gitlab.const.AccessLevel.MAINTAINER
3636
})
3737

3838
Create a protected branch with more granular access control::
@@ -41,7 +41,7 @@ Create a protected branch with more granular access control::
4141
'name': '*-stable',
4242
'allowed_to_push': [{"user_id": 99}, {"user_id": 98}],
4343
'allowed_to_merge': [{"group_id": 653}],
44-
'allowed_to_unprotect': [{"access_level": gitlab.const.AccessLevel.MAINTAINER.value}]
44+
'allowed_to_unprotect': [{"access_level": gitlab.const.AccessLevel.MAINTAINER}]
4545
})
4646

4747
Delete a protected branch::

docs/gl_objects/search.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,30 @@ Examples
4646
Search for issues matching a specific string::
4747

4848
# global search
49-
gl.search(gitlab.const.SearchScope.ISSUES.value, 'regression')
49+
gl.search(gitlab.const.SearchScope.ISSUES, 'regression')
5050

5151
# group search
5252
group = gl.groups.get('mygroup')
53-
group.search(gitlab.const.SearchScope.ISSUES.value, 'regression')
53+
group.search(gitlab.const.SearchScope.ISSUES, 'regression')
5454

5555
# project search
5656
project = gl.projects.get('myproject')
57-
project.search(gitlab.const.SearchScope.ISSUES.value, 'regression')
57+
project.search(gitlab.const.SearchScope.ISSUES, 'regression')
5858

5959
The ``search()`` methods implement the pagination support::
6060

6161
# get lists of 10 items, and start at page 2
62-
gl.search(gitlab.const.SearchScope.ISSUES.value, search_str, page=2, per_page=10)
62+
gl.search(gitlab.const.SearchScope.ISSUES, search_str, page=2, per_page=10)
6363

6464
# get a generator that will automatically make required API calls for
6565
# pagination
66-
for item in gl.search(gitlab.const.SearchScope.ISSUES.value, search_str, iterator=True):
66+
for item in gl.search(gitlab.const.SearchScope.ISSUES, search_str, iterator=True):
6767
do_something(item)
6868

6969
The search API doesn't return objects, but dicts. If you need to act on
7070
objects, you need to create them explicitly::
7171

72-
for item in gl.search(gitlab.const.SearchScope.ISSUES.value, search_str, iterator=True):
72+
for item in gl.search(gitlab.const.SearchScope.ISSUES, search_str, iterator=True):
7373
issue_project = gl.projects.get(item['project_id'], lazy=True)
7474
issue = issue_project.issues.get(item['iid'])
7575
issue.state = 'closed'

docs/gl_objects/snippets.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Create a snippet::
4444

4545
Update the snippet attributes::
4646

47-
snippet.visibility_level = gitlab.const.Visibility.PUBLIC.value
47+
snippet.visibility_level = gitlab.const.Visibility.PUBLIC
4848
snippet.save()
4949

5050
To update a snippet code you need to create a ``ProjectSnippet`` object::

tests/functional/api/test_gitlab.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ def test_namespaces(gl):
125125

126126
def test_notification_settings(gl):
127127
settings = gl.notificationsettings.get()
128-
settings.level = gitlab.const.NOTIFICATION_LEVEL_WATCH
128+
settings.level = gitlab.const.NotificationLevel.WATCH
129129
settings.save()
130130

131131
settings = gl.notificationsettings.get()
132-
assert settings.level == gitlab.const.NOTIFICATION_LEVEL_WATCH
132+
assert settings.level == gitlab.const.NotificationLevel.WATCH
133133

134134

135135
def test_search(gl):
136-
result = gl.search(scope=gitlab.const.SEARCH_SCOPE_USERS, search="Administrator")
136+
result = gl.search(scope=gitlab.const.SearchScope.USERS, search="Administrator")
137137
assert result[0]["id"] == 1
138138

139139

tests/functional/api/test_groups.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ def test_groups(gl):
4343
assert group4 in filtered_groups
4444

4545
group1.members.create(
46-
{"access_level": gitlab.const.OWNER_ACCESS, "user_id": user.id}
46+
{"access_level": gitlab.const.AccessLevel.OWNER, "user_id": user.id}
4747
)
4848
group1.members.create(
49-
{"access_level": gitlab.const.GUEST_ACCESS, "user_id": user2.id}
49+
{"access_level": gitlab.const.AccessLevel.GUEST, "user_id": user2.id}
5050
)
5151
group2.members.create(
52-
{"access_level": gitlab.const.OWNER_ACCESS, "user_id": user2.id}
52+
{"access_level": gitlab.const.AccessLevel.OWNER, "user_id": user2.id}
5353
)
5454

55-
group4.share(group1.id, gitlab.const.DEVELOPER_ACCESS)
56-
group4.share(group2.id, gitlab.const.MAINTAINER_ACCESS)
55+
group4.share(group1.id, gitlab.const.AccessLevel.DEVELOPER)
56+
group4.share(group2.id, gitlab.const.AccessLevel.MAINTAINER)
5757
# Reload group4 to have updated shared_with_groups
5858
group4 = gl.groups.get(group4.id)
5959
assert len(group4.shared_with_groups) == 2
@@ -71,7 +71,7 @@ def test_groups(gl):
7171

7272
membership = memberships1[0]
7373
assert membership.source_type == "Namespace"
74-
assert membership.access_level == gitlab.const.OWNER_ACCESS
74+
assert membership.access_level == gitlab.const.AccessLevel.OWNER
7575

7676
project_memberships = user.memberships.list(type="Project")
7777
assert len(project_memberships) == 0
@@ -95,10 +95,10 @@ def test_groups(gl):
9595
assert len(group1.members.list()) == 2
9696
assert len(group1.members_all.list())
9797
member = group1.members.get(user2.id)
98-
member.access_level = gitlab.const.OWNER_ACCESS
98+
member.access_level = gitlab.const.AccessLevel.OWNER
9999
member.save()
100100
member = group1.members.get(user2.id)
101-
assert member.access_level == gitlab.const.OWNER_ACCESS
101+
assert member.access_level == gitlab.const.AccessLevel.OWNER
102102

103103
gl.auth()
104104
group2.members.delete(gl.user.id)

tests/functional/api/test_projects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
import gitlab
6+
from gitlab.const import AccessLevel
67
from gitlab.v4.objects.projects import ProjectStorage
78

89

@@ -36,6 +37,17 @@ def test_create_project(gl, user):
3637
sudo_project.delete()
3738

3839

40+
def test_project_members(user, project):
41+
member = project.members.create(
42+
{"user_id": user.id, "access_level": AccessLevel.DEVELOPER}
43+
)
44+
assert member in project.members.list()
45+
assert member.access_level == 30
46+
47+
member.delete()
48+
assert member not in project.members.list()
49+
50+
3951
def test_project_badges(project):
4052
badge_image = "http://example.com"
4153
badge_link = "http://example/img.svg"

0 commit comments

Comments
 (0)