3
3
BaseHTTPRequestHandler,
6
from signal import SIGKILL
7
7
from StringIO import StringIO
8
8
from unittest import TestCase
10
from testtools import ExpectedException
10
12
from grackle import client
13
def fake_grackle_service():
17
service = HTTPServer(('', 8435), BaseHTTPRequestHandler)
18
service.handle_request()
17
def __init__(self, func_or_method):
18
self.func_or_method = func_or_method
29
def __exit__(self, exc_type, exc_val, traceback):
30
os.kill(self.pid, SIGKILL)
33
class FakeGrackleRequestHandler(BaseHTTPRequestHandler):
36
message = self.rfile.read(int(self.headers['content-length']))
37
if message == 'This is a message':
38
self.send_response(200)
46
service = HTTPServer(('', 8435), FakeGrackleRequestHandler)
47
service.serve_forever()
22
51
class TestPutMessage(TestCase):
24
53
def test_put_message(self):
25
service = fake_grackle_service()
26
client.put_message('arch1', StringIO('This is a message'))
54
with Forked(run_service):
55
client.put_message('arch1', StringIO('This is a message'))
56
with ExpectedException(Exception, 'wtf'):
57
client.put_message('arch1', StringIO('This is not a message'))