diff options
Diffstat (limited to 'gitlab/tests/objects/test_todos.py')
-rw-r--r-- | gitlab/tests/objects/test_todos.py | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/gitlab/tests/objects/test_todos.py b/gitlab/tests/objects/test_todos.py index 5b30dc9..07bb680 100644 --- a/gitlab/tests/objects/test_todos.py +++ b/gitlab/tests/objects/test_todos.py @@ -5,45 +5,51 @@ GitLab API: https://docs.gitlab.com/ce/api/todos.html import json import os -from httmock import response, urlmatch, with_httmock +import pytest +import responses from gitlab.v4.objects import Todo -from .mocks import headers - with open(os.path.dirname(__file__) + "/../data/todo.json", "r") as json_file: todo_content = json_file.read() json_content = json.loads(todo_content) - encoded_content = todo_content.encode("utf-8") - - -@urlmatch(scheme="http", netloc="localhost", path="/api/v4/todos", method="get") -def resp_get_todo(url, request): - return response(200, encoded_content, headers, None, 5, request) - - -@urlmatch( - scheme="http", - netloc="localhost", - path="/api/v4/todos/102/mark_as_done", - method="post", -) -def resp_mark_as_done(url, request): - single_todo = json.dumps(json_content[0]) - content = single_todo.encode("utf-8") - return response(200, content, headers, None, 5, request) - - -@urlmatch( - scheme="http", netloc="localhost", path="/api/v4/todos/mark_as_done", method="post", -) -def resp_mark_all_as_done(url, request): - return response(204, {}, headers, None, 5, request) -@with_httmock(resp_get_todo, resp_mark_as_done) -def test_todo(gl): +@pytest.fixture +def resp_todo(): + with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/todos", + json=json_content, + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.POST, + url="http://localhost/api/v4/todos/102/mark_as_done", + json=json_content[0], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture +def resp_mark_all_as_done(): + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.POST, + url="http://localhost/api/v4/todos/mark_as_done", + json={}, + content_type="application/json", + status=204, + ) + yield rsps + + +def test_todo(gl, resp_todo): todo = gl.todos.list()[0] assert isinstance(todo, Todo) assert todo.id == 102 @@ -53,6 +59,5 @@ def test_todo(gl): todo.mark_as_done() -@with_httmock(resp_mark_all_as_done) -def test_todo_mark_all_as_done(gl): +def test_todo_mark_all_as_done(gl, resp_mark_all_as_done): gl.todos.mark_all_as_done() |