~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/tests/test_client.py

  • Committer: Curtis Hovey
  • Date: 2012-03-01 01:08:15 UTC
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120301010815-hz0al69e3j0c9e6n
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
147
 
            self.end_headers()
148
 
            self.wfile.close()
149
 
        else:
150
 
            self.send_error(httplib.BAD_REQUEST)
 
142
        if parts[1] == 'archive' and len(parts) == 4:
 
143
            try:
 
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)
 
147
                self.end_headers()
 
148
                self.wfile.close()
 
149
            except:
 
150
                self.send_error(httplib.BAD_REQUEST)
151
151
 
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)
182
 
        with service:
 
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'])
188
187
 
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'))
196
194
 
197
195
 
198
196
class TestGetMessages(TestCase):