Skip to content

Commit 7715567

Browse files
committed
test(todo): add unittests
1 parent fef085d commit 7715567

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

gitlab/tests/data/todo.json

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[
2+
{
3+
"id": 102,
4+
"project": {
5+
"id": 2,
6+
"name": "Gitlab Ce",
7+
"name_with_namespace": "Gitlab Org / Gitlab Ce",
8+
"path": "gitlab-ce",
9+
"path_with_namespace": "gitlab-org/gitlab-ce"
10+
},
11+
"author": {
12+
"name": "Administrator",
13+
"username": "root",
14+
"id": 1,
15+
"state": "active",
16+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
17+
"web_url": "https://gitlab.example.com/root"
18+
},
19+
"action_name": "marked",
20+
"target_type": "MergeRequest",
21+
"target": {
22+
"id": 34,
23+
"iid": 7,
24+
"project_id": 2,
25+
"title": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.",
26+
"description": "Et ea et omnis illum cupiditate. Dolor aspernatur tenetur ducimus facilis est nihil. Quo esse cupiditate molestiae illo corrupti qui quidem dolor.",
27+
"state": "opened",
28+
"created_at": "2016-06-17T07:49:24.419Z",
29+
"updated_at": "2016-06-17T07:52:43.484Z",
30+
"target_branch": "tutorials_git_tricks",
31+
"source_branch": "DNSBL_docs",
32+
"upvotes": 0,
33+
"downvotes": 0,
34+
"author": {
35+
"name": "Maxie Medhurst",
36+
"username": "craig_rutherford",
37+
"id": 12,
38+
"state": "active",
39+
"avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon",
40+
"web_url": "https://gitlab.example.com/craig_rutherford"
41+
},
42+
"assignee": {
43+
"name": "Administrator",
44+
"username": "root",
45+
"id": 1,
46+
"state": "active",
47+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
48+
"web_url": "https://gitlab.example.com/root"
49+
},
50+
"source_project_id": 2,
51+
"target_project_id": 2,
52+
"labels": [],
53+
"work_in_progress": false,
54+
"milestone": {
55+
"id": 32,
56+
"iid": 2,
57+
"project_id": 2,
58+
"title": "v1.0",
59+
"description": "Assumenda placeat ea voluptatem voluptate qui.",
60+
"state": "active",
61+
"created_at": "2016-06-17T07:47:34.163Z",
62+
"updated_at": "2016-06-17T07:47:34.163Z",
63+
"due_date": null
64+
},
65+
"merge_when_pipeline_succeeds": false,
66+
"merge_status": "cannot_be_merged",
67+
"subscribed": true,
68+
"user_notes_count": 7
69+
},
70+
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-ce/merge_requests/7",
71+
"body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.",
72+
"state": "pending",
73+
"created_at": "2016-06-17T07:52:35.225Z"
74+
}
75+
]

gitlab/tests/test_gitlab.py

+46
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222
import pickle
2323
import tempfile
24+
import json
2425

2526
try:
2627
import unittest
@@ -671,6 +672,51 @@ def resp_get_user_status(url, request):
671672
self.assertEqual(status.message, "test")
672673
self.assertEqual(status.emoji, "thumbsup")
673674

675+
def test_todo(self):
676+
todo_content = open(os.path.dirname(__file__) + "/data/todo.json", "r").read()
677+
json_content = json.loads(todo_content)
678+
679+
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/todos", method="get")
680+
def resp_get_todo(url, request):
681+
headers = {"content-type": "application/json"}
682+
content = todo_content.encode("utf-8")
683+
return response(200, content, headers, None, 5, request)
684+
685+
@urlmatch(
686+
scheme="http",
687+
netloc="localhost",
688+
path="/api/v4/todos/102/mark_as_done",
689+
method="post",
690+
)
691+
def resp_mark_as_done(url, request):
692+
headers = {"content-type": "application/json"}
693+
single_todo = json.dumps(json_content[0])
694+
content = single_todo.encode("utf-8")
695+
return response(200, content, headers, None, 5, request)
696+
697+
with HTTMock(resp_get_todo):
698+
todo = self.gl.todos.list()[0]
699+
self.assertEqual(type(todo), Todo)
700+
self.assertEqual(todo.id, 102)
701+
self.assertEqual(todo.target_type, "MergeRequest")
702+
self.assertEqual(todo.target["assignee"]["username"], "root")
703+
with HTTMock(resp_mark_as_done):
704+
todo.mark_as_done()
705+
706+
def test_todo_mark_all_as_done(self):
707+
@urlmatch(
708+
scheme="http",
709+
netloc="localhost",
710+
path="/api/v4/todos/mark_as_done",
711+
method="post",
712+
)
713+
def resp_mark_all_as_done(url, request):
714+
headers = {"content-type": "application/json"}
715+
return response(204, {}, headers, None, 5, request)
716+
717+
with HTTMock(resp_mark_all_as_done):
718+
self.gl.todos.mark_all_as_done()
719+
674720
def _default_config(self):
675721
fd, temp_path = tempfile.mkstemp()
676722
os.write(fd, valid_config)

0 commit comments

Comments
 (0)