Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bec2094
commit 2bb16fa
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
###################### | ||
Personal Access Tokens | ||
###################### | ||
|
||
Get a list of personal access tokens | ||
|
||
References | ||
---------- | ||
|
||
* v4 API: | ||
|
||
+ :class:`gitlab.v4.objects.PersonalAccessToken` | ||
+ :class:`gitlab.v4.objects.PersonalAcessTokenManager` | ||
+ :attr:`gitlab.Gitlab.personal_access_tokens` | ||
|
||
* GitLab API: https://docs.gitlab.com/ee/api/personal_access_tokens.html | ||
|
||
Examples | ||
-------- | ||
|
||
List personal access tokens:: | ||
|
||
access_tokens = gl.personal_access_tokens.list() | ||
print(access_tokens[0].name) | ||
|
||
List personal access tokens from other user_id (admin only):: | ||
|
||
access_tokens = gl.personal_access_tokens.list(user_id=25) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
GitLab API: https://docs.gitlab.com/ee/api/personal_access_tokens.html | ||
""" | ||
|
||
import pytest | ||
import responses | ||
|
||
|
||
@pytest.fixture | ||
def resp_list_personal_access_token(): | ||
content = [ | ||
{ | ||
"id": 4, | ||
"name": "Test Token", | ||
"revoked": False, | ||
"created_at": "2020-07-23T14:31:47.729Z", | ||
"scopes": ["api"], | ||
"active": True, | ||
"user_id": 24, | ||
"expires_at": None, | ||
} | ||
] | ||
|
||
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: | ||
rsps.add( | ||
method=responses.GET, | ||
url="http://localhost/api/v4/personal_access_tokens", | ||
json=content, | ||
content_type="application/json", | ||
status=200, | ||
) | ||
yield rsps | ||
|
||
|
||
def test_list_personal_access_tokens(gl, resp_list_personal_access_token): | ||
access_tokens = gl.personal_access_tokens.list() | ||
assert len(access_tokens) == 1 | ||
assert access_tokens[0].revoked is False | ||
assert access_tokens[0].name == "Test Token" | ||
|
||
|
||
def test_list_personal_access_tokens_filter(gl, resp_list_personal_access_token): | ||
access_tokens = gl.personal_access_tokens.list(user_id=24) | ||
assert len(access_tokens) == 1 | ||
assert access_tokens[0].revoked is False | ||
assert access_tokens[0].user_id == 24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
__all__ = [ | ||
"PersonalAccessToken", | ||
"PersonalAccessTokenManager", | ||
] | ||
|
||
|
||
class PersonalAccessToken(RESTObject): | ||
pass | ||
|
||
|
||
class PersonalAccessTokenManager(ListMixin, RESTManager): | ||
_path = "/personal_access_tokens" | ||
_obj_cls = PersonalAccessToken | ||
_list_filters = ("user_id",) |