summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects/test_projects.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_projects.py
parent76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (diff)
downloadgitlab-refactor/split-unit-tests.tar.gz
refactor: rewrite unit tests for objects with responsesrefactor/split-unit-tests
Diffstat (limited to 'gitlab/tests/objects/test_projects.py')
-rw-r--r--gitlab/tests/objects/test_projects.py44
1 files changed, 32 insertions, 12 deletions
diff --git a/gitlab/tests/objects/test_projects.py b/gitlab/tests/objects/test_projects.py
index 7fefe3f..1e8b8b6 100644
--- a/gitlab/tests/objects/test_projects.py
+++ b/gitlab/tests/objects/test_projects.py
@@ -3,31 +3,51 @@ GitLab API: https://docs.gitlab.com/ce/api/projects.html
"""
import pytest
-
+import responses
from gitlab.v4.objects import Project
-from httmock import urlmatch, response, with_httmock
-from .mocks import headers
+project_content = {"name": "name", "id": 1}
+
+
+@pytest.fixture
+def resp_get_project():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1",
+ json=project_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
-@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects/1", method="get")
-def resp_get_project(url, request):
- content = '{"name": "name", "id": 1}'.encode("utf-8")
- return response(200, content, headers, None, 5, request)
+@pytest.fixture
+def resp_list_projects():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects",
+ json=[project_content],
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
-@with_httmock(resp_get_project)
-def test_get_project(gl):
+
+def test_get_project(gl, resp_get_project):
data = gl.projects.get(1)
assert isinstance(data, Project)
assert data.name == "name"
assert data.id == 1
-@pytest.mark.skip(reason="missing test")
-def test_list_projects(gl):
- pass
+def test_list_projects(gl, resp_list_projects):
+ projects = gl.projects.list()
+ assert isinstance(projects[0], Project)
+ assert projects[0].name == "name"
@pytest.mark.skip(reason="missing test")