36
class TestModel(fixtures.TestWithFixtures):
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)
44
class TestModel(fixtures.TestWithFixtures):
46
def test_add_message(self):
47
keyspace = self.useFixture(TemporaryDB()).keyspace
48
c = CassandraConnection(keyspace, ['localhost:9160'])
48
class TestParseMessage(unittest.TestCase):
51
# _parse_message extracts interesting fields. It also parses the
52
# date and returns it separately.
53
date, msg = _parse_message(TEST_MESSAGE)
54
self.assertEqual('sysadmin@example.com', msg['from'])
55
self.assertEqual('developer@example.com', msg['to'])
56
self.assertEqual('Everything is broken', msg['subject'])
57
self.assertEqual('2000-01-01T11:02:34+11:00', msg['date'])
58
self.assertEqual('<aaaaaaaaaaaaa@example.com>', msg['message-id'])
61
2000, 1, 1, 11, 2, 34, tzinfo=tzoffset('', 39600)),
65
class TestCassandra(fixtures.TestWithFixtures):
67
def test_add_message(self):
68
keyspace = self.useFixture(TemporaryDB()).keyspace
69
c = CassandraConnection(keyspace, ['localhost:9160'])
71
# Write the message out to Cassandra, and read it back in.
49
72
key = c.add_message('foo', TEST_MESSAGE)
50
73
cmsg = c.messages.get(key)
75
# The archive should contain a single message, a reference to
77
archive_messages = c.archive_messages.get('foo').items()
78
self.assertEqual(1, len(archive_messages))
79
self.assertEqual(key, archive_messages[0][1])
81
# The key in archive_message is a TimeUUID for the Date field in
83
utctime = time.mktime(datetime.datetime(
84
2000, 1, 1, 0, 2, 34, tzinfo=tzutc()).timetuple())
87
convert_uuid_to_time(archive_messages[0][0]))
89
# The stored message contains the full original text of the
90
# message, as well as interesting fields parsed out.
51
91
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'])
56
self.assertEqual('<aaaaaaaaaaaaa@example.com>', cmsg['message-id'])
92
parsed_message = _parse_message(TEST_MESSAGE)[1]
93
for key, value in parsed_message.iteritems():
94
self.assertEqual(value, cmsg[key])