1
from BaseHTTPServer import (
3
BaseHTTPRequestHandler,
7
from signal import SIGKILL
8
from StringIO import StringIO
9
from unittest import TestCase
11
from testtools import ExpectedException
13
from grackle import client
18
def __init__(self, func_or_method):
19
self.func_or_method = func_or_method
30
def __exit__(self, exc_type, exc_val, traceback):
31
os.kill(self.pid, SIGKILL)
34
class FakeGrackleRequestHandler(BaseHTTPRequestHandler):
37
message = self.rfile.read(int(self.headers['content-length']))
38
if message == 'This is a message':
39
self.send_response(httplib.CREATED)
43
self.send_error(httplib.BAD_REQUEST)
47
service = HTTPServer(('', 8435), FakeGrackleRequestHandler)
48
service.serve_forever()
52
class TestPutMessage(TestCase):
54
def test_put_message(self):
55
with Forked(run_service):
56
client.put_message('arch1', StringIO('This is a message'))
57
with ExpectedException(Exception, 'wtf'):
58
client.put_message('arch1', StringIO('This is not a message'))