~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:53:38 UTC
  • Revision ID: william.grant@canonical.com-20120123025338-n6lgeh6ra8kyi8h6
Refactor formatters, push headers into a subdict.

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
34
    _format_message,
36
35
    _parse_message,
37
36
    )
108
107
    def assertMessages(self, expected_ids, messages):
109
108
        expected_msgids = [
110
109
            '<message%d@example.com>' % id for id in expected_ids]
111
 
        actual_msgids = [msg['message-id'] for msg in messages]
 
110
        actual_msgids = [msg['headers']['message-id'] for msg in messages]
112
111
        self.assertEqual(expected_msgids, actual_msgids)
113
112
 
114
113
    def makeMessages(self, conn, archive, count):
144
143
        pmsg['content'] = expected_content
145
144
        self.assertEqual(
146
145
            _format_message(
147
 
                ['date', 'from', 'subject', 'message-id', 'content'],
148
 
                pmsg),
 
146
                pmsg,
 
147
                headers=['date', 'from', 'subject', 'message-id'],
 
148
                include_raw=True),
149
149
            cmsg)
150
150
 
151
151
    def test_limit(self):
205
205
        self.assertMessages([5], messages)
206
206
 
207
207
 
208
 
class TestMessageFormatters(unittest.TestCase):
 
208
class TestMessageFormatter(unittest.TestCase):
209
209
 
210
210
    def test_all(self):
211
211
        parsed = _parse_message(TEST_MESSAGE)[1]
212
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)
 
213
        formatted = _format_message(
 
214
            parsed,
 
215
            headers=['date', 'from', 'subject', 'message-id'],
 
216
            include_raw=True)
218
217
        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',
 
218
            'headers': {
 
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
                },
223
224
            'content': TEST_MESSAGE,
224
225
            }
225
226
        self.assertEqual(expected, formatted)