13
by William Grant
Test add_message a little. |
1 |
# Copyright (c) 2012 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software: you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU Affero General Public License as published by
|
|
5 |
# the Free Software Foundation, either version 3 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU Affero General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU Affero General Public
|
|
14 |
# License along with this program. If not, see
|
|
15 |
# <http://www.gnu.org/licenses/>.
|
|
16 |
||
17 |
__metaclass__ = type |
|
18 |
||
19 |
import fixtures |
|
20 |
||
21 |
from grackle.server.testing.cassandra import TemporaryDB |
|
22 |
from grackle.server.model import CassandraConnection |
|
23 |
||
24 |
||
25 |
TEST_MESSAGE = """\ |
|
26 |
From: sysadmin@example.com
|
|
27 |
To: developer@example.com
|
|
28 |
Subject: Everything is broken
|
|
29 |
Date: Sat, 1 Jan 2000 11:02:34 +1100
|
|
30 |
Message-Id: <aaaaaaaaaaaaa@example.com>
|
|
31 |
||
32 |
Help, everything has just broken.
|
|
33 |
"""
|
|
34 |
||
35 |
||
36 |
class TestModel(fixtures.TestWithFixtures): |
|
37 |
||
38 |
def test_add_message(self): |
|
39 |
keyspace = self.useFixture(TemporaryDB()).keyspace |
|
40 |
c = CassandraConnection(keyspace, ['localhost:9160']) |
|
41 |
c.add_message('foo', TEST_MESSAGE) |
|
42 |
||
43 |
||
44 |
class TestModel(fixtures.TestWithFixtures): |
|
45 |
||
46 |
def test_add_message(self): |
|
47 |
keyspace = self.useFixture(TemporaryDB()).keyspace |
|
48 |
c = CassandraConnection(keyspace, ['localhost:9160']) |
|
49 |
key = c.add_message('foo', TEST_MESSAGE) |
|
50 |
cmsg = c.messages.get(key) |
|
51 |
self.assertEqual(TEST_MESSAGE, cmsg['content']) |
|
52 |
self.assertEqual('sysadmin@example.com', cmsg['from']) |
|
53 |
self.assertEqual('developer@example.com', cmsg['to']) |
|
54 |
self.assertEqual('Everything is broken', cmsg['subject']) |
|
55 |
self.assertEqual('2000-01-01T11:02:34+11:00', cmsg['date']) |
|
14
by William Grant
Refactor. |
56 |
self.assertEqual('<aaaaaaaaaaaaa@example.com>', cmsg['message-id']) |