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

« back to all changes in this revision

Viewing changes to grackle/tests/test_model.py

  • Committer: William Grant
  • Date: 2012-01-23 02:43:10 UTC
  • Revision ID: william.grant@canonical.com-20120123024310-ybh2zasa4x6lbky2
Some flexibility in formatting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from grackle.model import (
33
33
    CassandraConnection,
 
34
    FORMATS,
 
35
    _format_message,
34
36
    _parse_message,
35
37
    )
36
38
 
127
129
    def test_single_message(self):
128
130
        conn, archive = self.makeArchive()
129
131
        self.makeMessages(conn, archive, 1)
 
132
 
 
133
        # We get a single message when we ask for it.
130
134
        messages = conn.get_messages(archive, 'date', 1, '')[1]
131
135
        self.assertMessages([0], messages)
132
136
        cmsg = messages[0]
 
137
 
 
138
        # The content matches what we generated, and the result is
 
139
        # formatted according to the default settings.
133
140
        expected_content = TEMPLATE_MESSAGE.format(
134
141
            date=formatdate(0), id='<message0@example.com>')
135
142
        self.assertEqual(expected_content, messages[0]['content'])
136
143
        pmsg = _parse_message(expected_content)[1]
137
 
        self.assertEqual(pmsg['date'], cmsg['date'])
138
 
        self.assertEqual(pmsg['from'], cmsg['from'])
139
 
        self.assertEqual(pmsg['subject'], cmsg['subject'])
140
 
        self.assertEqual(pmsg['message-id'], cmsg['message-id'])
 
144
        pmsg['content'] = expected_content
 
145
        self.assertEqual(
 
146
            _format_message(
 
147
                ['date', 'from', 'subject', 'message-id', 'content'],
 
148
                pmsg),
 
149
            cmsg)
141
150
 
142
151
    def test_limit(self):
143
152
        conn, archive = self.makeArchive()
194
203
        prev, messages, next = conn.get_messages(
195
204
            archive, 'date', 2, next, start_date=start, finish_date=finish)
196
205
        self.assertMessages([5], messages)
 
206
 
 
207
 
 
208
class TestMessageFormatters(unittest.TestCase):
 
209
 
 
210
    def test_all(self):
 
211
        parsed = _parse_message(TEST_MESSAGE)[1]
 
212
        parsed['content'] = TEST_MESSAGE
 
213
        want, func = FORMATS['all'](['date', 'from', 'subject', 'message-id'])
 
214
        self.assertEqual(
 
215
            ['content', 'date', 'from', 'message-id', 'subject'],
 
216
            sorted(want))
 
217
        formatted = func(parsed)
 
218
        expected = {
 
219
            'date': '2000-01-01T11:02:34+11:00',
 
220
            'from': 'sysadmin@example.com',
 
221
            'message-id': '<aaaaaaaaaaaaa@example.com>',
 
222
            'subject': 'Everything is broken',
 
223
            'content': TEST_MESSAGE,
 
224
            }
 
225
        self.assertEqual(expected, formatted)