Merge lp:~cjohnston/uci-engine/cli-requests into lp:uci-engine
- cli-requests
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Chris Johnston |
Approved revision: | 502 |
Merged at revision: | 518 |
Proposed branch: | lp:~cjohnston/uci-engine/cli-requests |
Merge into: | lp:uci-engine |
Diff against target: |
782 lines (+202/-160) 11 files modified
cli/ci_cli/image.py (+5/-4) cli/ci_cli/status.py (+5/-4) cli/ci_cli/tests/__init__.py (+43/-0) cli/ci_cli/tests/test_cli.py (+56/-44) cli/ci_cli/tests/test_get_ticket_status.py (+31/-31) cli/ci_cli/tests/test_image.py (+22/-38) cli/ci_cli/tests/test_utils.py (+13/-12) cli/ci_cli/utils.py (+9/-14) cli/setup.py (+1/-0) cli/ubuntu-ci (+16/-13) debian/control (+1/-0) |
To merge this branch: | bzr merge lp:~cjohnston/uci-engine/cli-requests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Andy Doan (community) | Approve | ||
Chris Johnston (community) | Needs Resubmitting | ||
Review via email:
|
Commit message
Switch the CLI to use python-requests
Description of the change
Swiftclient is already using python-requests, and I think that using python-requests will make working with the gatekeeper easier so lets switch to using it for the CLI.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:499
http://
Executed test runs:
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Andy Doan (doanac) wrote : | # |
nothing major, but 3 comments
- 500. By Chris Johnston
-
Remove double code block for exceptions
- 501. By Chris Johnston
-
Update test to call ConnectionError on socket.error
- 502. By Chris Johnston
-
More cleanup
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Chris Johnston (cjohnston) : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Andy Doan (doanac) : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:502
http://
Executed test runs:
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'cli/ci_cli/image.py' | |||
2 | --- cli/ci_cli/image.py 2014-05-07 14:56:11 +0000 | |||
3 | +++ cli/ci_cli/image.py 2014-05-27 09:44:30 +0000 | |||
4 | @@ -15,7 +15,8 @@ | |||
5 | 15 | 15 | ||
6 | 16 | import os | 16 | import os |
7 | 17 | import sys | 17 | import sys |
9 | 18 | import urllib2 | 18 | |
10 | 19 | from requests import exceptions | ||
11 | 19 | 20 | ||
12 | 20 | from ci_cli import utils | 21 | from ci_cli import utils |
13 | 21 | from ci_utils import ( | 22 | from ci_utils import ( |
14 | @@ -41,11 +42,11 @@ | |||
15 | 41 | url = artifact_base + '?type__exact=IMAGE&ticket__exact={}'.format( | 42 | url = artifact_base + '?type__exact=IMAGE&ticket__exact={}'.format( |
16 | 42 | ticket) | 43 | ticket) |
17 | 43 | return utils.get(url) | 44 | return utils.get(url) |
20 | 44 | except urllib2.HTTPError, exc: | 45 | except exceptions.HTTPError, exc: |
21 | 45 | if exc.code == 404 and ticket: | 46 | if exc.response.status_code == 404 and ticket: |
22 | 46 | sys.exit("Ticket number {} not found.".format(ticket)) | 47 | sys.exit("Ticket number {} not found.".format(ticket)) |
23 | 47 | raise | 48 | raise |
25 | 48 | except urllib2.URLError, exc: | 49 | except exceptions.ConnectionError, exc: |
26 | 49 | raise | 50 | raise |
27 | 50 | 51 | ||
28 | 51 | 52 | ||
29 | 52 | 53 | ||
30 | === modified file 'cli/ci_cli/status.py' | |||
31 | --- cli/ci_cli/status.py 2014-05-07 14:56:11 +0000 | |||
32 | +++ cli/ci_cli/status.py 2014-05-27 09:44:30 +0000 | |||
33 | @@ -14,7 +14,8 @@ | |||
34 | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | # with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | 15 | 15 | ||
36 | 16 | import sys | 16 | import sys |
38 | 17 | import urllib2 | 17 | |
39 | 18 | from requests import exceptions | ||
40 | 18 | 19 | ||
41 | 19 | from ci_cli import utils | 20 | from ci_cli import utils |
42 | 20 | 21 | ||
43 | @@ -27,11 +28,11 @@ | |||
44 | 27 | else: | 28 | else: |
45 | 28 | url = utils.CI_URL + utils.TICKET_BASE | 29 | url = utils.CI_URL + utils.TICKET_BASE |
46 | 29 | data = utils.get(url) | 30 | data = utils.get(url) |
49 | 30 | except urllib2.HTTPError, exc: | 31 | except exceptions.HTTPError, exc: |
50 | 31 | if exc.code == 404 and args.ticket: | 32 | if exc.response.status_code == 404 and args.ticket: |
51 | 32 | sys.exit("Ticket number {} not found.".format(args.ticket)) | 33 | sys.exit("Ticket number {} not found.".format(args.ticket)) |
52 | 33 | raise | 34 | raise |
54 | 34 | except urllib2.URLError, exc: | 35 | except exceptions.ConnectionError, exc: |
55 | 35 | raise | 36 | raise |
56 | 36 | 37 | ||
57 | 37 | if args.ticket: | 38 | if args.ticket: |
58 | 38 | 39 | ||
59 | === modified file 'cli/ci_cli/tests/__init__.py' | |||
60 | --- cli/ci_cli/tests/__init__.py 2014-05-07 17:57:12 +0000 | |||
61 | +++ cli/ci_cli/tests/__init__.py 2014-05-27 09:44:30 +0000 | |||
62 | @@ -17,10 +17,13 @@ | |||
63 | 17 | import imp | 17 | import imp |
64 | 18 | import os | 18 | import os |
65 | 19 | import sys | 19 | import sys |
66 | 20 | import json | ||
67 | 20 | 21 | ||
68 | 21 | from cStringIO import StringIO | 22 | from cStringIO import StringIO |
69 | 22 | from contextlib import contextmanager | 23 | from contextlib import contextmanager |
70 | 23 | 24 | ||
71 | 25 | from requests import exceptions | ||
72 | 26 | |||
73 | 24 | from ci_cli import utils | 27 | from ci_cli import utils |
74 | 25 | from ci_utils.testing import TestCaseWithGnupg | 28 | from ci_utils.testing import TestCaseWithGnupg |
75 | 26 | 29 | ||
76 | @@ -54,6 +57,46 @@ | |||
77 | 54 | utils.CI_URL = utils.AUTH_CONFIG['ci_url'] | 57 | utils.CI_URL = utils.AUTH_CONFIG['ci_url'] |
78 | 55 | 58 | ||
79 | 56 | 59 | ||
80 | 60 | class FakeRequestsReturn: | ||
81 | 61 | """Object to mock the return of python-requests return.""" | ||
82 | 62 | |||
83 | 63 | def __init__(self, code, content, reason=None): | ||
84 | 64 | self.status_code = code | ||
85 | 65 | self.content = content | ||
86 | 66 | self.reason = reason | ||
87 | 67 | |||
88 | 68 | def raise_for_status(self): | ||
89 | 69 | if 400 == self.status_code: | ||
90 | 70 | error = '%s Client Error: %s' % (self.status_code, self.reason) | ||
91 | 71 | e = exceptions.ConnectionError(error) | ||
92 | 72 | raise e | ||
93 | 73 | elif 400 < self.status_code < 500: | ||
94 | 74 | error = '%s Client Error: %s' % (self.status_code, self.reason) | ||
95 | 75 | e = exceptions.HTTPError(error, response=self) | ||
96 | 76 | raise e | ||
97 | 77 | elif 500 <= self.status_code < 600: | ||
98 | 78 | error = '%s Server Error: %s' % (self.status_code, self.reason) | ||
99 | 79 | e = exceptions.HTTPError(error, response=self) | ||
100 | 80 | raise e | ||
101 | 81 | else: | ||
102 | 82 | pass | ||
103 | 83 | |||
104 | 84 | def __repr__(self): | ||
105 | 85 | return self.content | ||
106 | 86 | |||
107 | 87 | def __iter__(self): | ||
108 | 88 | return (line for line in self.content.split("\n")) | ||
109 | 89 | |||
110 | 90 | def read(self): | ||
111 | 91 | return self.content | ||
112 | 92 | |||
113 | 93 | def json(self): | ||
114 | 94 | return json.loads(self.content) | ||
115 | 95 | |||
116 | 96 | def _status_code(self): | ||
117 | 97 | pass | ||
118 | 98 | |||
119 | 99 | |||
120 | 57 | class MainScriptTestCase(TestCaseWithGnupg): | 100 | class MainScriptTestCase(TestCaseWithGnupg): |
121 | 58 | """Load the 'ubuntu-ci' script module for tests. | 101 | """Load the 'ubuntu-ci' script module for tests. |
122 | 59 | 102 | ||
123 | 60 | 103 | ||
124 | === modified file 'cli/ci_cli/tests/test_cli.py' | |||
125 | --- cli/ci_cli/tests/test_cli.py 2014-05-12 15:49:28 +0000 | |||
126 | +++ cli/ci_cli/tests/test_cli.py 2014-05-27 09:44:30 +0000 | |||
127 | @@ -21,7 +21,6 @@ | |||
128 | 21 | import mock | 21 | import mock |
129 | 22 | import socket | 22 | import socket |
130 | 23 | from testfixtures import LogCapture | 23 | from testfixtures import LogCapture |
131 | 24 | import urllib2 | ||
132 | 25 | 24 | ||
133 | 26 | from ci_cli import utils | 25 | from ci_cli import utils |
134 | 27 | from ci_cli.tests import ( | 26 | from ci_cli.tests import ( |
135 | @@ -29,6 +28,7 @@ | |||
136 | 29 | capture_stdout, | 28 | capture_stdout, |
137 | 30 | mock_load_config, | 29 | mock_load_config, |
138 | 31 | MainScriptTestCase, | 30 | MainScriptTestCase, |
139 | 31 | FakeRequestsReturn, | ||
140 | 32 | ) | 32 | ) |
141 | 33 | from ci_cli.ticket import new_ticket | 33 | from ci_cli.ticket import new_ticket |
142 | 34 | from ci_utils.testing import get_test_file_path | 34 | from ci_utils.testing import get_test_file_path |
143 | @@ -41,9 +41,10 @@ | |||
144 | 41 | class CLICommandsTestCase(MainScriptTestCase): | 41 | class CLICommandsTestCase(MainScriptTestCase): |
145 | 42 | """Tests cli basic commands.""" | 42 | """Tests cli basic commands.""" |
146 | 43 | 43 | ||
148 | 44 | @mock.patch('urllib2.urlopen') | 44 | @mock.patch('requests.get') |
149 | 45 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 45 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
151 | 46 | def test_ticket_status_one_ticket(self, mock_load_config, mock_urlopen): | 46 | def test_ticket_status_one_ticket(self, mock_load_config, |
152 | 47 | mock_requests): | ||
153 | 47 | """Verify cli status command when providing ticket number.""" | 48 | """Verify cli status command when providing ticket number.""" |
154 | 48 | data = { | 49 | data = { |
155 | 49 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), | 50 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), |
156 | @@ -58,9 +59,9 @@ | |||
157 | 58 | "added_binaries": "mynewpackage", | 59 | "added_binaries": "mynewpackage", |
158 | 59 | "removed_binaries": "myoldpackage", | 60 | "removed_binaries": "myoldpackage", |
159 | 60 | } | 61 | } |
163 | 61 | resp = mock.Mock() | 62 | mock_requests.side_effect = [ |
164 | 62 | resp.read.return_value = json.dumps(data) | 63 | FakeRequestsReturn(200, json.dumps(data)) |
165 | 63 | mock_urlopen.return_value = resp | 64 | ] |
166 | 64 | args = ['status', '-t', '5'] | 65 | args = ['status', '-t', '5'] |
167 | 65 | with capture_stdout(self.cli.main, args) as cm: | 66 | with capture_stdout(self.cli.main, args) as cm: |
168 | 66 | self.assertEquals( | 67 | self.assertEquals( |
169 | @@ -76,11 +77,11 @@ | |||
170 | 76 | 'Removed binaries: myoldpackage\n'.format( | 77 | 'Removed binaries: myoldpackage\n'.format( |
171 | 77 | str(TicketWorkflowStep.IMAGE_BUILDING), | 78 | str(TicketWorkflowStep.IMAGE_BUILDING), |
172 | 78 | str(TicketWorkflowStepStatus.INPROGRESS))) | 79 | str(TicketWorkflowStepStatus.INPROGRESS))) |
174 | 79 | mock_urlopen.assert_called_once() | 80 | mock_requests.assert_called_once() |
175 | 80 | 81 | ||
177 | 81 | @mock.patch('urllib2.urlopen') | 82 | @mock.patch('requests.get') |
178 | 82 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 83 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
180 | 83 | def test_ticket_status_all_tickets(self, mock_load_config, mock_urlopen): | 84 | def test_ticket_status_all_tickets(self, mock_load_config, mock_requests): |
181 | 84 | """Verify cli status command for multiple tickets.""" | 85 | """Verify cli status command for multiple tickets.""" |
182 | 85 | data = { | 86 | data = { |
183 | 86 | "objects": [ | 87 | "objects": [ |
184 | @@ -98,16 +99,16 @@ | |||
185 | 98 | }, | 99 | }, |
186 | 99 | ] | 100 | ] |
187 | 100 | } | 101 | } |
191 | 101 | resp = mock.Mock() | 102 | mock_requests.side_effect = [ |
192 | 102 | resp.read.return_value = json.dumps(data) | 103 | FakeRequestsReturn(200, json.dumps(data)) |
193 | 103 | mock_urlopen.return_value = resp | 104 | ] |
194 | 104 | args = ['status'] | 105 | args = ['status'] |
195 | 105 | with capture_stdout(self.cli.main, args) as cm: | 106 | with capture_stdout(self.cli.main, args) as cm: |
196 | 106 | self.assertEquals( | 107 | self.assertEquals( |
197 | 107 | cm, | 108 | cm, |
198 | 108 | "Ticket #5, My cool feature is 100 110\n" + | 109 | "Ticket #5, My cool feature is 100 110\n" + |
199 | 109 | "Ticket #6, Ubuntu bug fix is 100 110\n") | 110 | "Ticket #6, Ubuntu bug fix is 100 110\n") |
201 | 110 | mock_urlopen.assert_called_once() | 111 | mock_requests.assert_called_once() |
202 | 111 | 112 | ||
203 | 112 | @mock.patch('ci_cli.ticket.SubTicket._process') | 113 | @mock.patch('ci_cli.ticket.SubTicket._process') |
204 | 113 | @mock.patch('ci_cli.utils.post', | 114 | @mock.patch('ci_cli.utils.post', |
205 | @@ -154,83 +155,94 @@ | |||
206 | 154 | self.assertTrue("foobar" in new_ticket_.subtickets) | 155 | self.assertTrue("foobar" in new_ticket_.subtickets) |
207 | 155 | self.assertTrue("barfoo" in new_ticket_.subtickets) | 156 | self.assertTrue("barfoo" in new_ticket_.subtickets) |
208 | 156 | 157 | ||
210 | 157 | @mock.patch('urllib2.urlopen') | 158 | @mock.patch('requests.get') |
211 | 158 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 159 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
213 | 159 | def test_ts_server_returns_urlerror(self, mock_load_config, mock_urlopen): | 160 | def test_ts_server_returns_urlerror(self, mock_load_config, mock_requests): |
214 | 160 | """Test cli response to ts server refusing connection (111).""" | 161 | """Test cli response to ts server refusing connection (111).""" |
217 | 161 | mock_urlopen.side_effect = urllib2.URLError(reason=socket.error(111, | 162 | mock_requests.side_effect = [ |
218 | 162 | "Connection refused")) | 163 | FakeRequestsReturn( |
219 | 164 | 400, '', socket.error(111, "Connection refused")) | ||
220 | 165 | ] | ||
221 | 163 | args = ['status'] | 166 | args = ['status'] |
222 | 164 | with LogCapture() as lc: | 167 | with LogCapture() as lc: |
223 | 165 | logger = logging.getLogger() | 168 | logger = logging.getLogger() |
224 | 166 | self.cli.main(args, log=logger) | 169 | self.cli.main(args, log=logger) |
226 | 167 | mock_urlopen.assert_called_once() | 170 | mock_requests.assert_called_once() |
227 | 168 | self.assertTrue("Cannot reach the server at %s." % utils.CI_URL in | 171 | self.assertTrue("Cannot reach the server at %s." % utils.CI_URL in |
228 | 172 | lc.records[0].msg, lc.records[0].msg) | ||
229 | 173 | self.assertTrue("Connection refused" in lc.records[0].msg, | ||
230 | 169 | lc.records[0].msg) | 174 | lc.records[0].msg) |
231 | 170 | self.assertTrue("Connection refused" in lc.records[0].msg) | ||
232 | 171 | 175 | ||
234 | 172 | @mock.patch('urllib2.urlopen') | 176 | @mock.patch('requests.get') |
235 | 173 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 177 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
236 | 174 | def test_ts_server_returns_internal_server_error(self, mock_load_config, | 178 | def test_ts_server_returns_internal_server_error(self, mock_load_config, |
238 | 175 | mock_urlopen): | 179 | mock_requests): |
239 | 176 | """Test cli response to ts server returning error 500.""" | 180 | """Test cli response to ts server returning error 500.""" |
243 | 177 | mock_urlopen.side_effect = urllib2.HTTPError(None, 500, | 181 | mock_requests.side_effect = [ |
244 | 178 | "INTERNAL SERVER ERROR", | 182 | FakeRequestsReturn( |
245 | 179 | None, None) | 183 | 500, "", "INTERNAL SERVER ERROR" |
246 | 184 | ) | ||
247 | 185 | ] | ||
248 | 180 | args = ['status'] | 186 | args = ['status'] |
249 | 181 | with LogCapture() as lc: | 187 | with LogCapture() as lc: |
250 | 182 | logger = logging.getLogger() | 188 | logger = logging.getLogger() |
251 | 183 | self.cli.main(args, log=logger) | 189 | self.cli.main(args, log=logger) |
253 | 184 | mock_urlopen.assert_called_once() | 190 | mock_requests.assert_called_once() |
254 | 185 | self.assertEquals("Server at {} reported internal error. Maybe a " | 191 | self.assertEquals("Server at {} reported internal error. Maybe a " |
255 | 186 | "database hiccup?".format(utils.CI_URL), | 192 | "database hiccup?".format(utils.CI_URL), |
256 | 187 | lc.records[0].msg) | 193 | lc.records[0].msg) |
257 | 188 | 194 | ||
259 | 189 | @mock.patch('urllib2.urlopen') | 195 | @mock.patch('requests.get') |
260 | 190 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 196 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
261 | 191 | def test_ts_server_returns_url_not_found(self, mock_load_config, | 197 | def test_ts_server_returns_url_not_found(self, mock_load_config, |
263 | 192 | mock_urlopen): | 198 | mock_requests): |
264 | 193 | """Test cli response to ts server returning 404 error.""" | 199 | """Test cli response to ts server returning 404 error.""" |
268 | 194 | mock_urlopen.side_effect = urllib2.HTTPError(None, 404, | 200 | mock_requests.side_effect = [ |
269 | 195 | "Server Not Found", | 201 | FakeRequestsReturn(404, '', 'Not Found') |
270 | 196 | None, None) | 202 | ] |
271 | 197 | args = ['status'] | 203 | args = ['status'] |
272 | 198 | with LogCapture() as lc: | 204 | with LogCapture() as lc: |
273 | 199 | logger = logging.getLogger() | 205 | logger = logging.getLogger() |
274 | 200 | self.cli.main(args, log=logger) | 206 | self.cli.main(args, log=logger) |
279 | 201 | mock_urlopen.assert_called_once() | 207 | mock_requests.assert_called_once() |
280 | 202 | self.assertEquals("Server at {} not found. Is 'ci_url' correctly " | 208 | self.assertEquals("Server at {} not found. Is 'ci_url' correctly " |
281 | 203 | "set? (HTTP Error 404: Server Not Found)".format( | 209 | "set? (404 Client Error: Not Found)".format( |
282 | 204 | utils.CI_URL), lc.records[0].msg) | 210 | utils.CI_URL), lc.records[0].msg) |
283 | 205 | 211 | ||
285 | 206 | @mock.patch('urllib2.urlopen') | 212 | @mock.patch('requests.get') |
286 | 207 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 213 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
287 | 208 | def test_ts_server_returns_bad_status_line(self, mock_load_config, | 214 | def test_ts_server_returns_bad_status_line(self, mock_load_config, |
289 | 209 | mock_urlopen): | 215 | mock_requests): |
290 | 210 | """Test cli response to ts server returning BadStatusLine.""" | 216 | """Test cli response to ts server returning BadStatusLine.""" |
291 | 211 | args = ['status'] | 217 | args = ['status'] |
293 | 212 | mock_urlopen.side_effect = httplib.BadStatusLine('') | 218 | mock_requests.side_effect = httplib.BadStatusLine('') |
294 | 213 | with LogCapture() as lc: | 219 | with LogCapture() as lc: |
295 | 214 | logger = logging.getLogger() | 220 | logger = logging.getLogger() |
296 | 215 | self.cli.main(args, log=logger) | 221 | self.cli.main(args, log=logger) |
298 | 216 | mock_urlopen.assert_called_once() | 222 | mock_requests.assert_called_once() |
299 | 217 | self.assertEquals("Server at {} replied with an empty response. Is " | 223 | self.assertEquals("Server at {} replied with an empty response. Is " |
300 | 218 | "'ci_url' pointing to the correct service?".format( | 224 | "'ci_url' pointing to the correct service?".format( |
301 | 219 | utils.CI_URL), lc.records[0].msg) | 225 | utils.CI_URL), lc.records[0].msg) |
302 | 220 | 226 | ||
304 | 221 | @mock.patch('urllib2.urlopen') | 227 | @mock.patch('requests.get') |
305 | 222 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) | 228 | @mock.patch('ci_cli.utils.load_config', side_effect=mock_load_config()) |
306 | 223 | def test_ts_server_returns_other_httperror(self, mock_load_config, | 229 | def test_ts_server_returns_other_httperror(self, mock_load_config, |
308 | 224 | mock_urlopen): | 230 | mock_requests): |
309 | 225 | """Test cli response to ts server returning HTTPError.""" | 231 | """Test cli response to ts server returning HTTPError.""" |
312 | 226 | mock_urlopen.side_effect = urllib2.HTTPError(None, 403, "Forbidden", | 232 | mock_requests.side_effect = [ |
313 | 227 | None, None) | 233 | FakeRequestsReturn(403, '', 'Forbidden') |
314 | 234 | ] | ||
315 | 228 | args = ['status'] | 235 | args = ['status'] |
316 | 229 | with LogCapture() as lc: | 236 | with LogCapture() as lc: |
317 | 230 | logger = logging.getLogger() | 237 | logger = logging.getLogger() |
318 | 231 | self.cli.main(args, log=logger) | 238 | self.cli.main(args, log=logger) |
321 | 232 | mock_urlopen.assert_called_once() | 239 | mock_requests.assert_called_once() |
322 | 233 | self.assertEquals("HTTP Error 403: Forbidden", lc.records[0].msg) | 240 | self.assertEquals( |
323 | 241 | "Cannot reach the server at {}. Please, check your " | ||
324 | 242 | "configuration file ({}): is 'ci_url' correctly set? " | ||
325 | 243 | "Is the server up and reachable from this machine? " | ||
326 | 244 | "(403 Client Error: Forbidden).".format( | ||
327 | 245 | utils.CI_URL, utils.DEF_CFG), lc.records[0].msg) | ||
328 | 234 | 246 | ||
329 | 235 | 247 | ||
330 | 236 | class CliArgumentsTestCase(MainScriptTestCase): | 248 | class CliArgumentsTestCase(MainScriptTestCase): |
331 | 237 | 249 | ||
332 | === modified file 'cli/ci_cli/tests/test_get_ticket_status.py' | |||
333 | --- cli/ci_cli/tests/test_get_ticket_status.py 2014-05-12 15:49:28 +0000 | |||
334 | +++ cli/ci_cli/tests/test_get_ticket_status.py 2014-05-27 09:44:30 +0000 | |||
335 | @@ -17,11 +17,11 @@ | |||
336 | 17 | 17 | ||
337 | 18 | import mock | 18 | import mock |
338 | 19 | import json | 19 | import json |
339 | 20 | import urllib2 | ||
340 | 21 | 20 | ||
341 | 22 | from ci_cli.tests import ( | 21 | from ci_cli.tests import ( |
342 | 23 | capture_stdout, | 22 | capture_stdout, |
343 | 24 | MainScriptTestCase, | 23 | MainScriptTestCase, |
344 | 24 | FakeRequestsReturn, | ||
345 | 25 | ) | 25 | ) |
346 | 26 | from ci_utils.ticket_states import ( | 26 | from ci_utils.ticket_states import ( |
347 | 27 | TicketWorkflowStep, | 27 | TicketWorkflowStep, |
348 | @@ -31,8 +31,8 @@ | |||
349 | 31 | 31 | ||
350 | 32 | class GetTicketStatus(MainScriptTestCase): | 32 | class GetTicketStatus(MainScriptTestCase): |
351 | 33 | 33 | ||
354 | 34 | @mock.patch('urllib2.urlopen') | 34 | @mock.patch('requests.get') |
355 | 35 | def test_get_single_ticket_status(self, mock_urlopen): | 35 | def test_get_single_ticket_status(self, mock_requests): |
356 | 36 | data = { | 36 | data = { |
357 | 37 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), | 37 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), |
358 | 38 | "status": str(TicketWorkflowStepStatus.INPROGRESS), | 38 | "status": str(TicketWorkflowStepStatus.INPROGRESS), |
359 | @@ -46,9 +46,9 @@ | |||
360 | 46 | "added_binaries": "mynewpackage", | 46 | "added_binaries": "mynewpackage", |
361 | 47 | "removed_binaries": "myoldpackage", | 47 | "removed_binaries": "myoldpackage", |
362 | 48 | } | 48 | } |
366 | 49 | resp = mock.Mock() | 49 | mock_requests.side_effect = [ |
367 | 50 | resp.read.return_value = json.dumps(data) | 50 | FakeRequestsReturn(200, json.dumps(data)) |
368 | 51 | mock_urlopen.return_value = resp | 51 | ] |
369 | 52 | args = self.cli.parse_arguments(['status', '-t', '100']) | 52 | args = self.cli.parse_arguments(['status', '-t', '100']) |
370 | 53 | with capture_stdout(args.func, args) as cm: | 53 | with capture_stdout(args.func, args) as cm: |
371 | 54 | self.assertEqual( | 54 | self.assertEqual( |
372 | @@ -64,10 +64,10 @@ | |||
373 | 64 | str(TicketWorkflowStep.IMAGE_BUILDING), | 64 | str(TicketWorkflowStep.IMAGE_BUILDING), |
374 | 65 | str(TicketWorkflowStepStatus.INPROGRESS)), | 65 | str(TicketWorkflowStepStatus.INPROGRESS)), |
375 | 66 | cm) | 66 | cm) |
377 | 67 | mock_urlopen.assert_called_once() | 67 | mock_requests.assert_called_once() |
378 | 68 | 68 | ||
381 | 69 | @mock.patch('urllib2.urlopen') | 69 | @mock.patch('requests.get') |
382 | 70 | def test_get_ticket_status_unicode(self, mock_urlopen): | 70 | def test_get_ticket_status_unicode(self, mock_requests): |
383 | 71 | data = { | 71 | data = { |
384 | 72 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), | 72 | "current_workflow_step": str(TicketWorkflowStep.IMAGE_BUILDING), |
385 | 73 | "status": str(TicketWorkflowStepStatus.INPROGRESS), | 73 | "status": str(TicketWorkflowStepStatus.INPROGRESS), |
386 | @@ -81,9 +81,9 @@ | |||
387 | 81 | "added_binaries": "mynewpackage", | 81 | "added_binaries": "mynewpackage", |
388 | 82 | "removed_binaries": "myoldpackage", | 82 | "removed_binaries": "myoldpackage", |
389 | 83 | } | 83 | } |
393 | 84 | resp = mock.Mock() | 84 | mock_requests.side_effect = [ |
394 | 85 | resp.read.return_value = json.dumps(data) | 85 | FakeRequestsReturn(200, json.dumps(data)) |
395 | 86 | mock_urlopen.return_value = resp | 86 | ] |
396 | 87 | args = self.cli.parse_arguments(['status', '-t', '100']) | 87 | args = self.cli.parse_arguments(['status', '-t', '100']) |
397 | 88 | with capture_stdout(args.func, args) as cm: | 88 | with capture_stdout(args.func, args) as cm: |
398 | 89 | self.assertEqual( | 89 | self.assertEqual( |
399 | @@ -99,10 +99,10 @@ | |||
400 | 99 | str(TicketWorkflowStep.IMAGE_BUILDING), | 99 | str(TicketWorkflowStep.IMAGE_BUILDING), |
401 | 100 | str(TicketWorkflowStepStatus.INPROGRESS)), | 100 | str(TicketWorkflowStepStatus.INPROGRESS)), |
402 | 101 | cm) | 101 | cm) |
404 | 102 | mock_urlopen.assert_called_once() | 102 | mock_requests.assert_called_once() |
405 | 103 | 103 | ||
408 | 104 | @mock.patch('urllib2.urlopen') | 104 | @mock.patch('requests.get') |
409 | 105 | def test_get_single_failed_ticket_status(self, mock_urlopen): | 105 | def test_get_single_failed_ticket_status(self, mock_requests): |
410 | 106 | data = { | 106 | data = { |
411 | 107 | "current_workflow_step": str(TicketWorkflowStep.FAILED), | 107 | "current_workflow_step": str(TicketWorkflowStep.FAILED), |
412 | 108 | "status": str(TicketWorkflowStepStatus.FAILED), | 108 | "status": str(TicketWorkflowStepStatus.FAILED), |
413 | @@ -116,9 +116,9 @@ | |||
414 | 116 | "added_binaries": "mynewpackage", | 116 | "added_binaries": "mynewpackage", |
415 | 117 | "removed_binaries": "myoldpackage", | 117 | "removed_binaries": "myoldpackage", |
416 | 118 | } | 118 | } |
420 | 119 | resp = mock.Mock() | 119 | mock_requests.side_effect = [ |
421 | 120 | resp.read.return_value = json.dumps(data) | 120 | FakeRequestsReturn(200, json.dumps(data)) |
422 | 121 | mock_urlopen.return_value = resp | 121 | ] |
423 | 122 | args = self.cli.parse_arguments(['status', '-t', '100']) | 122 | args = self.cli.parse_arguments(['status', '-t', '100']) |
424 | 123 | with capture_stdout(args.func, args) as cm: | 123 | with capture_stdout(args.func, args) as cm: |
425 | 124 | self.assertEqual( | 124 | self.assertEqual( |
426 | @@ -133,10 +133,10 @@ | |||
427 | 133 | 'Removed binaries: myoldpackage\n'.format( | 133 | 'Removed binaries: myoldpackage\n'.format( |
428 | 134 | str(TicketWorkflowStepStatus.FAILED)), | 134 | str(TicketWorkflowStepStatus.FAILED)), |
429 | 135 | cm) | 135 | cm) |
431 | 136 | mock_urlopen.assert_called_once() | 136 | mock_requests.assert_called_once() |
432 | 137 | 137 | ||
435 | 138 | @mock.patch('urllib2.urlopen') | 138 | @mock.patch('requests.get') |
436 | 139 | def test_get_all_ticket_status(self, mock_urlopen): | 139 | def test_get_all_ticket_status(self, mock_requests): |
437 | 140 | data = { | 140 | data = { |
438 | 141 | "objects": [ | 141 | "objects": [ |
439 | 142 | { | 142 | { |
440 | @@ -165,9 +165,9 @@ | |||
441 | 165 | }, | 165 | }, |
442 | 166 | ] | 166 | ] |
443 | 167 | } | 167 | } |
447 | 168 | resp = mock.Mock() | 168 | mock_requests.side_effect = [ |
448 | 169 | resp.read.return_value = json.dumps(data) | 169 | FakeRequestsReturn(200, json.dumps(data)) |
449 | 170 | mock_urlopen.return_value = resp | 170 | ] |
450 | 171 | args = self.cli.parse_arguments(['status']) | 171 | args = self.cli.parse_arguments(['status']) |
451 | 172 | with capture_stdout(args.func, args) as cm: | 172 | with capture_stdout(args.func, args) as cm: |
452 | 173 | self.assertEqual( | 173 | self.assertEqual( |
453 | @@ -176,15 +176,15 @@ | |||
454 | 176 | "Ticket #7, Upstream bug fix is 100 110\n" + | 176 | "Ticket #7, Upstream bug fix is 100 110\n" + |
455 | 177 | "Ticket #9, Other new feature is 100 110\n", | 177 | "Ticket #9, Other new feature is 100 110\n", |
456 | 178 | cm) | 178 | cm) |
458 | 179 | mock_urlopen.assert_called_once() | 179 | mock_requests.assert_called_once() |
459 | 180 | 180 | ||
465 | 181 | @mock.patch('urllib2.urlopen') | 181 | @mock.patch('requests.get') |
466 | 182 | def test_get_status_404_response(self, mock_urlopen): | 182 | def test_get_status_404_response(self, mock_requests): |
467 | 183 | mock_urlopen.side_effect = urllib2.HTTPError("http://example.com", | 183 | mock_requests.side_effect = [ |
468 | 184 | 404, "Not Found", "", | 184 | FakeRequestsReturn(404, '', 'Not Found') |
469 | 185 | None) | 185 | ] |
470 | 186 | args = self.cli.parse_arguments(['status', '-t', '99']) | 186 | args = self.cli.parse_arguments(['status', '-t', '99']) |
471 | 187 | with self.assertRaises(SystemExit) as cm: | 187 | with self.assertRaises(SystemExit) as cm: |
472 | 188 | args.func(args) | 188 | args.func(args) |
474 | 189 | mock_urlopen.assert_called_once() | 189 | mock_requests.assert_called_once() |
475 | 190 | self.assertEqual("Ticket number 99 not found.", cm.exception.message) | 190 | self.assertEqual("Ticket number 99 not found.", cm.exception.message) |
476 | 191 | 191 | ||
477 | === modified file 'cli/ci_cli/tests/test_image.py' | |||
478 | --- cli/ci_cli/tests/test_image.py 2014-05-07 14:56:11 +0000 | |||
479 | +++ cli/ci_cli/tests/test_image.py 2014-05-27 09:44:30 +0000 | |||
480 | @@ -26,26 +26,10 @@ | |||
481 | 26 | from ci_cli.tests import ( | 26 | from ci_cli.tests import ( |
482 | 27 | capture_stdout, | 27 | capture_stdout, |
483 | 28 | MainScriptTestCase, | 28 | MainScriptTestCase, |
484 | 29 | FakeRequestsReturn, | ||
485 | 29 | ) | 30 | ) |
486 | 30 | 31 | ||
487 | 31 | 32 | ||
488 | 32 | class FakeUrlOpenReturn: | ||
489 | 33 | """Object to mock the return of urllib2.urlopen.""" | ||
490 | 34 | |||
491 | 35 | def __init__(self, code, content): | ||
492 | 36 | self.code = code | ||
493 | 37 | self.content = content | ||
494 | 38 | |||
495 | 39 | def __repr__(self): | ||
496 | 40 | return self.content | ||
497 | 41 | |||
498 | 42 | def __iter__(self): | ||
499 | 43 | return (line for line in self.content.split("\n")) | ||
500 | 44 | |||
501 | 45 | def read(self): | ||
502 | 46 | return self.content | ||
503 | 47 | |||
504 | 48 | |||
505 | 49 | artifact_data = { | 33 | artifact_data = { |
506 | 50 | "objects": [ | 34 | "objects": [ |
507 | 51 | { | 35 | { |
508 | @@ -88,11 +72,11 @@ | |||
509 | 88 | if os.path.exists(self.image_path): | 72 | if os.path.exists(self.image_path): |
510 | 89 | os.remove(self.image_path) | 73 | os.remove(self.image_path) |
511 | 90 | 74 | ||
513 | 91 | @mock.patch('urllib2.urlopen') | 75 | @mock.patch('requests.get') |
514 | 92 | @mock.patch('ci_utils.data_store.create_for_ticket') | 76 | @mock.patch('ci_utils.data_store.create_for_ticket') |
518 | 93 | def test_get_ticket_image(self, mock_create_datastore, mock_urlopen): | 77 | def test_get_ticket_image(self, mock_create_datastore, mock_requests): |
519 | 94 | mock_urlopen.side_effect = [ | 78 | mock_requests.side_effect = [ |
520 | 95 | FakeUrlOpenReturn(200, json.dumps(artifact_data))] | 79 | FakeRequestsReturn(200, json.dumps(artifact_data))] |
521 | 96 | mock_datastore = mock.Mock() | 80 | mock_datastore = mock.Mock() |
522 | 97 | mock_datastore.get_file.return_value = buffer(" ") | 81 | mock_datastore.get_file.return_value = buffer(" ") |
523 | 98 | mock_create_datastore.return_value = mock_datastore | 82 | mock_create_datastore.return_value = mock_datastore |
524 | @@ -106,12 +90,12 @@ | |||
525 | 106 | "Image file can be found at: {}\n".format(self.image_path)) | 90 | "Image file can be found at: {}\n".format(self.image_path)) |
526 | 107 | mock_datastore.assert_called_once() | 91 | mock_datastore.assert_called_once() |
527 | 108 | 92 | ||
529 | 109 | @mock.patch('urllib2.urlopen') | 93 | @mock.patch('requests.get') |
530 | 110 | @mock.patch('ci_utils.data_store.create_for_ticket') | 94 | @mock.patch('ci_utils.data_store.create_for_ticket') |
531 | 111 | def test_get_ticket_image_not_found(self, mock_create_datastore, | 95 | def test_get_ticket_image_not_found(self, mock_create_datastore, |
535 | 112 | mock_urlopen): | 96 | mock_requests): |
536 | 113 | mock_urlopen.side_effect = [ | 97 | mock_requests.side_effect = [ |
537 | 114 | FakeUrlOpenReturn(200, json.dumps(artifact_data))] | 98 | FakeRequestsReturn(200, json.dumps(artifact_data))] |
538 | 115 | mock_datastore = mock.Mock() | 99 | mock_datastore = mock.Mock() |
539 | 116 | mock_datastore.get_file.side_effect = data_store.DataStoreException( | 100 | mock_datastore.get_file.side_effect = data_store.DataStoreException( |
540 | 117 | "Failed to get file: d62d3d9a-ac3d-11e3-847d-fa163eaf5928.img, " | 101 | "Failed to get file: d62d3d9a-ac3d-11e3-847d-fa163eaf5928.img, " |
541 | @@ -125,12 +109,12 @@ | |||
542 | 125 | with self.assertRaises(ImageObjectNotFound): | 109 | with self.assertRaises(ImageObjectNotFound): |
543 | 126 | args.func(args) | 110 | args.func(args) |
544 | 127 | 111 | ||
546 | 128 | @mock.patch('urllib2.urlopen') | 112 | @mock.patch('requests.get') |
547 | 129 | @mock.patch('ci_utils.data_store.DataStore') | 113 | @mock.patch('ci_utils.data_store.DataStore') |
548 | 130 | def test_get_ticket_image_already_exists(self, mock_data_store, | 114 | def test_get_ticket_image_already_exists(self, mock_data_store, |
552 | 131 | mock_urlopen): | 115 | mock_requests): |
553 | 132 | mock_urlopen.side_effect = [ | 116 | mock_requests.side_effect = [ |
554 | 133 | FakeUrlOpenReturn(200, json.dumps(artifact_data))] | 117 | FakeRequestsReturn(200, json.dumps(artifact_data))] |
555 | 134 | open(self.image_path, 'a').close() | 118 | open(self.image_path, 'a').close() |
556 | 135 | args = self.cli.parse_arguments(['get_image', '-t', '4', '-n', | 119 | args = self.cli.parse_arguments(['get_image', '-t', '4', '-n', |
557 | 136 | self.image_path]) | 120 | self.image_path]) |
558 | @@ -139,13 +123,13 @@ | |||
559 | 139 | "{} already exists.\n".format(self.image_path), | 123 | "{} already exists.\n".format(self.image_path), |
560 | 140 | cm) | 124 | cm) |
561 | 141 | 125 | ||
563 | 142 | @mock.patch('urllib2.urlopen') | 126 | @mock.patch('requests.get') |
564 | 143 | @mock.patch('ci_utils.data_store.create_for_ticket') | 127 | @mock.patch('ci_utils.data_store.create_for_ticket') |
565 | 144 | def test_get_last_completed_ticket_image(self, mock_create_datastore, | 128 | def test_get_last_completed_ticket_image(self, mock_create_datastore, |
570 | 145 | mock_urlopen): | 129 | mock_requests): |
571 | 146 | mock_urlopen.side_effect = [ | 130 | mock_requests.side_effect = [ |
572 | 147 | FakeUrlOpenReturn(200, json.dumps(ticket_data)), | 131 | FakeRequestsReturn(200, json.dumps(ticket_data)), |
573 | 148 | FakeUrlOpenReturn(200, json.dumps(artifact_data)) | 132 | FakeRequestsReturn(200, json.dumps(artifact_data)) |
574 | 149 | ] | 133 | ] |
575 | 150 | mock_datastore = mock.Mock() | 134 | mock_datastore = mock.Mock() |
576 | 151 | mock_datastore.get_file.return_value = buffer(" ") | 135 | mock_datastore.get_file.return_value = buffer(" ") |
577 | @@ -159,11 +143,11 @@ | |||
578 | 159 | "Image file can be found at: {}\n".format(self.image_path)) | 143 | "Image file can be found at: {}\n".format(self.image_path)) |
579 | 160 | mock_datastore.assert_called_once() | 144 | mock_datastore.assert_called_once() |
580 | 161 | 145 | ||
583 | 162 | @mock.patch('urllib2.urlopen') | 146 | @mock.patch('requests.get') |
584 | 163 | def test_get_last_completed_ticket_none_complete(self, mock_urlopen): | 147 | def test_get_last_completed_ticket_none_complete(self, mock_requests): |
585 | 164 | data = {'objects': []} | 148 | data = {'objects': []} |
588 | 165 | mock_urlopen.side_effect = [ | 149 | mock_requests.side_effect = [ |
589 | 166 | FakeUrlOpenReturn(200, json.dumps(data))] | 150 | FakeRequestsReturn(200, json.dumps(data))] |
590 | 167 | args = self.cli.parse_arguments(['get_image', '-n', self.image_path]) | 151 | args = self.cli.parse_arguments(['get_image', '-n', self.image_path]) |
591 | 168 | with self.assertRaises(SystemExit) as cm: | 152 | with self.assertRaises(SystemExit) as cm: |
592 | 169 | args.func(args) | 153 | args.func(args) |
593 | 170 | 154 | ||
594 | === modified file 'cli/ci_cli/tests/test_utils.py' | |||
595 | --- cli/ci_cli/tests/test_utils.py 2014-05-07 17:57:12 +0000 | |||
596 | +++ cli/ci_cli/tests/test_utils.py 2014-05-27 09:44:30 +0000 | |||
597 | @@ -21,6 +21,7 @@ | |||
598 | 21 | import tempfile | 21 | import tempfile |
599 | 22 | 22 | ||
600 | 23 | from ci_cli import utils | 23 | from ci_cli import utils |
601 | 24 | from ci_cli.tests import FakeRequestsReturn | ||
602 | 24 | from ci_utils.testing import TestCaseWithGnupg | 25 | from ci_utils.testing import TestCaseWithGnupg |
603 | 25 | 26 | ||
604 | 26 | 27 | ||
605 | @@ -47,24 +48,24 @@ | |||
606 | 47 | location = 'http://www.example.com/api/v1/ticket/abc/123/' | 48 | location = 'http://www.example.com/api/v1/ticket/abc/123/' |
607 | 48 | self.assertRaises(ValueError, utils.parse_id, location) | 49 | self.assertRaises(ValueError, utils.parse_id, location) |
608 | 49 | 50 | ||
611 | 50 | @mock.patch('urllib2.urlopen') | 51 | @mock.patch('requests.get') |
612 | 51 | def test_get_sourcepackage_uri(self, mock_urlopen): | 52 | def test_get_sourcepackage_uri(self, mock_requests): |
613 | 52 | data = {"objects": [{"resource_uri": "/api/v1/sourcepackage/4/"}]} | 53 | data = {"objects": [{"resource_uri": "/api/v1/sourcepackage/4/"}]} |
617 | 53 | resp = mock.Mock() | 54 | mock_requests.side_effect = [ |
618 | 54 | resp.read.return_value = json.dumps(data) | 55 | FakeRequestsReturn(200, json.dumps(data)) |
619 | 55 | mock_urlopen.return_value = resp | 56 | ] |
620 | 56 | uri = utils.get_sourcepackage_uri('foobar') | 57 | uri = utils.get_sourcepackage_uri('foobar') |
622 | 57 | mock_urlopen.assert_called_once() | 58 | mock_requests.assert_called_once() |
623 | 58 | self.assertEquals(uri, '/api/v1/sourcepackage/4/') | 59 | self.assertEquals(uri, '/api/v1/sourcepackage/4/') |
624 | 59 | 60 | ||
627 | 60 | @mock.patch('urllib2.urlopen') | 61 | @mock.patch('requests.get') |
628 | 61 | def test_get_sourcepackage_uri_not_found(self, mock_urlopen): | 62 | def test_get_sourcepackage_uri_not_found(self, mock_requests): |
629 | 62 | data = {"objects": []} | 63 | data = {"objects": []} |
633 | 63 | resp = mock.Mock() | 64 | mock_requests.side_effect = [ |
634 | 64 | resp.read.return_value = json.dumps(data) | 65 | FakeRequestsReturn(200, json.dumps(data)) |
635 | 65 | mock_urlopen.return_value = resp | 66 | ] |
636 | 66 | uri = utils.get_sourcepackage_uri('foobar') | 67 | uri = utils.get_sourcepackage_uri('foobar') |
638 | 67 | mock_urlopen.assert_called_once() | 68 | mock_requests.assert_called_once() |
639 | 68 | self.assertEquals(uri, '') | 69 | self.assertEquals(uri, '') |
640 | 69 | 70 | ||
641 | 70 | def test_load_config(self): | 71 | def test_load_config(self): |
642 | 71 | 72 | ||
643 | === modified file 'cli/ci_cli/utils.py' | |||
644 | --- cli/ci_cli/utils.py 2014-04-08 13:27:01 +0000 | |||
645 | +++ cli/ci_cli/utils.py 2014-05-27 09:44:30 +0000 | |||
646 | @@ -17,8 +17,8 @@ | |||
647 | 17 | import json | 17 | import json |
648 | 18 | import logging | 18 | import logging |
649 | 19 | import sys | 19 | import sys |
650 | 20 | import urllib2 | ||
651 | 21 | import yaml | 20 | import yaml |
652 | 21 | import requests | ||
653 | 22 | 22 | ||
654 | 23 | from ci_utils import data_store | 23 | from ci_utils import data_store |
655 | 24 | 24 | ||
656 | @@ -72,22 +72,19 @@ | |||
657 | 72 | 72 | ||
658 | 73 | 73 | ||
659 | 74 | def post(url, data, headers=HEADERS, patch=False): | 74 | def post(url, data, headers=HEADERS, patch=False): |
663 | 75 | req = urllib2.Request(url=url, data=json.dumps(data), headers=HEADERS) | 75 | req = requests.post(url=url, data=json.dumps(data), headers=HEADERS) |
664 | 76 | f = urllib2.urlopen(req) | 76 | resp = req.headers |
665 | 77 | return f.info().dict['location'] | 77 | return resp['location'] |
666 | 78 | 78 | ||
667 | 79 | 79 | ||
668 | 80 | def patch(url, data, headers=HEADERS): | 80 | def patch(url, data, headers=HEADERS): |
672 | 81 | req = urllib2.Request(url=url, data=json.dumps(data), headers=HEADERS) | 81 | requests.patch(url=url, data=json.dumps(data), headers=HEADERS) |
670 | 82 | req.get_method = lambda: 'PATCH' | ||
671 | 83 | urllib2.urlopen(req) | ||
673 | 84 | 82 | ||
674 | 85 | 83 | ||
675 | 86 | def get(url): | 84 | def get(url): |
680 | 87 | f = urllib2.urlopen(url) | 85 | r = requests.get(url) |
681 | 88 | 86 | r.raise_for_status() | |
682 | 89 | json_data = f.read() | 87 | return r.json() |
679 | 90 | return json.loads(json_data) | ||
683 | 91 | 88 | ||
684 | 92 | 89 | ||
685 | 93 | def parse_id(location): | 90 | def parse_id(location): |
686 | @@ -101,9 +98,7 @@ | |||
687 | 101 | 98 | ||
688 | 102 | def get_sourcepackage_uri(sourcepackage): | 99 | def get_sourcepackage_uri(sourcepackage): |
689 | 103 | url = CI_URL + SOURCEPACKAGE_BASE + '?name__iexact=' + sourcepackage | 100 | url = CI_URL + SOURCEPACKAGE_BASE + '?name__iexact=' + sourcepackage |
693 | 104 | f = urllib2.urlopen(url) | 101 | data = get(url) |
691 | 105 | json_data = f.read() | ||
692 | 106 | data = json.loads(json_data) | ||
694 | 107 | try: | 102 | try: |
695 | 108 | sourcepackage_uri = data['objects'][0]['resource_uri'] | 103 | sourcepackage_uri = data['objects'][0]['resource_uri'] |
696 | 109 | return sourcepackage_uri | 104 | return sourcepackage_uri |
697 | 110 | 105 | ||
698 | === modified file 'cli/setup.py' | |||
699 | --- cli/setup.py 2014-05-07 17:33:32 +0000 | |||
700 | +++ cli/setup.py 2014-05-27 09:44:30 +0000 | |||
701 | @@ -27,6 +27,7 @@ | |||
702 | 27 | 'dput>=1.6', | 27 | 'dput>=1.6', |
703 | 28 | 'lazr.enum>=1.1.2', | 28 | 'lazr.enum>=1.1.2', |
704 | 29 | 'PyYAML==3.10', | 29 | 'PyYAML==3.10', |
705 | 30 | 'requests==2.2.1', | ||
706 | 30 | 'mock==1.0.1', | 31 | 'mock==1.0.1', |
707 | 31 | 'testfixtures>=3.0.1', | 32 | 'testfixtures>=3.0.1', |
708 | 32 | 'python-gnupg>=0.3.6', | 33 | 'python-gnupg>=0.3.6', |
709 | 33 | 34 | ||
710 | === modified file 'cli/ubuntu-ci' | |||
711 | --- cli/ubuntu-ci 2014-05-07 14:56:11 +0000 | |||
712 | +++ cli/ubuntu-ci 2014-05-27 09:44:30 +0000 | |||
713 | @@ -19,7 +19,8 @@ | |||
714 | 19 | import logging | 19 | import logging |
715 | 20 | import os | 20 | import os |
716 | 21 | import sys | 21 | import sys |
718 | 22 | import urllib2 | 22 | |
719 | 23 | from requests import exceptions | ||
720 | 23 | 24 | ||
721 | 24 | from ci_cli import ( | 25 | from ci_cli import ( |
722 | 25 | ticket, | 26 | ticket, |
723 | @@ -78,8 +79,8 @@ | |||
724 | 78 | help='Ticket to display status of. Leave off ' | 79 | help='Ticket to display status of. Leave off ' |
725 | 79 | 'for last successful ticket') | 80 | 'for last successful ticket') |
726 | 80 | image_parser.add_argument('-n', '--name', | 81 | image_parser.add_argument('-n', '--name', |
729 | 81 | help='Desired file name (and path) for the ' | 82 | help='Desired file name (and path) for the ' |
730 | 82 | 'downloaded image', required=True) | 83 | 'downloaded image', required=True) |
731 | 83 | image_parser.set_defaults(func=image.get_image) | 84 | image_parser.set_defaults(func=image.get_image) |
732 | 84 | return parser.parse_args(args) | 85 | return parser.parse_args(args) |
733 | 85 | 86 | ||
734 | @@ -153,10 +154,16 @@ | |||
735 | 153 | except image.ImageObjectNotFound as exc: | 154 | except image.ImageObjectNotFound as exc: |
736 | 154 | log.error("Image cannot be downloaded: {} ({})".format(exc.filename, | 155 | log.error("Image cannot be downloaded: {} ({})".format(exc.filename, |
737 | 155 | str(exc))) | 156 | str(exc))) |
742 | 156 | except urllib2.URLError as exc: | 157 | except exceptions.RequestException as exc: |
743 | 157 | if isinstance(exc, urllib2.HTTPError): | 158 | error = ("Cannot reach the server at {}. Please, check your " |
744 | 158 | reason = exc.reason | 159 | "configuration file ({}): is 'ci_url' correctly set? " |
745 | 159 | code = exc.code | 160 | "Is the server up and reachable from this machine? " |
746 | 161 | "({}).".format(utils.CI_URL, utils.DEF_CFG, str(exc))) | ||
747 | 162 | if isinstance(exc, exceptions.HTTPError): | ||
748 | 163 | code = None | ||
749 | 164 | if exc.response: | ||
750 | 165 | code = exc.response.status_code | ||
751 | 166 | |||
752 | 160 | if code == 500: | 167 | if code == 500: |
753 | 161 | log.error("Server at {} reported internal error. Maybe a " | 168 | log.error("Server at {} reported internal error. Maybe a " |
754 | 162 | "database hiccup?".format(utils.CI_URL)) | 169 | "database hiccup?".format(utils.CI_URL)) |
755 | @@ -164,13 +171,9 @@ | |||
756 | 164 | log.error("Server at {} not found. Is 'ci_url' correctly " | 171 | log.error("Server at {} not found. Is 'ci_url' correctly " |
757 | 165 | "set? ({})".format(utils.CI_URL, str(exc))) | 172 | "set? ({})".format(utils.CI_URL, str(exc))) |
758 | 166 | else: | 173 | else: |
760 | 167 | log.error(str(exc)) | 174 | log.error(error) |
761 | 168 | else: | 175 | else: |
767 | 169 | reason = exc.reason | 176 | log.error(error) |
763 | 170 | log.error("Cannot reach the server at {}. Please, check your " | ||
764 | 171 | "configuration file ({}): is 'ci_url' correctly set? " | ||
765 | 172 | "Is the server up and reachable from this machine? " | ||
766 | 173 | "({}).".format(utils.CI_URL, utils.DEF_CFG, reason)) | ||
768 | 174 | except data_store.DataStoreException as exc: | 177 | except data_store.DataStoreException as exc: |
769 | 175 | log.error("Data Store Error: {}".format(exc)) | 178 | log.error("Data Store Error: {}".format(exc)) |
770 | 176 | except Exception: | 179 | except Exception: |
771 | 177 | 180 | ||
772 | === modified file 'debian/control' | |||
773 | --- debian/control 2014-05-15 16:12:18 +0000 | |||
774 | +++ debian/control 2014-05-27 09:44:30 +0000 | |||
775 | @@ -32,6 +32,7 @@ | |||
776 | 32 | python-lazr.enum (>= 1.1.2-0~), | 32 | python-lazr.enum (>= 1.1.2-0~), |
777 | 33 | python-yaml (>= 3.10-2), | 33 | python-yaml (>= 3.10-2), |
778 | 34 | python-swiftclient, | 34 | python-swiftclient, |
779 | 35 | python-requests (>=2.2.1), | ||
780 | 35 | uci-utils (= ${binary:Version}), | 36 | uci-utils (= ${binary:Version}), |
781 | 36 | ${misc:Depends}, | 37 | ${misc:Depends}, |
782 | 37 | ${python:Depends} | 38 | ${python:Depends} |
FAILED: Continuous integration, rev:499 /code.launchpad .net/~cjohnston /uci-engine/ cli-requests/ +merge/ 220960/ +edit-commit- message
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http:// s-jenkins. ubuntu- ci:8080/ job/uci- engine- ci/701/
Executed test runs:
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/uci- engine- ci/701/ rebuild
http://