|
21 | 21 | import os
|
22 | 22 | import pickle
|
23 | 23 | import tempfile
|
| 24 | +import json |
24 | 25 |
|
25 | 26 | try:
|
26 | 27 | import unittest
|
@@ -671,6 +672,51 @@ def resp_get_user_status(url, request):
|
671 | 672 | self.assertEqual(status.message, "test")
|
672 | 673 | self.assertEqual(status.emoji, "thumbsup")
|
673 | 674 |
|
| 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 | + |
674 | 720 | def _default_config(self):
|
675 | 721 | fd, temp_path = tempfile.mkstemp()
|
676 | 722 | os.write(fd, valid_config)
|
|
0 commit comments