summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects/test_deploy_tokens.py
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2020-08-23 21:16:20 +0200
committerNejc Habjan <nejc.habjan@siemens.com>2020-08-23 21:19:47 +0200
commit204782a117f77f367dee87aa2c70822587829147 (patch)
treeb7d68fc7e4833139cc8c1d2360059b90ee43b3de /gitlab/tests/objects/test_deploy_tokens.py
parent76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (diff)
downloadgitlab-204782a117f77f367dee87aa2c70822587829147.tar.gz
refactor: rewrite unit tests for objects with responsesrefactor/split-unit-tests
Diffstat (limited to 'gitlab/tests/objects/test_deploy_tokens.py')
-rw-r--r--gitlab/tests/objects/test_deploy_tokens.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/gitlab/tests/objects/test_deploy_tokens.py b/gitlab/tests/objects/test_deploy_tokens.py
index b98a670..9cfa598 100644
--- a/gitlab/tests/objects/test_deploy_tokens.py
+++ b/gitlab/tests/objects/test_deploy_tokens.py
@@ -1,34 +1,36 @@
"""
GitLab API: https://docs.gitlab.com/ce/api/deploy_tokens.html
"""
-
-from httmock import response, urlmatch, with_httmock
+import pytest
+import responses
from gitlab.v4.objects import ProjectDeployToken
-from .mocks import headers
-
-@urlmatch(
- scheme="http",
- netloc="localhost",
- path="/api/v4/projects/1/deploy_tokens",
- method="post",
-)
-def resp_deploy_token_create(url, request):
- content = """{
+create_content = {
"id": 1,
"name": "test_deploy_token",
"username": "custom-user",
"expires_at": "2022-01-01T00:00:00.000Z",
"token": "jMRvtPNxrn3crTAGukpZ",
- "scopes": [ "read_repository" ]}"""
- content = content.encode("utf-8")
- return response(200, content, headers, None, 5, request)
+ "scopes": ["read_repository"],
+}
+
+
+@pytest.fixture
+def resp_deploy_token_create():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/deploy_tokens",
+ json=create_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
-@with_httmock(resp_deploy_token_create)
-def test_deploy_tokens(gl):
+def test_deploy_tokens(gl, resp_deploy_token_create):
deploy_token = gl.projects.get(1, lazy=True).deploytokens.create(
{
"name": "test_deploy_token",