139
139
scheme, netloc, path, params, query_string, fragments = (
140
140
urlparse(self.path))
141
141
parts = path.split('/')
142
if parts[1] == 'archive':
143
# This expected path is /archive/archive_id/message_id.
144
self.server.store.put_message(parts[2], parts[3], message)
145
if message == 'This is a message':
146
self.send_response(httplib.CREATED)
150
self.send_error(httplib.BAD_REQUEST)
142
if parts[1] == 'archive' and len(parts) == 4:
144
# This expected path is /archive/archive_id/message_id.
145
self.server.store.put_message(parts[2], parts[3], message)
146
self.send_response(httplib.CREATED)
150
self.send_error(httplib.BAD_REQUEST)
152
152
def do_GET(self):
153
153
"""Retrieve a list of messages on GET."""
178
178
def test_put_message(self):
179
179
client = GrackleClient('localhost', 8420)
180
180
message_archives = {'arch1': []}
181
service = ForkedFakeService.from_client(client, message_archives)
181
with ForkedFakeService.from_client(client, message_archives):
183
182
client.put_message('arch1', 'id1', StringIO('This is a message'))
184
183
response = client.get_messages('arch1')
185
self.assertEqual(1, len(response['messages']))
186
message = response['messages'][0]
187
self.assertEqual('id1', message['message_id'])
184
self.assertEqual(1, len(response['messages']))
185
message = response['messages'][0]
186
self.assertEqual('id1', message['message_id'])
189
def test_put_message_without_message(self):
188
def test_put_message_without_archive(self):
190
189
client = GrackleClient('localhost', 8421)
191
190
message_archives = {'arch1': []}
192
191
with ForkedFakeService.from_client(client, message_archives):
193
192
with ExpectedException(Exception, 'wtf'):
194
client.put_message('arch1', 'id1',
195
StringIO('This is not a message'))
193
client.put_message('no-archive', 'id1', StringIO('message'))
198
196
class TestGetMessages(TestCase):