summaryrefslogtreecommitdiff
path: root/gitlab/tests
diff options
context:
space:
mode:
authorMax Wittig <max.wittig@siemens.com>2021-02-24 18:44:40 +0100
committerMax Wittig <max.wittig@siemens.com>2021-02-24 18:45:32 +0100
commit1becef0253804f119c8a4d0b8b1c53deb2f4d889 (patch)
treea2bca4df7c148c5381c614861542ce2ba9f8dded /gitlab/tests
parentf6fd99530d70f2a7626602fd9132b628bb968eab (diff)
downloadgitlab-1becef0253804f119c8a4d0b8b1c53deb2f4d889.tar.gz
feat(projects): add project access token api
Diffstat (limited to 'gitlab/tests')
-rw-r--r--gitlab/tests/objects/test_project_access_tokens.py139
1 files changed, 139 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_project_access_tokens.py b/gitlab/tests/objects/test_project_access_tokens.py
new file mode 100644
index 0000000..76f664f
--- /dev/null
+++ b/gitlab/tests/objects/test_project_access_tokens.py
@@ -0,0 +1,139 @@
+"""
+GitLab API: https://docs.gitlab.com/ee/api/resource_access_tokens.html
+"""
+
+import pytest
+import responses
+
+
+@pytest.fixture
+def resp_list_project_access_token():
+ content = [
+ {
+ "user_id": 141,
+ "scopes": ["api"],
+ "name": "token",
+ "expires_at": "2021-01-31",
+ "id": 42,
+ "active": True,
+ "created_at": "2021-01-20T22:11:48.151Z",
+ "revoked": False,
+ }
+ ]
+
+ with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/access_tokens",
+ json=content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_create_project_access_token():
+ content = {
+ "user_id": 141,
+ "scopes": ["api"],
+ "name": "token",
+ "expires_at": "2021-01-31",
+ "id": 42,
+ "active": True,
+ "created_at": "2021-01-20T22:11:48.151Z",
+ "revoked": False,
+ }
+
+ with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/access_tokens",
+ json=content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_list_project_access_token():
+ content = [
+ {
+ "user_id": 141,
+ "scopes": ["api"],
+ "name": "token",
+ "expires_at": "2021-01-31",
+ "id": 42,
+ "active": True,
+ "created_at": "2021-01-20T22:11:48.151Z",
+ "revoked": False,
+ }
+ ]
+
+ with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/access_tokens",
+ json=content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_revoke_project_access_token():
+ content = [
+ {
+ "user_id": 141,
+ "scopes": ["api"],
+ "name": "token",
+ "expires_at": "2021-01-31",
+ "id": 42,
+ "active": True,
+ "created_at": "2021-01-20T22:11:48.151Z",
+ "revoked": False,
+ }
+ ]
+
+ with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
+ rsps.add(
+ method=responses.DELETE,
+ url="http://localhost/api/v4/projects/1/access_tokens/42",
+ json=content,
+ content_type="application/json",
+ status=204,
+ )
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/access_tokens",
+ json=content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+def test_list_project_access_tokens(gl, resp_list_project_access_token):
+ access_tokens = gl.projects.get(1, lazy=True).access_tokens.list()
+ assert len(access_tokens) == 1
+ assert access_tokens[0].revoked is False
+ assert access_tokens[0].name == "token"
+
+
+def test_create_project_access_token(gl, resp_create_project_access_token):
+ access_tokens = gl.projects.get(1, lazy=True).access_tokens.create(
+ {"name": "test", "scopes": ["api"]}
+ )
+ assert access_tokens.revoked is False
+ assert access_tokens.user_id == 141
+ assert access_tokens.expires_at == "2021-01-31"
+
+
+def test_revoke_project_access_token(
+ gl, resp_list_project_access_token, resp_revoke_project_access_token
+):
+ gl.projects.get(1, lazy=True).access_tokens.delete(42)
+ access_token = gl.projects.get(1, lazy=True).access_tokens.list()[0]
+ access_token.delete()