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

« back to all changes in this revision

Viewing changes to grackle/server/tests/test_model.py

  • Committer: William Grant
  • Date: 2012-01-22 10:34:09 UTC
  • Revision ID: william.grant@canonical.com-20120122103409-f5fpezqgxkqu7eeq
Creating a keyspace and schema for each test (or even test run) is too slow -- it takes about 2s. Instead use a random archivename.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
__metaclass__ = type
18
18
 
19
19
import datetime
 
20
import os
 
21
from tempfile import _RandomNameSequence
20
22
import time
21
23
import unittest
22
24
 
27
29
import fixtures
28
30
from pycassa.util import convert_uuid_to_time
29
31
 
30
 
from grackle.server.testing.cassandra import TemporaryDB
31
32
from grackle.server.model import (
32
33
    CassandraConnection,
33
34
    _parse_message,
65
66
class TestCassandra(fixtures.TestWithFixtures):
66
67
 
67
68
    def test_add_message(self):
68
 
        keyspace = self.useFixture(TemporaryDB()).keyspace
69
 
        c = CassandraConnection(keyspace, ['localhost:9160'])
 
69
        c = CassandraConnection(
 
70
            os.environ['GRACKLE_TEST_KEYSPACE'], ['localhost:9160'])
 
71
 
 
72
        archive = next(_RandomNameSequence())
70
73
 
71
74
        # Write the message out to Cassandra, and read it back in.
72
 
        key = c.add_message('foo', TEST_MESSAGE)
 
75
        key = c.add_message(archive, TEST_MESSAGE)
73
76
        cmsg = c.messages.get(key)
74
77
 
75
78
        # The archive should contain a single message, a reference to
76
79
        # our new key.
77
 
        archive_messages = c.archive_messages.get('foo').items()
 
80
        archive_messages = c.archive_messages.get(archive).items()
78
81
        self.assertEqual(1, len(archive_messages))
79
82
        self.assertEqual(key, archive_messages[0][1])
80
83