133
134
self.logger = logging.getLogger('http')
134
135
BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
138
"""Create an archive or message on PUT."""
139
scheme, netloc, path, params, query_string, fragments = (
141
parts = path.split('/')
142
if parts[1] != 'archive':
143
# This is an unknonwn operation?
146
# This expected path is /archive/archive_id.
148
self.server.store.put_archive(parts[2])
149
self.send_response(httplib.CREATED)
152
except Exception, error:
154
httplib.BAD_REQUEST, error.__doc__)
156
# This expected path is /archive/archive_id/message_id.
158
message = self.rfile.read(int(self.headers['content-length']))
159
self.server.store.put_message(parts[2], parts[3], message)
160
self.send_response(httplib.CREATED)
164
self.send_error(httplib.BAD_REQUEST)
136
166
def do_POST(self):
137
"""Create a message on POST."""
167
"""Change a message on POST."""
138
168
scheme, netloc, path, params, query_string, fragments = (
139
169
urlparse(self.path))
140
170
parts = path.split('/')
141
171
if parts[1] != 'archive':
142
172
# This is an unknonwn operation?
144
if 'content-length' in self.headers:
145
operation = 'put_message'
147
operation = 'hide_message'
148
if operation == 'put_message':
149
message = self.rfile.read(int(self.headers['content-length']))
151
# This expected path is /archive/archive_id/message_id.
152
self.server.store.put_message(parts[2], parts[3], message)
153
self.send_response(httplib.CREATED)
157
self.send_error(httplib.BAD_REQUEST)
158
elif operation == 'hide_message':
175
# This expected path is /archive/archive_id/message_id.
160
177
# This expected path is /archive/archive_id/message_id.
161
178
response = self.server.store.hide_message(
190
207
self.logger.info(message)
210
class TestPutArchive(TestCase):
212
def test_put_archive(self):
213
client = GrackleClient('localhost', 8410)
214
message_archives = {}
215
with ForkedFakeService.from_client(client, message_archives):
216
client.put_archive('arch1')
217
response = client.get_messages('arch1')
218
self.assertEqual(0, len(response['messages']))
220
def test_put_archive_existing_archive(self):
221
client = GrackleClient('localhost', 8411)
222
message_archives = {'arch1': []}
223
with ForkedFakeService.from_client(client, message_archives):
224
with ExpectedException(ArchiveIdExists, ''):
225
client.put_archive('arch1')
193
228
class TestPutMessage(TestCase):
195
230
def test_put_message(self):