| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d652133 commit 323ab3c
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,7 @@ Create an access request:: | |||
| 43 | 43 | Approve an access request:: | |
| 44 | 44 | ||
| 45 | 45 | 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 | ||
| 47 | 47 | ||
| 48 | 48 | Deny (delete) an access request:: | |
| 49 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,7 +80,7 @@ Remove a group:: | |||
| 80 | 80 | ||
| 81 | 81 | Share/unshare the group with a group:: | |
| 82 | 82 | ||
| 83 | - group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER.value) | ||
| 83 | + group.share(group2.id, gitlab.const.AccessLevel.DEVELOPER) | ||
| 84 | 84 | group.unshare(group2.id) | |
| 85 | 85 | ||
| 86 | 86 | Import / Export | |
@@ -284,11 +284,11 @@ Get a member of a group, including members inherited through ancestor groups:: | |||
| 284 | 284 | Add a member to the group:: | |
| 285 | 285 | ||
| 286 | 286 | member = group.members.create({'user_id': user_id, | |
| 287 | - 'access_level': gitlab.const.AccessLevel.GUEST.value}) | ||
| 287 | + 'access_level': gitlab.const.AccessLevel.GUEST}) | ||
| 288 | 288 | ||
| 289 | 289 | Update a member (change the access level):: | |
| 290 | 290 | ||
| 291 | - member.access_level = gitlab.const.AccessLevel.DEVELOPER.value | ||
| 291 | + member.access_level = gitlab.const.AccessLevel.DEVELOPER | ||
| 292 | 292 | member.save() | |
| 293 | 293 | ||
| 294 | 294 | Remove a member from the group:: | |
@@ -316,7 +316,7 @@ LDAP group links | |||
| 316 | 316 | ||
| 317 | 317 | Add an LDAP group link to an existing GitLab group:: | |
| 318 | 318 | ||
| 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') | ||
| 320 | 320 | ||
| 321 | 321 | Remove a link:: | |
| 322 | 322 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,10 +47,10 @@ Get the notifications settings:: | |||
| 47 | 47 | Update the notifications settings:: | |
| 48 | 48 | ||
| 49 | 49 | # use a predefined level | |
| 50 | - settings.level = gitlab.const.NotificationLevel.WATCH.value | ||
| 50 | + settings.level = gitlab.const.NotificationLevel.WATCH | ||
| 51 | 51 | ||
| 52 | 52 | # create a custom setup | |
| 53 | - settings.level = gitlab.const.NotificationLevel.CUSTOM.value | ||
| 53 | + settings.level = gitlab.const.NotificationLevel.CUSTOM | ||
| 54 | 54 | settings.save() # will create additional attributes, but not mandatory | |
| 55 | 55 | ||
| 56 | 56 | settings.new_merge_request = True | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -511,7 +511,7 @@ Create a snippet:: | |||
| 511 | 511 | 'file_name': 'foo.py', | |
| 512 | 512 | 'code': 'import gitlab', | |
| 513 | 513 | 'visibility_level': | |
| 514 | - gitlab.const.Visibility.PRIVATE.value}) | ||
| 514 | + gitlab.const.Visibility.PRIVATE}) | ||
| 515 | 515 | ||
| 516 | 516 | Update a snippet:: | |
| 517 | 517 | ||
@@ -577,11 +577,11 @@ Get a member of a project, including members inherited through ancestor groups:: | |||
| 577 | 577 | Add a project member:: | |
| 578 | 578 | ||
| 579 | 579 | member = project.members.create({'user_id': user.id, 'access_level': | |
| 580 | - gitlab.const.AccessLevel.DEVELOPER.value}) | ||
| 580 | + gitlab.const.AccessLevel.DEVELOPER}) | ||
| 581 | 581 | ||
| 582 | 582 | Modify a project member (change the access level):: | |
| 583 | 583 | ||
| 584 | - member.access_level = gitlab.const.AccessLevel.MAINTAINER.value | ||
| 584 | + member.access_level = gitlab.const.AccessLevel.MAINTAINER | ||
| 585 | 585 | member.save() | |
| 586 | 586 | ||
| 587 | 587 | Remove a member from the project team:: | |
@@ -592,7 +592,7 @@ Remove a member from the project team:: | |||
| 592 | 592 | ||
| 593 | 593 | Share/unshare the project with a group:: | |
| 594 | 594 | ||
| 595 | - project.share(group.id, gitlab.const.AccessLevel.DEVELOPER.value) | ||
| 595 | + project.share(group.id, gitlab.const.AccessLevel.DEVELOPER) | ||
| 596 | 596 | project.unshare(group.id) | |
| 597 | 597 | ||
| 598 | 598 | Project hooks | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,8 +31,8 @@ Create a protected branch:: | |||
| 31 | 31 | ||
| 32 | 32 | p_branch = project.protectedbranches.create({ | |
| 33 | 33 | '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 | ||
| 36 | 36 | }) | |
| 37 | 37 | ||
| 38 | 38 | Create a protected branch with more granular access control:: | |
@@ -41,7 +41,7 @@ Create a protected branch with more granular access control:: | |||
| 41 | 41 | 'name': '*-stable', | |
| 42 | 42 | 'allowed_to_push': [{"user_id": 99}, {"user_id": 98}], | |
| 43 | 43 | '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}] | ||
| 45 | 45 | }) | |
| 46 | 46 | ||
| 47 | 47 | Delete a protected branch:: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,30 +46,30 @@ Examples | |||
| 46 | 46 | Search for issues matching a specific string:: | |
| 47 | 47 | ||
| 48 | 48 | # global search | |
| 49 | - gl.search(gitlab.const.SearchScope.ISSUES.value, 'regression') | ||
| 49 | + gl.search(gitlab.const.SearchScope.ISSUES, 'regression') | ||
| 50 | 50 | ||
| 51 | 51 | # group search | |
| 52 | 52 | group = gl.groups.get('mygroup') | |
| 53 | - group.search(gitlab.const.SearchScope.ISSUES.value, 'regression') | ||
| 53 | + group.search(gitlab.const.SearchScope.ISSUES, 'regression') | ||
| 54 | 54 | ||
| 55 | 55 | # project search | |
| 56 | 56 | project = gl.projects.get('myproject') | |
| 57 | - project.search(gitlab.const.SearchScope.ISSUES.value, 'regression') | ||
| 57 | + project.search(gitlab.const.SearchScope.ISSUES, 'regression') | ||
| 58 | 58 | ||
| 59 | 59 | The ``search()`` methods implement the pagination support:: | |
| 60 | 60 | ||
| 61 | 61 | # 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) | ||
| 63 | 63 | ||
| 64 | 64 | # get a generator that will automatically make required API calls for | |
| 65 | 65 | # 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): | ||
| 67 | 67 | do_something(item) | |
| 68 | 68 | ||
| 69 | 69 | The search API doesn't return objects, but dicts. If you need to act on | |
| 70 | 70 | objects, you need to create them explicitly:: | |
| 71 | 71 | ||
| 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): | ||
| 73 | 73 | issue_project = gl.projects.get(item['project_id'], lazy=True) | |
| 74 | 74 | issue = issue_project.issues.get(item['iid']) | |
| 75 | 75 | issue.state = 'closed' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ Create a snippet:: | |||
| 44 | 44 | ||
| 45 | 45 | Update the snippet attributes:: | |
| 46 | 46 | ||
| 47 | - snippet.visibility_level = gitlab.const.Visibility.PUBLIC.value | ||
| 47 | + snippet.visibility_level = gitlab.const.Visibility.PUBLIC | ||
| 48 | 48 | snippet.save() | |
| 49 | 49 | ||
| 50 | 50 | To update a snippet code you need to create a ``ProjectSnippet`` object:: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -125,15 +125,15 @@ def test_namespaces(gl): | |||
| 125 | 125 | ||
| 126 | 126 | def test_notification_settings(gl): | |
| 127 | 127 | settings = gl.notificationsettings.get() | |
| 128 | - settings.level = gitlab.const.NOTIFICATION_LEVEL_WATCH | ||
| 128 | + settings.level = gitlab.const.NotificationLevel.WATCH | ||
| 129 | 129 | settings.save() | |
| 130 | 130 | ||
| 131 | 131 | settings = gl.notificationsettings.get() | |
| 132 | - assert settings.level == gitlab.const.NOTIFICATION_LEVEL_WATCH | ||
| 132 | + assert settings.level == gitlab.const.NotificationLevel.WATCH | ||
| 133 | 133 | ||
| 134 | 134 | ||
| 135 | 135 | 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") | ||
| 137 | 137 | assert result[0]["id"] == 1 | |
| 138 | 138 | ||
| 139 | 139 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,17 +43,17 @@ def test_groups(gl): | |||
| 43 | 43 | assert group4 in filtered_groups | |
| 44 | 44 | ||
| 45 | 45 | 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} | ||
| 47 | 47 | ) | |
| 48 | 48 | 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} | ||
| 50 | 50 | ) | |
| 51 | 51 | 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} | ||
| 53 | 53 | ) | |
| 54 | 54 | ||
| 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) | ||
| 57 | 57 | # Reload group4 to have updated shared_with_groups | |
| 58 | 58 | group4 = gl.groups.get(group4.id) | |
| 59 | 59 | assert len(group4.shared_with_groups) == 2 | |
@@ -71,7 +71,7 @@ def test_groups(gl): | |||
| 71 | 71 | ||
| 72 | 72 | membership = memberships1[0] | |
| 73 | 73 | assert membership.source_type == "Namespace" | |
| 74 | - assert membership.access_level == gitlab.const.OWNER_ACCESS | ||
| 74 | + assert membership.access_level == gitlab.const.AccessLevel.OWNER | ||
| 75 | 75 | ||
| 76 | 76 | project_memberships = user.memberships.list(type="Project") | |
| 77 | 77 | assert len(project_memberships) == 0 | |
@@ -95,10 +95,10 @@ def test_groups(gl): | |||
| 95 | 95 | assert len(group1.members.list()) == 2 | |
| 96 | 96 | assert len(group1.members_all.list()) | |
| 97 | 97 | member = group1.members.get(user2.id) | |
| 98 | - member.access_level = gitlab.const.OWNER_ACCESS | ||
| 98 | + member.access_level = gitlab.const.AccessLevel.OWNER | ||
| 99 | 99 | member.save() | |
| 100 | 100 | member = group1.members.get(user2.id) | |
| 101 | - assert member.access_level == gitlab.const.OWNER_ACCESS | ||
| 101 | + assert member.access_level == gitlab.const.AccessLevel.OWNER | ||
| 102 | 102 | ||
| 103 | 103 | gl.auth() | |
| 104 | 104 | group2.members.delete(gl.user.id) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | import pytest | |
| 4 | 4 | ||
| 5 | 5 | import gitlab | |
| 6 | + from gitlab.const import AccessLevel | ||
| 6 | 7 | from gitlab.v4.objects.projects import ProjectStorage | |
| 7 | 8 | ||
| 8 | 9 | ||
@@ -36,6 +37,17 @@ def test_create_project(gl, user): | |||
| 36 | 37 | sudo_project.delete() | |
| 37 | 38 | ||
| 38 | 39 | ||
| 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 | + | ||
| 39 | 51 | def test_project_badges(project): | |
| 40 | 52 | badge_image = "http://example.com" | |
| 41 | 53 | badge_link = "http://example/img.svg" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments