summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects/test_todos.py
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2020-04-17 02:26:28 +0200
committerNejc Habjan <nejc.habjan@siemens.com>2020-08-22 20:09:52 +0200
commit76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7 (patch)
tree4dbe6ae57c4f03e1351f7a49e590cbbc6d31121a /gitlab/tests/objects/test_todos.py
parent11383e70f74c70e6fe8a56f18b5b170db982f402 (diff)
downloadgitlab-76b2cadf1418e4ea2ac420ebba5a4b4f16fbd4c7.tar.gz
refactor: split unit tests by GitLab API resources
Diffstat (limited to 'gitlab/tests/objects/test_todos.py')
-rw-r--r--gitlab/tests/objects/test_todos.py58
1 files changed, 58 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_todos.py b/gitlab/tests/objects/test_todos.py
new file mode 100644
index 0000000..5b30dc9
--- /dev/null
+++ b/gitlab/tests/objects/test_todos.py
@@ -0,0 +1,58 @@
+"""
+GitLab API: https://docs.gitlab.com/ce/api/todos.html
+"""
+
+import json
+import os
+
+from httmock import response, urlmatch, with_httmock
+
+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):
+ todo = gl.todos.list()[0]
+ assert isinstance(todo, Todo)
+ assert todo.id == 102
+ assert todo.target_type == "MergeRequest"
+ assert todo.target["assignee"]["username"] == "root"
+
+ todo.mark_as_done()
+
+
+@with_httmock(resp_mark_all_as_done)
+def test_todo_mark_all_as_done(gl):
+ gl.todos.mark_all_as_done()