|
7 | 7 | from pygithub3.exceptions import ValidationError |
8 | 8 | from pygithub3.tests.utils.core import TestCase |
9 | 9 | from pygithub3.resources.base import json |
10 | | -from pygithub3.services.issues import Issue, Comments, Events, Labels, Milestones |
| 10 | +from pygithub3.services.issues import (Issue, Comments, Events, Labels, |
| 11 | + Milestones) |
11 | 12 | from pygithub3.tests.utils.base import (mock_response, mock_response_result, |
12 | 13 | mock_json) |
13 | 14 | from pygithub3.tests.utils.services import _ |
|
20 | 21 | class TestIssuesService(TestCase): |
21 | 22 |
|
22 | 23 | def setUp(self): |
23 | | - self.isu = Issue() |
| 24 | + self.isu = Issue(user='octocat', repo='Hello-World') |
24 | 25 |
|
25 | 26 | def test_LIST_without_user(self, request_method): |
26 | 27 | request_method.return_value = mock_response_result() |
@@ -29,27 +30,25 @@ def test_LIST_without_user(self, request_method): |
29 | 30 |
|
30 | 31 | def test_LIST_by_repo(self, request_method): |
31 | 32 | request_method.return_value = mock_response_result() |
32 | | - self.isu.list_by_repo('octocat', 'Hello-World').all() |
| 33 | + self.isu.list_by_repo().all() |
33 | 34 | self.assertEqual(request_method.call_args[0], |
34 | 35 | ('get', _('repos/octocat/Hello-World/issues'))) |
35 | 36 |
|
36 | 37 | def test_GET(self, request_method): |
37 | 38 | request_method.return_value = mock_response() |
38 | | - self.isu.get('octocat', 'Hello-World', 1) |
| 39 | + self.isu.get(1) |
39 | 40 | self.assertEqual(request_method.call_args[0], |
40 | 41 | ('get', _('repos/octocat/Hello-World/issues/1'))) |
41 | 42 |
|
42 | 43 | def test_CREATE(self, request_method): |
43 | 44 | request_method.return_value = mock_response('post') |
44 | | - self.isu.create('octocat', 'Hello-World', |
45 | | - dict(title='My issue', body='Fix this issue')) |
| 45 | + self.isu.create(dict(title='My issue', body='Fix this issue')) |
46 | 46 | self.assertEqual(request_method.call_args[0], |
47 | 47 | ('post', _('repos/octocat/Hello-World/issues'))) |
48 | 48 |
|
49 | 49 | def test_UPDATE(self, request_method): |
50 | 50 | request_method.return_value = mock_response('patch') |
51 | | - self.isu.update('octocat', 'Hello-World', 1, |
52 | | - {'body': 'edited'}) |
| 51 | + self.isu.update(1, {'body': 'edited'}) |
53 | 52 | self.assertEqual(request_method.call_args[0], |
54 | 53 | ('patch', _('repos/octocat/Hello-World/issues/1'))) |
55 | 54 |
|
@@ -58,35 +57,35 @@ def test_UPDATE(self, request_method): |
58 | 57 | class TestCommentService(TestCase): |
59 | 58 |
|
60 | 59 | def setUp(self): |
61 | | - self.cs = Comments() |
| 60 | + self.cs = Comments(user='octocat', repo='Hello-World') |
62 | 61 |
|
63 | 62 | def test_LIST(self, request_method): |
64 | 63 | request_method.return_value = mock_response_result() |
65 | | - self.cs.list('octocat', 'Hello-World', 1).all() |
| 64 | + self.cs.list(1).all() |
66 | 65 | self.assertEqual(request_method.call_args[0], |
67 | 66 | ('get', _('repos/octocat/Hello-World/issues/1/comments'))) |
68 | 67 |
|
69 | 68 | def test_GET(self, request_method): |
70 | 69 | request_method.return_value = mock_response() |
71 | | - self.cs.get('octocat', 'Hello-World', 1) |
| 70 | + self.cs.get(1) |
72 | 71 | self.assertEqual(request_method.call_args[0], |
73 | 72 | ('get', _('repos/octocat/Hello-World/issues/comments/1'))) |
74 | 73 |
|
75 | 74 | def test_CREATE(self, request_method): |
76 | 75 | request_method.return_value = mock_response('post') |
77 | | - self.cs.create('octocat', 'Hello-World', 1, 'comment') |
| 76 | + self.cs.create(1, 'comment') |
78 | 77 | self.assertEqual(request_method.call_args[0], |
79 | 78 | ('post', _('repos/octocat/Hello-World/issues/1/comments'))) |
80 | 79 |
|
81 | 80 | def test_UPDATE(self, request_method): |
82 | 81 | request_method.return_value = mock_response('patch') |
83 | | - self.cs.update('octocat', 'Hello-World', 1, 'new comment') |
| 82 | + self.cs.update(1, 'new comment') |
84 | 83 | self.assertEqual(request_method.call_args[0], |
85 | 84 | ('patch', _('repos/octocat/Hello-World/issues/comments/1'))) |
86 | 85 |
|
87 | 86 | def test_DELETE(self, request_method): |
88 | 87 | request_method.return_value = mock_response('delete') |
89 | | - self.cs.delete('octocat', 'Hello-World', 1) |
| 88 | + self.cs.delete(1) |
90 | 89 | self.assertEqual(request_method.call_args[0], |
91 | 90 | ('delete', _('repos/octocat/Hello-World/issues/comments/1'))) |
92 | 91 |
|
@@ -95,23 +94,23 @@ def test_DELETE(self, request_method): |
95 | 94 | class TestEventsService(TestCase): |
96 | 95 |
|
97 | 96 | def setUp(self): |
98 | | - self.ev = Events() |
| 97 | + self.ev = Events(user='octocat', repo='Hello-World') |
99 | 98 |
|
100 | 99 | def test_LIST_by_issue(self, request_method): |
101 | 100 | request_method.return_value = mock_response_result() |
102 | | - self.ev.list_by_issue('octocat', 'Hello-World', 1).all() |
| 101 | + self.ev.list_by_issue(1).all() |
103 | 102 | self.assertEqual(request_method.call_args[0], |
104 | 103 | ('get', _('repos/octocat/Hello-World/issues/1/events'))) |
105 | 104 |
|
106 | 105 | def test_LIST_by_repo(self, request_method): |
107 | 106 | request_method.return_value = mock_response_result() |
108 | | - self.ev.list_by_repo('octocat', 'Hello-World').all() |
| 107 | + self.ev.list_by_repo().all() |
109 | 108 | self.assertEqual(request_method.call_args[0], |
110 | 109 | ('get', _('repos/octocat/Hello-World/issues/events'))) |
111 | 110 |
|
112 | 111 | def test_GET(self, request_method): |
113 | 112 | request_method.return_value = mock_response() |
114 | | - self.ev.get('octocat', 'Hello-World', 1) |
| 113 | + self.ev.get(1) |
115 | 114 | self.assertEqual(request_method.call_args[0], |
116 | 115 | ('get', _('repos/octocat/Hello-World/issues/events/1'))) |
117 | 116 |
|
@@ -120,121 +119,115 @@ def test_GET(self, request_method): |
120 | 119 | class TestLabelsService(TestCase): |
121 | 120 |
|
122 | 121 | def setUp(self): |
123 | | - self.lb = Labels() |
| 122 | + self.lb = Labels(user='octocat', repo='Hello-World') |
124 | 123 |
|
125 | 124 | def test_GET(self, request_method): |
126 | 125 | request_method.return_value = mock_response() |
127 | | - self.lb.get('octocat', 'Hello-World', 'bug') |
| 126 | + self.lb.get('bug') |
128 | 127 | self.assertEqual(request_method.call_args[0], |
129 | 128 | ('get', _('repos/octocat/Hello-World/labels/bug'))) |
130 | 129 |
|
131 | 130 | def test_CREATE(self, request_method): |
132 | 131 | request_method.return_value = mock_response('post') |
133 | | - self.lb.create('octocat', 'Hello-World', 'bug', 'FF0000') |
| 132 | + self.lb.create(dict(name='bug', color='FF0000')) |
134 | 133 | self.assertEqual(request_method.call_args[0], |
135 | 134 | ('post', _('repos/octocat/Hello-World/labels'))) |
136 | 135 |
|
137 | 136 | def test_CREATE_with_invalid_color(self, request_method): |
138 | 137 | request_method.return_value = mock_response('post') |
139 | 138 | # invalid color |
140 | | - with self.assertRaises(ValidationError): |
141 | | - args={'user': 'octocat', |
142 | | - 'repo': 'Hello-world', |
143 | | - 'name': 'bug', |
144 | | - 'color': 'FF00',} |
145 | | - self.lb.create(**args) |
| 139 | + with self.assertRaises(ValidationError): |
| 140 | + args={'name': 'bug', 'color': 'FF00'} |
| 141 | + self.lb.create(args) |
146 | 142 |
|
147 | 143 | def test_UPDATE(self, request_method): |
148 | 144 | request_method.return_value = mock_response('patch') |
149 | | - self.lb.update('octocat', 'Hello-World', 'bug', 'critical', 'FF0000') |
| 145 | + self.lb.update('bug', dict(name='critical', color='FF0000')) |
150 | 146 | self.assertEqual(request_method.call_args[0], |
151 | 147 | ('patch', _('repos/octocat/Hello-World/labels/bug'))) |
152 | 148 |
|
153 | 149 | def test_UPDATE_with_invalid_color(self, request_method): |
154 | 150 | request_method.return_value = mock_response('post') |
155 | 151 | # invalid color |
156 | | - with self.assertRaises(ValidationError): |
157 | | - args={'user': 'octocat', |
158 | | - 'repo': 'Hello-world', |
159 | | - 'name': 'bug', |
160 | | - 'new_name': 'critical', |
| 152 | + with self.assertRaises(ValidationError): |
| 153 | + args={'name': 'critical', |
161 | 154 | 'color': 'FF00',} |
162 | | - self.lb.update(**args) |
| 155 | + self.lb.update('bug', args) |
163 | 156 |
|
164 | 157 | def test_DELETE(self, request_method): |
165 | 158 | request_method.return_value = mock_response('delete') |
166 | | - self.lb.delete('octocat', 'Hello-World', 'bug') |
| 159 | + self.lb.delete('bug') |
167 | 160 | self.assertEqual(request_method.call_args[0], |
168 | 161 | ('delete', _('repos/octocat/Hello-World/labels/bug'))) |
169 | 162 |
|
170 | | - def test_LIST_by_repo(self, request_method): |
171 | | - request_method.return_value = mock_response() |
172 | | - self.lb.list_by_repo('octocat', 'Hello-World') |
173 | | - self.assertEqual(request_method.call_args[0], |
174 | | - ('get', _('repos/octocat/Hello-World/labels'))) |
175 | | - |
176 | 163 | def test_LIST_by_issue(self, request_method): |
177 | 164 | request_method.return_value = mock_response() |
178 | | - self.lb.list_by_issue('octocat', 'Hello-World', 1) |
| 165 | + self.lb.list_by_issue(1) |
179 | 166 | self.assertEqual(request_method.call_args[0], |
180 | 167 | ('get', _('repos/octocat/Hello-World/issues/1/labels'))) |
181 | 168 |
|
182 | 169 | def test_ADD_to_issue(self, request_method): |
183 | 170 | request_method.return_value = mock_response('post') |
184 | | - self.lb.add_to_issue('octocat', 'Hello-World', 1, ['bug', 'critical']) |
| 171 | + self.lb.add_to_issue(1, ('bug', 'critical')) |
185 | 172 | self.assertEqual(request_method.call_args[0], |
186 | 173 | ('post', _('repos/octocat/Hello-World/issues/1/labels'))) |
187 | 174 |
|
188 | 175 | def test_REMOVE_from_issue(self, request_method): |
189 | 176 | request_method.return_value = mock_response('delete') |
190 | | - self.lb.remove_from_issue('octocat', 'Hello-World', 1, 'bug') |
| 177 | + self.lb.remove_from_issue(1, 'bug') |
191 | 178 | self.assertEqual(request_method.call_args[0], |
192 | 179 | ('delete', _('repos/octocat/Hello-World/issues/1/labels/bug'))) |
193 | 180 |
|
194 | 181 | def test_REPLACE_all(self, request_method): |
195 | | - self.lb.replace_all('octocat', 'Hello-World', 1, ['bug', 'critical']) |
| 182 | + self.lb.replace_all(1, ['bug', 'critical']) |
196 | 183 | self.assertEqual(request_method.call_args[0], |
197 | 184 | ('put', _('repos/octocat/Hello-World/issues/1/labels'))) |
198 | 185 |
|
199 | 186 | def test_REMOVE_all(self, request_method): |
200 | 187 | request_method.return_value = mock_response('delete') |
201 | | - self.lb.remove_all('octocat', 'Hello-World', 1) |
| 188 | + self.lb.remove_all(1) |
202 | 189 | self.assertEqual(request_method.call_args[0], |
203 | 190 | ('delete', _('repos/octocat/Hello-World/issues/1/labels'))) |
204 | | - |
| 191 | + |
| 192 | + def test_LIST_by_milestone(self, request_method): |
| 193 | + request_method.return_value = mock_response_result() |
| 194 | + self.lb.list_by_milestone(1).all() |
| 195 | + self.assertEqual(request_method.call_args[0], |
| 196 | + ('get', _('repos/octocat/Hello-World/milestones/1/labels'))) |
| 197 | + |
205 | 198 |
|
206 | 199 | @patch.object(requests.sessions.Session, 'request') |
207 | 200 | class TestMilestonesService(TestCase): |
208 | 201 |
|
209 | 202 | def setUp(self): |
210 | | - self.mi = Milestones() |
| 203 | + self.mi = Milestones(user='octocat', repo='Hello-World') |
211 | 204 |
|
212 | 205 | def test_LIST_by_repo(self, request_method): |
213 | 206 | request_method.return_value = mock_response_result() |
214 | | - self.mi.list('octocat', 'Hello-World').all() |
| 207 | + self.mi.list().all() |
215 | 208 | self.assertEqual(request_method.call_args[0], |
216 | 209 | ('get', _('repos/octocat/Hello-World/milestones'))) |
217 | 210 |
|
218 | 211 | def test_GET(self, request_method): |
219 | 212 | request_method.return_value = mock_response() |
220 | | - self.mi.get('octocat', 'Hello-World', 1) |
| 213 | + self.mi.get(1) |
221 | 214 | self.assertEqual(request_method.call_args[0], |
222 | 215 | ('get', _('repos/octocat/Hello-World/milestones/1'))) |
223 | 216 |
|
224 | 217 | def test_CREATE(self, request_method): |
225 | 218 | request_method.return_value = mock_response('post') |
226 | | - self.mi.create('octocat', 'Hello-World', 'title') |
| 219 | + self.mi.create(dict(title='test')) |
227 | 220 | self.assertEqual(request_method.call_args[0], |
228 | 221 | ('post', _('repos/octocat/Hello-World/milestones'))) |
229 | 222 |
|
230 | 223 | def test_UPDATE(self, request_method): |
231 | 224 | request_method.return_value = mock_response('patch') |
232 | | - self.mi.update('octocat', 'Hello-World', 1, 'critical') |
| 225 | + self.mi.update(1, dict(title='test')) |
233 | 226 | self.assertEqual(request_method.call_args[0], |
234 | 227 | ('patch', _('repos/octocat/Hello-World/milestones/1'))) |
235 | 228 |
|
236 | 229 | def test_DELETE(self, request_method): |
237 | 230 | request_method.return_value = mock_response('delete') |
238 | | - self.mi.delete('octocat', 'Hello-World', 1) |
| 231 | + self.mi.delete(1) |
239 | 232 | self.assertEqual(request_method.call_args[0], |
240 | 233 | ('delete', _('repos/octocat/Hello-World/milestones/1'))) |