diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-23 21:16:20 +0200 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2020-08-23 21:19:47 +0200 |
commit | 204782a117f77f367dee87aa2c70822587829147 (patch) | |
tree | b7d68fc7e4833139cc8c1d2360059b90ee43b3de /gitlab/tests/objects/test_issues.py | |
parent | 76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (diff) | |
download | gitlab-refactor/split-unit-tests.tar.gz |
refactor: rewrite unit tests for objects with responsesrefactor/split-unit-tests
Diffstat (limited to 'gitlab/tests/objects/test_issues.py')
-rw-r--r-- | gitlab/tests/objects/test_issues.py | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/gitlab/tests/objects/test_issues.py b/gitlab/tests/objects/test_issues.py index e094841..f67d720 100644 --- a/gitlab/tests/objects/test_issues.py +++ b/gitlab/tests/objects/test_issues.py @@ -2,41 +2,49 @@ GitLab API: https://docs.gitlab.com/ce/api/issues.html """ -from httmock import urlmatch, response, with_httmock +import pytest +import responses -from .mocks import headers from gitlab.v4.objects import ProjectIssuesStatistics -@urlmatch(scheme="http", netloc="localhost", path="/api/v4/issues", method="get") -def resp_get_issue(url, request): - content = '[{"name": "name", "id": 1}, ' '{"name": "other_name", "id": 2}]' - content = content.encode("utf-8") - return response(200, content, headers, None, 5, request) +@pytest.fixture +def resp_issue(): + content = [{"name": "name", "id": 1}, {"name": "other_name", "id": 2}] + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/issues", + json=content, + content_type="application/json", + status=200, + ) + yield rsps -@urlmatch( - scheme="http", - netloc="localhost", - path="/api/v4/projects/1/issues_statistics", - method="get", -) -def resp_get_environment(url, request): - content = """{"statistics": {"counts": {"all": 20, "closed": 5, "opened": 15}}}""".encode( - "utf-8" - ) - return response(200, content, headers, None, 5, request) +@pytest.fixture +def resp_issue_statistics(): + content = {"statistics": {"counts": {"all": 20, "closed": 5, "opened": 15}}} -@with_httmock(resp_get_issue) -def test_issues(gl): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/issues_statistics", + json=content, + content_type="application/json", + status=200, + ) + yield rsps + + +def test_issues(gl, resp_issue): data = gl.issues.list() assert data[1].id == 2 assert data[1].name == "other_name" -@with_httmock(resp_get_environment) -def test_project_issues_statistics(project): +def test_project_issues_statistics(project, resp_issue_statistics): statistics = project.issuesstatistics.get() assert isinstance(statistics, ProjectIssuesStatistics) assert statistics.statistics["counts"]["all"] == 20 |