~didrocks/unity/altf10

70 by Curtis Hovey
Clean up python-oddities.
1
__metaclass__ = type
2
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
3
from email.message import Message
4
from email.mime.multipart import MIMEMultipart
5
from email.mime.text import MIMEText
4 by Aaron Bentley
Initial test.
6
from StringIO import StringIO
3 by Aaron Bentley
Add test framework.
7
from unittest import TestCase
8
5 by Aaron Bentley
Actual fake service working.
9
from testtools import ExpectedException
10
58 by Curtis Hovey
Raise an error when the archive already exists.
11
from grackle.client import GrackleClient
12
from grackle.error import (
13
    ArchiveIdExists,
38 by Curtis Hovey
Added basic handling of date_range.
14
    UnparsableDateRange,
35.1.4 by Curtis Hovey
Added SUPPORTED_DISPLAY_TYPES.
15
    UnsupportedDisplayType,
21 by Aaron Bentley
Test unsupported orders.
16
    UnsupportedOrder,
8 by Aaron Bentley
Test message path.
17
    )
60 by Curtis Hovey
Converted gracle from a request handler to a wsgi app.
18
from grackle.service import ForkedFakeService
70 by Curtis Hovey
Clean up python-oddities.
19
from grackle.store import make_json_message
4 by Aaron Bentley
Initial test.
20
21
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
22
def make_message(message_id, body='body', headers=None, hidden=False):
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
23
    if headers is None:
24
        headers = {}
51 by Curtis Hovey
Always use an rfc822 message in tests.
25
    message_headers = {
26
        'Message-Id': message_id,
27
        'date': '2005-01-01',
28
        'subject': 'subject',
29
        'from': 'author',
30
        'replies': '',
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
31
        }
51 by Curtis Hovey
Always use an rfc822 message in tests.
32
    message_headers.update(headers.items())
33
    message = Message()
34
    message.set_payload(body)
35
    for key, value in message_headers.items():
36
        message[key] = value
37
    return make_json_message(message_id, message.as_string(), hidden)
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
38
39
35.1.16 by Curtis Hovey
make_mime_message calls to make_message.
40
def make_mime_message(message_id, body='body', headers=None, hidden=False,
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
41
                      attachment_type=None):
49 by Curtis Hovey
Make an rfc822 message with a mime payload.
42
    parts = MIMEMultipart()
43
    parts.attach(MIMEText(body))
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
44
    if attachment_type is not None:
45
        attachment = Message()
46
        attachment.set_payload('attactment data.')
47
        attachment['Content-Type'] = attachment_type
35.1.16 by Curtis Hovey
make_mime_message calls to make_message.
48
        attachment['Content-Disposition'] = 'attachment; filename="file.ext"'
49 by Curtis Hovey
Make an rfc822 message with a mime payload.
49
        parts.attach(attachment)
51 by Curtis Hovey
Always use an rfc822 message in tests.
50
    return make_message(message_id, parts.as_string(), headers, hidden)
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
51
52
57 by Curtis Hovey
Added a rudimentary put_archive.
53
class TestPutArchive(TestCase):
54
58 by Curtis Hovey
Raise an error when the archive already exists.
55
    def test_put_archive(self):
57 by Curtis Hovey
Added a rudimentary put_archive.
56
        client = GrackleClient('localhost', 8410)
57
        message_archives = {}
58
        with ForkedFakeService.from_client(client, message_archives):
59
            client.put_archive('arch1')
60
            response = client.get_messages('arch1')
61
        self.assertEqual(0, len(response['messages']))
62
58 by Curtis Hovey
Raise an error when the archive already exists.
63
    def test_put_archive_existing_archive(self):
64
        client = GrackleClient('localhost', 8411)
65
        message_archives = {'arch1': []}
66
        with ForkedFakeService.from_client(client, message_archives):
67
            with ExpectedException(ArchiveIdExists, ''):
68
                client.put_archive('arch1')
69
57 by Curtis Hovey
Added a rudimentary put_archive.
70
3 by Aaron Bentley
Add test framework.
71
class TestPutMessage(TestCase):
72
73
    def test_put_message(self):
42 by Curtis Hovey
Separate gracle MemoryStore to its own module.
74
        client = GrackleClient('localhost', 8420)
46 by Curtis Hovey
Implemented a partial put into the MemoryStore.
75
        message_archives = {'arch1': []}
47 by Curtis Hovey
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.
76
        with ForkedFakeService.from_client(client, message_archives):
46 by Curtis Hovey
Implemented a partial put into the MemoryStore.
77
            client.put_message('arch1', 'id1', StringIO('This is a message'))
78
            response = client.get_messages('arch1')
47 by Curtis Hovey
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.
79
        self.assertEqual(1, len(response['messages']))
80
        message = response['messages'][0]
81
        self.assertEqual('id1', message['message_id'])
46 by Curtis Hovey
Implemented a partial put into the MemoryStore.
82
47 by Curtis Hovey
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.
83
    def test_put_message_without_archive(self):
46 by Curtis Hovey
Implemented a partial put into the MemoryStore.
84
        client = GrackleClient('localhost', 8421)
85
        message_archives = {'arch1': []}
86
        with ForkedFakeService.from_client(client, message_archives):
5 by Aaron Bentley
Actual fake service working.
87
            with ExpectedException(Exception, 'wtf'):
47 by Curtis Hovey
Raise ArchiveIdNotFound if the client puts a message into an unknown archive.
88
                client.put_message('no-archive', 'id1', StringIO('message'))
11 by Aaron Bentley
Start working on GET.
89
90
91
class TestGetMessages(TestCase):
92
20 by Aaron Bentley
Support order by date
93
    def assertIDOrder(self, ids, messages):
94
        self.assertEqual(ids, [m['message_id'] for m in messages])
95
19 by Aaron Bentley
Implement memo/limit support.
96
    def assertMessageIDs(self, ids, messages):
20 by Aaron Bentley
Support order by date
97
        self.assertIDOrder(
35.1.1 by Curtis Hovey
Hush lint.
98
            sorted(ids), sorted(messages, key=lambda m: m['message_id']))
19 by Aaron Bentley
Implement memo/limit support.
99
11 by Aaron Bentley
Start working on GET.
100
    def test_get_messages(self):
42 by Curtis Hovey
Separate gracle MemoryStore to its own module.
101
        client = GrackleClient('localhost', 8430)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
102
        archive = {
103
            'baz': [make_message('foo'), make_message('bar')]}
104
        with ForkedFakeService.from_client(client, archive):
15 by Aaron Bentley
Test filtering by message-id.
105
            response = client.get_messages('baz')
17 by Aaron Bentley
Switch hyphens to underscores.
106
        self.assertEqual(['bar', 'foo'], sorted(m['message_id'] for m in
16 by Aaron Bentley
Include next_memo, previous_memo in get_messages response.
107
            response['messages']))
108
        self.assertIs(None, response['next_memo'])
109
        self.assertIs(None, response['previous_memo'])
15 by Aaron Bentley
Test filtering by message-id.
110
111
    def test_get_messages_by_id(self):
112
        client = GrackleClient('localhost', 8437)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
113
        archive = {
114
            'baz': [make_message('foo'), make_message('bar')]}
115
        with ForkedFakeService.from_client(client, archive):
16 by Aaron Bentley
Include next_memo, previous_memo in get_messages response.
116
            response = client.get_messages('baz', message_ids=['foo'])
117
        message, = response['messages']
17 by Aaron Bentley
Switch hyphens to underscores.
118
        self.assertEqual('foo', message['message_id'])
19 by Aaron Bentley
Implement memo/limit support.
119
120
    def test_get_messages_batching(self):
20 by Aaron Bentley
Support order by date
121
        client = GrackleClient('localhost', 8438)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
122
        archive = {'baz': [make_message('foo'), make_message('bar')]}
123
        with ForkedFakeService.from_client(client, archive):
19 by Aaron Bentley
Implement memo/limit support.
124
            response = client.get_messages('baz', limit=1)
125
            self.assertEqual(1, len(response['messages']))
126
            messages = response['messages']
127
            response = client.get_messages(
128
                'baz', limit=1, memo=response['next_memo'])
129
            self.assertEqual(1, len(response['messages']))
130
            messages.extend(response['messages'])
131
            self.assertMessageIDs(['foo', 'bar'], messages)
20 by Aaron Bentley
Support order by date
132
22 by Aaron Bentley
Order by thread subject.
133
    def get_messages_member_order_test(self, key):
20 by Aaron Bentley
Support order by date
134
        client = GrackleClient('localhost', 8439)
51 by Curtis Hovey
Always use an rfc822 message in tests.
135
        if key == 'author':
136
            header_name = 'from'
137
        else:
138
            header_name = key
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
139
        archive = {
140
            'baz': [
51 by Curtis Hovey
Always use an rfc822 message in tests.
141
                make_message('foo', headers={header_name: '2011-03-25'}),
142
                make_message('bar', headers={header_name: '2011-03-24'}),
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
143
             ]}
144
        with ForkedFakeService.from_client(client, archive):
20 by Aaron Bentley
Support order by date
145
            response = client.get_messages('baz')
146
            self.assertIDOrder(['foo', 'bar'], response['messages'])
22 by Aaron Bentley
Order by thread subject.
147
            response = client.get_messages('baz', order=key)
20 by Aaron Bentley
Support order by date
148
            self.assertIDOrder(['bar', 'foo'], response['messages'])
21 by Aaron Bentley
Test unsupported orders.
149
22 by Aaron Bentley
Order by thread subject.
150
    def test_get_messages_date_order(self):
151
        self.get_messages_member_order_test('date')
152
153
    def test_get_messages_author_order(self):
154
        self.get_messages_member_order_test('author')
155
156
    def test_get_messages_subject_order(self):
157
        self.get_messages_member_order_test('subject')
158
159
    def test_get_messages_thread_subject_order(self):
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
160
        archive = {
161
            'baz': [
162
                make_message('bar', headers={'subject': 'y'}),
163
                make_message('qux', headers={'subject': 'z'}),
164
                make_message('foo', headers={'subject': 'x',
165
                                             'in-reply-to': 'qux'}),
166
             ]}
22 by Aaron Bentley
Order by thread subject.
167
        client = GrackleClient('localhost', 8439)
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
168
        with ForkedFakeService.from_client(client, archive):
22 by Aaron Bentley
Order by thread subject.
169
            response = client.get_messages('baz')
170
            self.assertIDOrder(['bar', 'qux', 'foo'], response['messages'])
171
            response = client.get_messages('baz', order='subject')
172
            self.assertIDOrder(['foo', 'bar', 'qux'], response['messages'])
173
            response = client.get_messages('baz', order='thread_subject')
174
            self.assertIDOrder(['bar', 'qux', 'foo'], response['messages'])
175
23 by Aaron Bentley
Support thread_oldest order.
176
    def test_get_messages_thread_oldest_order(self):
177
        client = GrackleClient('localhost', 8439)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
178
        archive = {
179
            'baz': [
180
                make_message('bar', headers={'date': 'x'}),
181
                make_message('qux', headers={'date': 'z'}),
182
                make_message('foo', headers={'date': 'y',
183
                                             'in-reply-to': 'qux'}),
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
184
            ]}
185
        with ForkedFakeService.from_client(client, archive):
23 by Aaron Bentley
Support thread_oldest order.
186
            response = client.get_messages('baz')
187
            self.assertIDOrder(['bar', 'qux', 'foo'], response['messages'])
188
            response = client.get_messages('baz', order='date')
189
            self.assertIDOrder(['bar', 'foo', 'qux'], response['messages'])
190
            response = client.get_messages('baz', order='thread_oldest')
191
            self.assertIDOrder(['bar', 'qux', 'foo'], response['messages'])
192
24 by Aaron Bentley
Support thread_newest threading.
193
    def test_get_messages_thread_newest_order(self):
194
        client = GrackleClient('localhost', 8439)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
195
        archive = {
196
            'baz': [
197
                make_message('bar', headers={'date': 'x'}),
198
                make_message('qux', headers={'date': 'w'}),
199
                make_message('foo', headers={'date': 'y',
200
                                             'in-reply-to': 'bar'}),
201
                make_message('baz', headers={'date': 'z',
202
                                             'in-reply-to': 'qux'}),
203
            ]}
204
        with ForkedFakeService.from_client(client, archive):
24 by Aaron Bentley
Support thread_newest threading.
205
            response = client.get_messages('baz', order='date')
206
            self.assertIDOrder(
207
                ['qux', 'bar', 'foo', 'baz'], response['messages'])
208
            response = client.get_messages('baz', order='thread_newest')
209
            self.assertIDOrder(
210
                ['bar', 'foo', 'qux', 'baz'], response['messages'])
211
21 by Aaron Bentley
Test unsupported orders.
212
    def test_get_messages_unsupported_order(self):
213
        client = GrackleClient('localhost', 8439)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
214
        archive = {
215
            'baz': [
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
216
                make_message('foo', headers={'date': '2011-03-25'}),
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
217
                make_message('foo', headers={'date': '2011-03-24'}),
218
            ]}
219
        with ForkedFakeService.from_client(client, archive):
35 by William Grant
Fix test.
220
            with ExpectedException(UnsupportedOrder, ''):
21 by Aaron Bentley
Test unsupported orders.
221
                client.get_messages('baz', order='nonsense')
27 by Aaron Bentley
get_messages supports header parameter.
222
223
    def test_get_messages_headers_no_headers(self):
224
        client = GrackleClient('localhost', 8440)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
225
        archive = {'baz': [make_message('foo')]}
226
        with ForkedFakeService.from_client(client, archive):
27 by Aaron Bentley
get_messages supports header parameter.
227
            response = client.get_messages('baz', headers=[
228
                'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
229
        first_message = response['messages'][0]
230
        self.assertEqual('foo', first_message['message_id'])
231
        self.assertEqual({}, first_message['headers'])
232
233
    def test_get_messages_headers_exclude_headers(self):
29 by Aaron Bentley
implement include_hidden.
234
        client = GrackleClient('localhost', 8441)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
235
        archive = {
236
            'baz': [make_message('foo', headers={'From': 'me'})]}
237
        with ForkedFakeService.from_client(client, archive):
27 by Aaron Bentley
get_messages supports header parameter.
238
            response = client.get_messages('baz', headers=[
239
                'Subject', 'Date', 'X-Launchpad-Message-Rationale'])
240
        first_message = response['messages'][0]
241
        self.assertEqual('foo', first_message['message_id'])
242
        self.assertEqual({}, first_message['headers'])
243
244
    def test_get_messages_headers_include_headers(self):
29 by Aaron Bentley
implement include_hidden.
245
        client = GrackleClient('localhost', 8442)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
246
        archive = {
247
            'baz': [
248
                make_message('foo', headers={'From': 'me', 'To': 'you'})]}
249
        with ForkedFakeService.from_client(client, archive):
27 by Aaron Bentley
get_messages supports header parameter.
250
            response = client.get_messages('baz', headers=[
251
                'From', 'To'])
252
        first_message = response['messages'][0]
253
        self.assertEqual('foo', first_message['message_id'])
254
        self.assertEqual({'From': 'me', 'To': 'you'}, first_message['headers'])
28 by Aaron Bentley
Extract GrackleStore.
255
256
    def test_get_messages_max_body_length(self):
29 by Aaron Bentley
implement include_hidden.
257
        client = GrackleClient('localhost', 8443)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
258
        archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
259
        with ForkedFakeService.from_client(client, archive):
28 by Aaron Bentley
Extract GrackleStore.
260
            response = client.get_messages('baz', max_body_length=3)
261
        first_message = response['messages'][0]
262
        self.assertEqual('abc', first_message['body'])
263
29 by Aaron Bentley
implement include_hidden.
264
    def test_include_hidden(self):
265
        client = GrackleClient('localhost', 8444)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
266
        archive = {
267
            'baz': [
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
268
                make_message('foo', hidden=True),
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
269
                make_message('bar', hidden=False),
270
            ]}
271
        with ForkedFakeService.from_client(client, archive):
29 by Aaron Bentley
implement include_hidden.
272
            response = client.get_messages('baz', include_hidden=True)
273
            self.assertMessageIDs(['bar', 'foo'], response['messages'])
274
            response = client.get_messages('baz', include_hidden=False)
275
            self.assertMessageIDs(['bar'], response['messages'])
35.1.4 by Curtis Hovey
Added SUPPORTED_DISPLAY_TYPES.
276
277
    def test_display_type_unknown_value(self):
35.1.5 by Curtis Hovey
Moved the display_type arg.
278
        client = GrackleClient('localhost', 8445)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
279
        archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
280
        with ForkedFakeService.from_client(client, archive):
35.1.4 by Curtis Hovey
Added SUPPORTED_DISPLAY_TYPES.
281
            with ExpectedException(UnsupportedDisplayType, ''):
282
                client.get_messages('baz', display_type='unknown')
35.1.6 by Curtis Hovey
Added display_type == 'headers-only' support.
283
284
    def test_display_type_headers_only(self):
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
285
        client = GrackleClient('localhost', 8446)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
286
        archive = {
287
            'baz': [
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
288
                make_message('foo', body=u'abcdefghi',
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
289
                             headers={'From': 'me', 'To': 'you'})]}
290
        with ForkedFakeService.from_client(client, archive):
35.1.6 by Curtis Hovey
Added display_type == 'headers-only' support.
291
            response = client.get_messages('baz', display_type='headers-only')
292
        first_message = response['messages'][0]
293
        self.assertEqual('foo', first_message['message_id'])
35.1.13 by Curtis Hovey
Use make_message() to make test data consistent.
294
        self.assertEqual(
51 by Curtis Hovey
Always use an rfc822 message in tests.
295
            archive['baz'][0]['headers'], first_message['headers'])
35.1.6 by Curtis Hovey
Added display_type == 'headers-only' support.
296
        self.assertNotIn('body', first_message)
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
297
298
    def test_display_type_text_only(self):
299
        client = GrackleClient('localhost', 8446)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
300
        archive = {
301
            'baz': [
35.1.12 by Curtis Hovey
Renamed make_message => make_mime_message.
302
                make_mime_message(
35.1.11 by Curtis Hovey
Reanme make_json_message => make_message.
303
                    'foo', 'abcdefghi',
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
304
                    headers={'From': 'me', 'To': 'you'},
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
305
                    attachment_type='text/x-diff')]}
306
        with ForkedFakeService.from_client(client, archive):
35.1.9 by Curtis Hovey
Added support for display_type == 'text-only'.
307
            response = client.get_messages('baz', display_type='text-only')
308
        first_message = response['messages'][0]
309
        self.assertEqual('foo', first_message['message_id'])
310
        self.assertEqual('me', first_message['headers']['From'])
311
        self.assertEqual('you', first_message['headers']['To'])
48 by Curtis Hovey
Use a real rfc822 message for mime testing.
312
        self.assertEqual(archive['baz'][0]['body'], first_message['body'])
35.1.10 by Curtis Hovey
Added support for display_type == 'all'.
313
314
    def test_display_type_all(self):
315
        client = GrackleClient('localhost', 8447)
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
316
        archive = {
317
            'baz': [
35.1.12 by Curtis Hovey
Renamed make_message => make_mime_message.
318
                make_mime_message(
35.1.11 by Curtis Hovey
Reanme make_json_message => make_message.
319
                    'foo', 'abcdefghi',
35.1.10 by Curtis Hovey
Added support for display_type == 'all'.
320
                    headers={'From': 'me', 'To': 'you'},
35.1.14 by Curtis Hovey
Create the archive outside of the call to create the server.
321
                    attachment_type='text/x-diff')]}
322
        with ForkedFakeService.from_client(client, archive):
35.1.10 by Curtis Hovey
Added support for display_type == 'all'.
323
            response = client.get_messages('baz', display_type='all')
324
        first_message = response['messages'][0]
325
        self.assertEqual('foo', first_message['message_id'])
326
        self.assertEqual('me', first_message['headers']['From'])
327
        self.assertEqual('you', first_message['headers']['To'])
48 by Curtis Hovey
Use a real rfc822 message for mime testing.
328
        self.assertEqual(archive['baz'][0]['body'], first_message['body'])
38 by Curtis Hovey
Added basic handling of date_range.
329
330
    def test_date_range(self):
331
        client = GrackleClient('localhost', 8448)
332
        archive = {
333
            'baz': [
334
                make_mime_message(
335
                    'foo', 'abcdefghi', headers={'date': '2011-12-31'}),
336
                make_mime_message(
337
                    'bar', 'abcdefghi', headers={'date': '2012-01-01'}),
338
                make_mime_message(
339
                    'qux', 'abcdefghi', headers={'date': '2012-01-15'}),
340
                make_mime_message(
341
                    'naf', 'abcdefghi', headers={'date': '2012-01-31'}),
342
                make_mime_message(
343
                    'doh', 'abcdefghi', headers={'date': '2012-02-01'}),
344
                    ]}
345
        with ForkedFakeService.from_client(client, archive):
346
            response = client.get_messages(
347
                'baz', date_range='2012-01-01..2012-01-31')
348
        ids = sorted(m['message_id'] for m in response['messages'])
349
        self.assertEqual(['bar', 'naf', 'qux'], ids)
39 by Curtis Hovey
Raise UnparsableDateRange when the date cannot be parsed.
350
351
    def test_date_range_unparsabledaterange(self):
41 by Curtis Hovey
Added test for extra data argument.
352
        client = GrackleClient('localhost', 8449)
39 by Curtis Hovey
Raise UnparsableDateRange when the date cannot be parsed.
353
        archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
354
        with ForkedFakeService.from_client(client, archive):
355
            with ExpectedException(UnparsableDateRange, ''):
356
                client.get_messages('baz', date_range='2012-01-01')
40 by Curtis Hovey
Dates must be a value.
357
358
    def test_date_range_unparsabledaterange_missing_part(self):
41 by Curtis Hovey
Added test for extra data argument.
359
        client = GrackleClient('localhost', 8450)
40 by Curtis Hovey
Dates must be a value.
360
        archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
361
        with ForkedFakeService.from_client(client, archive):
362
            with ExpectedException(UnparsableDateRange, ''):
363
                client.get_messages('baz', date_range='2012-01-01..')
41 by Curtis Hovey
Added test for extra data argument.
364
365
    def test_date_range_unparsabledaterange_extra_part(self):
366
        client = GrackleClient('localhost', 8451)
367
        archive = {'baz': [make_message('foo', body=u'abcdefghi')]}
368
        with ForkedFakeService.from_client(client, archive):
369
            with ExpectedException(UnparsableDateRange, ''):
370
                client.get_messages('baz', date_range='2012-01..12-02..12-03')
52 by Curtis Hovey
Added support for hide_message.
371
372
373
class TestHideMessages(TestCase):
374
375
    def test_hide_message_true(self):
376
        client = GrackleClient('localhost', 8470)
377
        archive = {
378
            'baz': [
379
                make_message('foo', hidden=False),
380
            ]}
381
        with ForkedFakeService.from_client(client, archive):
382
            response = client.hide_message('baz', 'foo', hidden=True)
383
        self.assertEqual('foo', response['message_id'])
384
        self.assertIs(True, response['hidden'])
385
386
    def test_hide_message_false(self):
387
        client = GrackleClient('localhost', 8470)
388
        archive = {
389
            'baz': [
390
                make_message('foo', hidden=True),
391
            ]}
392
        with ForkedFakeService.from_client(client, archive):
393
            response = client.hide_message('baz', 'foo', hidden=False)
394
        self.assertEqual('foo', response['message_id'])
395
        self.assertIs(False, response['hidden'])