1
from BaseHTTPServer import (
3
BaseHTTPRequestHandler,
6
from signal import SIGKILL
7
from StringIO import StringIO
8
1
from unittest import TestCase
10
from testtools import ExpectedException
12
from grackle import client
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()
51
3
class TestPutMessage(TestCase):
53
5
def test_put_message(self):
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'))