Status: | Merged |
---|---|
Approved by: | Eric Day |
Approved revision: | 40 |
Merged at revision: | 38 |
Proposed branch: | lp:~eday/burrow/doc-updates |
Merge into: | lp:burrow |
Diff against target: |
771 lines (+246/-121) 13 files modified
burrow/__init__.py (+11/-0) burrow/backend/__init__.py (+3/-14) burrow/backend/http.py (+5/-2) burrow/backend/memory.py (+6/-6) burrow/backend/sqlite.py (+13/-13) burrow/frontend/wsgi.py (+5/-6) burrow/shell.py (+7/-6) test/__init__.py (+55/-0) test/backend/__init__.py (+21/-21) test/backend/test_http.py (+0/-53) test/frontend/__init__.py (+15/-0) test/frontend/test_wsgi.py (+45/-0) test/test_client.py (+60/-0) |
To merge this branch: | bzr merge lp:~eday/burrow/doc-updates |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Burrow Core Team | Pending | ||
Review via email: mp+72783@code.launchpad.net |
Commit message
Description of the change
Added client API unit tests, moved exceptions to main burrow module, and added more WSGI frontend tests.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'burrow/__init__.py' |
2 | --- burrow/__init__.py 2011-04-20 18:21:51 +0000 |
3 | +++ burrow/__init__.py 2011-08-24 20:17:24 +0000 |
4 | @@ -25,3 +25,14 @@ |
5 | # This installs the _(...) function as a built-in so all other modules |
6 | # don't need to. |
7 | gettext.install('burrow') |
8 | + |
9 | + |
10 | +class NotFound(Exception): |
11 | + '''Raised when an account, queue, or message can not be found.''' |
12 | + pass |
13 | + |
14 | + |
15 | +class InvalidArguments(Exception): |
16 | + '''Raised when the given arguments are invalid, usually from attributes |
17 | + or filters.''' |
18 | + pass |
19 | |
20 | === modified file 'burrow/backend/__init__.py' |
21 | --- burrow/backend/__init__.py 2011-08-24 16:54:43 +0000 |
22 | +++ burrow/backend/__init__.py 2011-08-24 20:17:24 +0000 |
23 | @@ -228,7 +228,7 @@ |
24 | if detail == 'none': |
25 | detail = None |
26 | elif detail is not None and detail not in ['id', 'all']: |
27 | - raise burrow.backend.InvalidArguments(detail) |
28 | + raise burrow.InvalidArguments(detail) |
29 | return detail |
30 | |
31 | def _get_message_detail(self, filters, default=None): |
32 | @@ -239,7 +239,7 @@ |
33 | if detail == 'none': |
34 | detail = None |
35 | elif detail is not None and detail not in options: |
36 | - raise burrow.backend.InvalidArguments(detail) |
37 | + raise burrow.InvalidArguments(detail) |
38 | return detail |
39 | |
40 | def notify(self, account, queue): |
41 | @@ -293,20 +293,9 @@ |
42 | for message in method(): |
43 | yield message |
44 | return |
45 | - except burrow.backend.NotFound, exception: |
46 | + except burrow.NotFound, exception: |
47 | now = time.time() |
48 | if seconds - now > 0: |
49 | self.wait(account, queue, seconds - now) |
50 | if seconds < time.time(): |
51 | raise exception |
52 | - |
53 | - |
54 | -class NotFound(Exception): |
55 | - '''Raised when an account, queue, or message can not be found.''' |
56 | - pass |
57 | - |
58 | - |
59 | -class InvalidArguments(Exception): |
60 | - '''Raised when the given arguments are invalid, usually from attributes |
61 | - or filters.''' |
62 | - pass |
63 | |
64 | === modified file 'burrow/backend/http.py' |
65 | --- burrow/backend/http.py 2011-08-24 16:54:43 +0000 |
66 | +++ burrow/backend/http.py 2011-08-24 20:17:24 +0000 |
67 | @@ -145,8 +145,11 @@ |
68 | yield item |
69 | return |
70 | yield body |
71 | + body = response.read() |
72 | + if body == '': |
73 | + body = response.reason |
74 | if response.status == 400: |
75 | - raise burrow.backend.InvalidArguments(response.reason) |
76 | + raise burrow.InvalidArguments(body) |
77 | if response.status == 404: |
78 | - raise burrow.backend.NotFound() |
79 | + raise burrow.NotFound(body) |
80 | raise Exception(response.reason) |
81 | |
82 | === modified file 'burrow/backend/memory.py' |
83 | --- burrow/backend/memory.py 2011-08-24 16:54:43 +0000 |
84 | +++ burrow/backend/memory.py 2011-08-24 20:17:24 +0000 |
85 | @@ -110,7 +110,7 @@ |
86 | try: |
87 | message = queue.messages.get(message) |
88 | created = False |
89 | - except burrow.backend.NotFound: |
90 | + except burrow.NotFound: |
91 | message = queue.messages.get(message, True) |
92 | created = True |
93 | message.ttl = ttl |
94 | @@ -226,7 +226,7 @@ |
95 | return self.index[id] |
96 | elif create: |
97 | return self.add(self.item_class(id)) |
98 | - raise burrow.backend.NotFound() |
99 | + raise burrow.NotFound(self.item_class.__name__ + " not found") |
100 | |
101 | def iter(self, filters=None): |
102 | '''Iterate through all items in the list, possibly filtered.''' |
103 | @@ -241,7 +241,7 @@ |
104 | else: |
105 | item = self.first |
106 | if item is None: |
107 | - raise burrow.backend.NotFound() |
108 | + raise burrow.NotFound(self.item_class.__name__ + " not found") |
109 | while item is not None: |
110 | yield item |
111 | if limit: |
112 | @@ -253,7 +253,7 @@ |
113 | def reset(self): |
114 | '''Remove all items in the list.''' |
115 | if self.count() == 0: |
116 | - raise burrow.backend.NotFound() |
117 | + raise burrow.NotFound(self.item_class.__name__ + " not found") |
118 | self.first = None |
119 | self.last = None |
120 | self.index.clear() |
121 | @@ -287,7 +287,7 @@ |
122 | elif create: |
123 | account = self.add(Account(account)) |
124 | else: |
125 | - raise burrow.backend.NotFound() |
126 | + raise burrow.NotFound('Account not found') |
127 | return account, account.queues.get(queue, create) |
128 | |
129 | |
130 | @@ -361,4 +361,4 @@ |
131 | break |
132 | item = item.next |
133 | if count == 0: |
134 | - raise burrow.backend.NotFound() |
135 | + raise burrow.NotFound('Message not found') |
136 | |
137 | === modified file 'burrow/backend/sqlite.py' |
138 | --- burrow/backend/sqlite.py 2011-08-24 16:54:43 +0000 |
139 | +++ burrow/backend/sqlite.py 2011-08-24 20:17:24 +0000 |
140 | @@ -66,7 +66,7 @@ |
141 | if filters is None or len(filters) == 0: |
142 | query = 'SELECT rowid FROM accounts LIMIT 1' |
143 | if len(self.db.execute(query).fetchall()) == 0: |
144 | - raise burrow.backend.NotFound() |
145 | + raise burrow.NotFound('Account not found') |
146 | self.db.execute('DELETE FROM accounts') |
147 | self.db.execute('DELETE FROM queues') |
148 | self.db.execute('DELETE FROM messages') |
149 | @@ -136,7 +136,7 @@ |
150 | marker = self._get_account(marker) |
151 | query += ' WHERE rowid > ?' |
152 | values += (marker,) |
153 | - except burrow.backend.NotFound: |
154 | + except burrow.NotFound: |
155 | marker = None |
156 | if limit is not None: |
157 | query += ' LIMIT ?' |
158 | @@ -146,14 +146,14 @@ |
159 | count += 1 |
160 | yield row |
161 | if count == 0: |
162 | - raise burrow.backend.NotFound() |
163 | + raise burrow.NotFound('Account not found') |
164 | |
165 | def _get_account(self, account): |
166 | '''Get the rowid for a given account ID.''' |
167 | query = 'SELECT rowid FROM accounts WHERE account=?' |
168 | rows = self.db.execute(query, (account,)).fetchall() |
169 | if len(rows) == 0: |
170 | - raise burrow.backend.NotFound() |
171 | + raise burrow.NotFound('Account not found') |
172 | return rows[0][0] |
173 | |
174 | def delete_queues(self, account, filters=None): |
175 | @@ -213,7 +213,7 @@ |
176 | marker = self._get_queue(account_rowid, marker) |
177 | query += ' AND rowid > ?' |
178 | values += (marker,) |
179 | - except burrow.backend.NotFound: |
180 | + except burrow.NotFound: |
181 | marker = None |
182 | if limit is not None: |
183 | query += ' LIMIT ?' |
184 | @@ -223,14 +223,14 @@ |
185 | count += 1 |
186 | yield row |
187 | if count == 0: |
188 | - raise burrow.backend.NotFound() |
189 | + raise burrow.NotFound('Queue not found') |
190 | |
191 | def _get_queue(self, account_rowid, queue): |
192 | '''Get the rowid for a given queue ID.''' |
193 | query = 'SELECT rowid FROM queues WHERE account=? AND queue=?' |
194 | rows = self.db.execute(query, (account_rowid, queue)).fetchall() |
195 | if len(rows) == 0: |
196 | - raise burrow.backend.NotFound() |
197 | + raise burrow.NotFound('Queue not found') |
198 | return rows[0][0] |
199 | |
200 | @burrow.backend.wait_without_attributes |
201 | @@ -311,7 +311,7 @@ |
202 | marker = self._get_message(queue_rowid, marker) |
203 | query += ' AND rowid > ?' |
204 | values += (marker,) |
205 | - except burrow.backend.NotFound: |
206 | + except burrow.NotFound: |
207 | marker = None |
208 | if match_hidden is False: |
209 | query += ' AND hide=0' |
210 | @@ -323,7 +323,7 @@ |
211 | count += 1 |
212 | yield row |
213 | if count == 0: |
214 | - raise burrow.backend.NotFound() |
215 | + raise burrow.NotFound('Message not found') |
216 | |
217 | def _get_message(self, queue_rowid, message, full=False): |
218 | '''Get the rowid for a given message ID.''' |
219 | @@ -334,7 +334,7 @@ |
220 | query += ' FROM messages WHERE queue=? AND message=?' |
221 | rows = self.db.execute(query, (queue_rowid, message)).fetchall() |
222 | if len(rows) == 0: |
223 | - raise burrow.backend.NotFound() |
224 | + raise burrow.NotFound('Message not found') |
225 | if full: |
226 | return rows[0] |
227 | return rows[0][0] |
228 | @@ -390,12 +390,12 @@ |
229 | ttl, hide = self._get_attributes(attributes, ttl=0, hide=0) |
230 | try: |
231 | account_rowid = self._get_account(account) |
232 | - except burrow.backend.NotFound: |
233 | + except burrow.NotFound: |
234 | query = 'INSERT INTO accounts VALUES (?)' |
235 | account_rowid = self.db.execute(query, (account,)).lastrowid |
236 | try: |
237 | queue_rowid = self._get_queue(account_rowid, queue) |
238 | - except burrow.backend.NotFound: |
239 | + except burrow.NotFound: |
240 | query = 'INSERT INTO queues VALUES (?,?)' |
241 | values = (account_rowid, queue) |
242 | queue_rowid = self.db.execute(query, values).lastrowid |
243 | @@ -404,7 +404,7 @@ |
244 | query = 'UPDATE messages SET ttl=?,hide=?,body=? WHERE rowid=?' |
245 | self.db.execute(query, (ttl, hide, body, message_rowid)) |
246 | created = False |
247 | - except burrow.backend.NotFound: |
248 | + except burrow.NotFound: |
249 | query = 'INSERT INTO messages VALUES (?,?,?,?,?)' |
250 | self.db.execute(query, (queue_rowid, message, ttl, hide, body)) |
251 | created = True |
252 | |
253 | === modified file 'burrow/frontend/wsgi.py' |
254 | --- burrow/frontend/wsgi.py 2011-08-16 23:37:49 +0000 |
255 | +++ burrow/frontend/wsgi.py 2011-08-24 20:17:24 +0000 |
256 | @@ -21,7 +21,6 @@ |
257 | import routes.middleware |
258 | import webob.dec |
259 | |
260 | -import burrow.backend |
261 | import burrow.frontend |
262 | |
263 | # Default configuration values for this module. |
264 | @@ -101,7 +100,7 @@ |
265 | args['attributes'] = self._parse_attributes(req) |
266 | method = getattr(self.backend, '%s_%s' % (method, action), None) |
267 | if method is None: |
268 | - return self._response(status=400) |
269 | + return self._response(status=405) |
270 | args['filters'] = self._parse_filters(req) |
271 | return self._response(body=lambda: method(**args)) |
272 | |
273 | @@ -187,12 +186,12 @@ |
274 | body = body() |
275 | if isinstance(body, types.GeneratorType): |
276 | body = list(body) |
277 | - except burrow.backend.InvalidArguments: |
278 | + except burrow.InvalidArguments, exception: |
279 | status = 400 |
280 | - body = None |
281 | - except burrow.backend.NotFound: |
282 | + body = exception.message |
283 | + except burrow.NotFound, exception: |
284 | status = 404 |
285 | - body = None |
286 | + body = exception.message |
287 | if body == []: |
288 | body = None |
289 | return status, body |
290 | |
291 | === modified file 'burrow/shell.py' |
292 | --- burrow/shell.py 2011-04-22 02:18:26 +0000 |
293 | +++ burrow/shell.py 2011-08-24 20:17:24 +0000 |
294 | @@ -112,7 +112,10 @@ |
295 | '''Run the command given in arguments or enter an interactive shell.''' |
296 | if len(self.args) == 0: |
297 | for command in self._get_command(): |
298 | - self.run_command(command[0], command[1:]) |
299 | + try: |
300 | + self.run_command(command[0], command[1:]) |
301 | + except burrow.NotFound, exception: |
302 | + print exception |
303 | else: |
304 | self.run_command(self.args[0], self.args[1:]) |
305 | |
306 | @@ -131,6 +134,8 @@ |
307 | while True: |
308 | try: |
309 | command = raw_input(prompt) |
310 | + except KeyboardInterrupt: |
311 | + break |
312 | except EOFError: |
313 | if os.isatty(sys.stdin.fileno()): |
314 | |
315 | @@ -164,11 +169,7 @@ |
316 | args.append(self._pack_attributes()) |
317 | if section.get('filters', None): |
318 | args.append(self._pack_filters()) |
319 | - try: |
320 | - result = getattr(self.client, command)(*args) |
321 | - except Exception, exception: |
322 | - print exception |
323 | - return |
324 | + result = getattr(self.client, command)(*args) |
325 | self._print_result(result) |
326 | |
327 | def _get_section(self, command): |
328 | |
329 | === modified file 'test/__init__.py' |
330 | --- test/__init__.py 2011-08-16 20:59:06 +0000 |
331 | +++ test/__init__.py 2011-08-24 20:17:24 +0000 |
332 | @@ -13,3 +13,58 @@ |
333 | # limitations under the License. |
334 | |
335 | '''Unittests for burrow.''' |
336 | + |
337 | +import atexit |
338 | +import os |
339 | +import signal |
340 | +import sys |
341 | +import time |
342 | + |
343 | +import burrow |
344 | + |
345 | + |
346 | +def start_server(): |
347 | + '''Fork and start the server, saving the pid in a file.''' |
348 | + kill_server() |
349 | + pid = os.fork() |
350 | + if pid == 0: |
351 | + try: |
352 | + import coverage |
353 | + cov = coverage.coverage(data_suffix=True) |
354 | + cov.start() |
355 | + |
356 | + def save_coverage(_signum, _frame): |
357 | + '''Callback for signal to save coverage info to file.''' |
358 | + cov.save() |
359 | + |
360 | + signal.signal(signal.SIGUSR1, save_coverage) |
361 | + except ImportError: |
362 | + pass |
363 | + server = burrow.Server(add_default_log_handler=False) |
364 | + server.frontends[0].default_ttl = 0 |
365 | + server.run() |
366 | + sys.exit(0) |
367 | + pid_file = open('TestHTTP.pid', 'w') |
368 | + pid_file.write(str(pid)) |
369 | + pid_file.close() |
370 | + atexit.register(kill_server) |
371 | + time.sleep(1) |
372 | + |
373 | + |
374 | +def kill_server(): |
375 | + '''Try killing the server if the pid file exists.''' |
376 | + try: |
377 | + pid_file = open('TestHTTP.pid', 'r') |
378 | + pid = pid_file.read() |
379 | + pid_file.close() |
380 | + try: |
381 | + os.kill(int(pid), signal.SIGUSR1) |
382 | + time.sleep(1) |
383 | + os.kill(int(pid), signal.SIGTERM) |
384 | + except OSError: |
385 | + pass |
386 | + os.unlink('TestHTTP.pid') |
387 | + except IOError: |
388 | + pass |
389 | + |
390 | +start_server() |
391 | |
392 | === modified file 'test/backend/__init__.py' |
393 | --- test/backend/__init__.py 2011-08-16 20:59:06 +0000 |
394 | +++ test/backend/__init__.py 2011-08-24 20:17:24 +0000 |
395 | @@ -41,12 +41,12 @@ |
396 | '''Ensure the backend is empty before, used before and after |
397 | each test.''' |
398 | accounts = self.backend.get_accounts() |
399 | - self.assertRaises(burrow.backend.NotFound, list, accounts) |
400 | + self.assertRaises(burrow.NotFound, list, accounts) |
401 | queues = self.backend.get_queues('a') |
402 | - self.assertRaises(burrow.backend.NotFound, list, queues) |
403 | + self.assertRaises(burrow.NotFound, list, queues) |
404 | filters = dict(match_hidden=True) |
405 | messages = self.backend.get_messages('a', 'q', filters) |
406 | - self.assertRaises(burrow.backend.NotFound, list, messages) |
407 | + self.assertRaises(burrow.NotFound, list, messages) |
408 | |
409 | def delete_messages(self): |
410 | '''Delete messages, including those that are hidden. Use |
411 | @@ -73,7 +73,7 @@ |
412 | self.assertEquals(['a'], list(self.backend.get_accounts())) |
413 | self.assertEquals([], list(self.backend.delete_accounts())) |
414 | accounts = self.backend.delete_accounts() |
415 | - self.assertRaises(burrow.backend.NotFound, list, accounts) |
416 | + self.assertRaises(burrow.NotFound, list, accounts) |
417 | |
418 | def test_large(self): |
419 | for name in xrange(0, 1000): |
420 | @@ -104,7 +104,7 @@ |
421 | self.backend.create_message('a', 'q', 'm', 'test') |
422 | filters = dict(detail='bad') |
423 | accounts = self.backend.delete_accounts(filters) |
424 | - self.assertRaises(burrow.backend.InvalidArguments, list, accounts) |
425 | + self.assertRaises(burrow.InvalidArguments, list, accounts) |
426 | self.assertEquals([], list(self.backend.delete_accounts())) |
427 | |
428 | def test_delete_marker(self): |
429 | @@ -174,7 +174,7 @@ |
430 | self.backend.create_message('a', 'q', 'm', 'test') |
431 | filters = dict(detail='bad') |
432 | accounts = self.backend.get_accounts(filters) |
433 | - self.assertRaises(burrow.backend.InvalidArguments, list, accounts) |
434 | + self.assertRaises(burrow.InvalidArguments, list, accounts) |
435 | self.assertEquals([], list(self.backend.delete_accounts())) |
436 | |
437 | def test_get_marker(self): |
438 | @@ -191,7 +191,7 @@ |
439 | self.assertEquals(accounts[2:], accounts2) |
440 | filters = dict(marker=accounts[2]) |
441 | accounts2 = self.backend.get_accounts(filters) |
442 | - self.assertRaises(burrow.backend.NotFound, list, accounts2) |
443 | + self.assertRaises(burrow.NotFound, list, accounts2) |
444 | filters = dict(marker='unknown') |
445 | accounts2 = list(self.backend.get_accounts(filters)) |
446 | self.assertEquals(accounts, accounts2) |
447 | @@ -240,7 +240,7 @@ |
448 | self.assertEquals(['q'], list(self.backend.get_queues('a'))) |
449 | self.assertEquals([], list(self.backend.delete_queues('a'))) |
450 | queues = self.backend.delete_queues('a') |
451 | - self.assertRaises(burrow.backend.NotFound, list, queues) |
452 | + self.assertRaises(burrow.NotFound, list, queues) |
453 | |
454 | def test_large(self): |
455 | for name in xrange(0, 1000): |
456 | @@ -271,7 +271,7 @@ |
457 | self.backend.create_message('a', 'q', 'm', 'test') |
458 | filters = dict(detail='bad') |
459 | queues = self.backend.delete_queues('a', filters) |
460 | - self.assertRaises(burrow.backend.InvalidArguments, list, queues) |
461 | + self.assertRaises(burrow.InvalidArguments, list, queues) |
462 | self.assertEquals([], list(self.backend.delete_queues('a'))) |
463 | |
464 | def test_delete_marker(self): |
465 | @@ -341,7 +341,7 @@ |
466 | self.backend.create_message('a', 'q', 'm', 'test') |
467 | filters = dict(detail='bad') |
468 | queues = self.backend.get_queues('a', filters) |
469 | - self.assertRaises(burrow.backend.InvalidArguments, list, queues) |
470 | + self.assertRaises(burrow.InvalidArguments, list, queues) |
471 | self.assertEquals([], list(self.backend.delete_queues('a'))) |
472 | |
473 | def test_get_marker(self): |
474 | @@ -358,7 +358,7 @@ |
475 | self.assertEquals(queues[2:], queues2) |
476 | filters = dict(marker=queues[2]) |
477 | queues2 = self.backend.get_queues('a', filters) |
478 | - self.assertRaises(burrow.backend.NotFound, list, queues2) |
479 | + self.assertRaises(burrow.NotFound, list, queues2) |
480 | filters = dict(marker='unknown') |
481 | queues2 = list(self.backend.get_queues('a', filters)) |
482 | self.assertEquals(queues, queues2) |
483 | @@ -418,9 +418,9 @@ |
484 | self.assertEquals([], list(messages)) |
485 | self.delete_messages() |
486 | messages = self.backend.delete_messages('a', 'q') |
487 | - self.assertRaises(burrow.backend.NotFound, list, messages) |
488 | + self.assertRaises(burrow.NotFound, list, messages) |
489 | messages = self.backend.update_messages('a', 'q', attributes) |
490 | - self.assertRaises(burrow.backend.NotFound, list, messages) |
491 | + self.assertRaises(burrow.NotFound, list, messages) |
492 | |
493 | def test_large(self): |
494 | for name in xrange(0, 1000): |
495 | @@ -467,7 +467,7 @@ |
496 | self.backend.create_message('a', 'q', 'm', 'test') |
497 | filters = dict(detail='bad') |
498 | messages = self.backend.delete_messages('a', 'q', filters) |
499 | - self.assertRaises(burrow.backend.InvalidArguments, list, messages) |
500 | + self.assertRaises(burrow.InvalidArguments, list, messages) |
501 | self.assertEquals([], list(self.backend.delete_messages('a', 'q'))) |
502 | |
503 | def test_delete_marker(self): |
504 | @@ -553,7 +553,7 @@ |
505 | self.backend.create_message('a', 'q', 'm', 'test') |
506 | filters = dict(detail='bad') |
507 | messages = self.backend.get_messages('a', 'q', filters) |
508 | - self.assertRaises(burrow.backend.InvalidArguments, list, messages) |
509 | + self.assertRaises(burrow.InvalidArguments, list, messages) |
510 | self.delete_messages() |
511 | |
512 | def test_get_marker(self): |
513 | @@ -570,7 +570,7 @@ |
514 | self.assertEquals(messages[2:], messages2) |
515 | filters = dict(marker=messages[2]['id']) |
516 | messages2 = self.backend.get_messages('a', 'q', filters) |
517 | - self.assertRaises(burrow.backend.NotFound, list, messages2) |
518 | + self.assertRaises(burrow.NotFound, list, messages2) |
519 | filters = dict(marker='unknown') |
520 | messages2 = list(self.backend.get_messages('a', 'q', filters)) |
521 | self.assertEquals(messages, messages2) |
522 | @@ -657,7 +657,7 @@ |
523 | attributes = dict(ttl=100, hide=200) |
524 | filters = dict(detail='bad') |
525 | messages = self.backend.update_messages('a', 'q', attributes, filters) |
526 | - self.assertRaises(burrow.backend.InvalidArguments, list, messages) |
527 | + self.assertRaises(burrow.InvalidArguments, list, messages) |
528 | self.delete_messages() |
529 | |
530 | def test_update_marker(self): |
531 | @@ -677,7 +677,7 @@ |
532 | self.assertEquals(messages[2:], list(messages2)) |
533 | filters.update(marker=messages[2]['id']) |
534 | messages2 = self.backend.update_messages('a', 'q', attributes, filters) |
535 | - self.assertRaises(burrow.backend.NotFound, list, messages2) |
536 | + self.assertRaises(burrow.NotFound, list, messages2) |
537 | filters = dict(detail='all', marker='unknown', match_hidden=True) |
538 | messages2 = self.backend.update_messages('a', 'q', attributes, filters) |
539 | self.assertEquals(messages, list(messages2)) |
540 | @@ -807,7 +807,7 @@ |
541 | def test_delete_detail_bad(self): |
542 | self.backend.create_message('a', 'q', 'm', 'test') |
543 | filters = dict(detail='bad') |
544 | - self.assertRaises(burrow.backend.InvalidArguments, |
545 | + self.assertRaises(burrow.InvalidArguments, |
546 | self.backend.delete_message, 'a', 'q', 'm', filters) |
547 | self.delete_messages() |
548 | |
549 | @@ -849,7 +849,7 @@ |
550 | def test_get_detail_bad(self): |
551 | self.backend.create_message('a', 'q', 'm', 'test') |
552 | filters = dict(detail='bad') |
553 | - self.assertRaises(burrow.backend.InvalidArguments, |
554 | + self.assertRaises(burrow.InvalidArguments, |
555 | self.backend.get_message, 'a', 'q', 'm', filters) |
556 | self.delete_messages() |
557 | |
558 | @@ -903,7 +903,7 @@ |
559 | self.backend.create_message('a', 'q', 'm', 'test') |
560 | attributes = dict(ttl=100, hide=200) |
561 | filters = dict(detail='bad') |
562 | - self.assertRaises(burrow.backend.InvalidArguments, |
563 | + self.assertRaises(burrow.InvalidArguments, |
564 | self.backend.update_message, 'a', 'q', 'm', attributes, filters) |
565 | self.delete_messages() |
566 | |
567 | |
568 | === modified file 'test/backend/test_http.py' |
569 | --- test/backend/test_http.py 2011-08-16 20:59:06 +0000 |
570 | +++ test/backend/test_http.py 2011-08-24 20:17:24 +0000 |
571 | @@ -15,12 +15,7 @@ |
572 | '''Unittests for the HTTP backend. This starts the WSGI server so |
573 | tests the WSGI frontend as well.''' |
574 | |
575 | -import atexit |
576 | import ConfigParser |
577 | -import os |
578 | -import signal |
579 | -import sys |
580 | -import time |
581 | |
582 | import burrow.backend.http |
583 | import test.backend |
584 | @@ -53,51 +48,3 @@ |
585 | class TestHTTPMessage(HTTPBase, test.backend.TestMessage): |
586 | '''Test case for message with http backend.''' |
587 | pass |
588 | - |
589 | - |
590 | -def start_server(): |
591 | - '''Fork and start the server, saving the pid in a file.''' |
592 | - kill_server() |
593 | - pid = os.fork() |
594 | - if pid == 0: |
595 | - try: |
596 | - import coverage |
597 | - cov = coverage.coverage(data_suffix=True) |
598 | - cov.start() |
599 | - |
600 | - def save_coverage(_signum, _frame): |
601 | - '''Callback for signal to save coverage info to file.''' |
602 | - cov.save() |
603 | - |
604 | - signal.signal(signal.SIGUSR1, save_coverage) |
605 | - except ImportError: |
606 | - pass |
607 | - server = burrow.Server(add_default_log_handler=False) |
608 | - server.frontends[0].default_ttl = 0 |
609 | - server.run() |
610 | - sys.exit(0) |
611 | - pid_file = open('TestHTTP.pid', 'w') |
612 | - pid_file.write(str(pid)) |
613 | - pid_file.close() |
614 | - atexit.register(kill_server) |
615 | - time.sleep(1) |
616 | - |
617 | - |
618 | -def kill_server(): |
619 | - '''Try killing the server if the pid file exists.''' |
620 | - try: |
621 | - pid_file = open('TestHTTP.pid', 'r') |
622 | - pid = pid_file.read() |
623 | - pid_file.close() |
624 | - try: |
625 | - os.kill(int(pid), signal.SIGUSR1) |
626 | - time.sleep(1) |
627 | - os.kill(int(pid), signal.SIGTERM) |
628 | - except OSError: |
629 | - pass |
630 | - os.unlink('TestHTTP.pid') |
631 | - except IOError: |
632 | - pass |
633 | - |
634 | - |
635 | -start_server() |
636 | |
637 | === added directory 'test/frontend' |
638 | === added file 'test/frontend/__init__.py' |
639 | --- test/frontend/__init__.py 1970-01-01 00:00:00 +0000 |
640 | +++ test/frontend/__init__.py 2011-08-24 20:17:24 +0000 |
641 | @@ -0,0 +1,15 @@ |
642 | +# Copyright (C) 2011 OpenStack LLC. |
643 | +# |
644 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
645 | +# you may not use this file except in compliance with the License. |
646 | +# You may obtain a copy of the License at |
647 | +# |
648 | +# http://www.apache.org/licenses/LICENSE-2.0 |
649 | +# |
650 | +# Unless required by applicable law or agreed to in writing, software |
651 | +# distributed under the License is distributed on an "AS IS" BASIS, |
652 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
653 | +# See the License for the specific language governing permissions and |
654 | +# limitations under the License. |
655 | + |
656 | +'''Unittests for burrow frontends.''' |
657 | |
658 | === added file 'test/frontend/test_wsgi.py' |
659 | --- test/frontend/test_wsgi.py 1970-01-01 00:00:00 +0000 |
660 | +++ test/frontend/test_wsgi.py 2011-08-24 20:17:24 +0000 |
661 | @@ -0,0 +1,45 @@ |
662 | +# Copyright (C) 2011 OpenStack LLC. |
663 | +# |
664 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
665 | +# you may not use this file except in compliance with the License. |
666 | +# You may obtain a copy of the License at |
667 | +# |
668 | +# http://www.apache.org/licenses/LICENSE-2.0 |
669 | +# |
670 | +# Unless required by applicable law or agreed to in writing, software |
671 | +# distributed under the License is distributed on an "AS IS" BASIS, |
672 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
673 | +# See the License for the specific language governing permissions and |
674 | +# limitations under the License. |
675 | + |
676 | +'''Unittests for the WSGI frontend. Most of the WSGI server is tested by |
677 | +the HTTP backend, so this covers things that don't translate directly to |
678 | +the Python API.''' |
679 | + |
680 | +import httplib |
681 | +import json |
682 | +import unittest |
683 | + |
684 | + |
685 | +class TestWSGI(unittest.TestCase): |
686 | + '''Test case for WSGI frontend.''' |
687 | + |
688 | + def test_versions(self): |
689 | + connection = httplib.HTTPConnection('localhost', 8080) |
690 | + connection.request('GET', '/') |
691 | + response = connection.getresponse() |
692 | + self.assertEquals(response.status, 200) |
693 | + body = json.loads(response.read()) |
694 | + self.assertEquals(body, ['v1.0']) |
695 | + |
696 | + def test_unknown_method(self): |
697 | + connection = httplib.HTTPConnection('localhost', 8080) |
698 | + connection.request('OPTIONS', '/v1.0') |
699 | + response = connection.getresponse() |
700 | + self.assertEquals(response.status, 405) |
701 | + |
702 | + def test_unknown_url(self): |
703 | + connection = httplib.HTTPConnection('localhost', 8080) |
704 | + connection.request('GET', '/unknown') |
705 | + response = connection.getresponse() |
706 | + self.assertEquals(response.status, 404) |
707 | |
708 | === added file 'test/test_client.py' |
709 | --- test/test_client.py 1970-01-01 00:00:00 +0000 |
710 | +++ test/test_client.py 2011-08-24 20:17:24 +0000 |
711 | @@ -0,0 +1,60 @@ |
712 | +# Copyright (C) 2011 OpenStack LLC. |
713 | +# |
714 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
715 | +# you may not use this file except in compliance with the License. |
716 | +# You may obtain a copy of the License at |
717 | +# |
718 | +# http://www.apache.org/licenses/LICENSE-2.0 |
719 | +# |
720 | +# Unless required by applicable law or agreed to in writing, software |
721 | +# distributed under the License is distributed on an "AS IS" BASIS, |
722 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
723 | +# See the License for the specific language governing permissions and |
724 | +# limitations under the License. |
725 | + |
726 | +'''Unittests for the Client API.''' |
727 | + |
728 | +import unittest |
729 | + |
730 | +import burrow |
731 | + |
732 | + |
733 | +class TestClient(unittest.TestCase): |
734 | + '''Test case for Client API.''' |
735 | + |
736 | + def test_client(self): |
737 | + client = burrow.Client() |
738 | + self.assertRaises(burrow.NotFound, list, client.get_accounts()) |
739 | + self.assertEquals(True, client.create_message('a', 'q', 'm', 'body')) |
740 | + self.assertEquals(['a'], list(client.get_accounts())) |
741 | + self.assertEquals([], list(client.delete_accounts())) |
742 | + |
743 | + def test_account(self): |
744 | + account = burrow.Account('a') |
745 | + self.assertRaises(burrow.NotFound, list, account.get_queues()) |
746 | + self.assertEquals(True, account.create_message('q', 'm', 'body')) |
747 | + self.assertEquals(['q'], list(account.get_queues())) |
748 | + self.assertEquals([], list(account.delete_accounts())) |
749 | + |
750 | + def test_queue(self): |
751 | + queue = burrow.Queue('a', 'q') |
752 | + self.assertRaises(burrow.NotFound, list, queue.get_messages()) |
753 | + self.assertEquals(True, queue.create_message('m', 'body')) |
754 | + messages = queue.get_messages(filters=dict(detail='id')) |
755 | + self.assertEquals(['m'], list(messages)) |
756 | + self.assertEquals([], list(queue.delete_accounts())) |
757 | + |
758 | + def test_url(self): |
759 | + client = burrow.Client(url='http://localhost:8080') |
760 | + self.assertRaises(burrow.NotFound, list, client.get_accounts()) |
761 | + self.assertEquals(True, client.create_message('a', 'q', 'm', 'body')) |
762 | + self.assertEquals(['a'], list(client.get_accounts())) |
763 | + self.assertEquals([], list(client.delete_accounts())) |
764 | + |
765 | + def test_shared_client(self): |
766 | + client = burrow.Client(url='http://localhost:8080') |
767 | + self.assertRaises(burrow.NotFound, list, client.get_accounts()) |
768 | + self.assertEquals(True, client.create_message('a', 'q', 'm', 'body')) |
769 | + account = burrow.Account('a', client=client) |
770 | + self.assertEquals(['q'], list(account.get_queues())) |
771 | + self.assertEquals([], list(account.delete_accounts())) |