def setUp(self): self.factory = ManagedCassandraClientFactory() self.client = CassandraClient(self.factory, KEYSPACE) self.conns = [] for i in xrange(CONNS): conn = reactor.connectTCP(HOST, PORT, self.factory) self.conns.append(conn)
class CassandraClientTest(unittest.TestCase): def setUp(self): self.factory = ManagedCassandraClientFactory() self.client = CassandraClient(self.factory, KEYSPACE) self.conns = [] for i in xrange(CONNS): conn = reactor.connectTCP(HOST, PORT, self.factory) self.conns.append(conn) @defer.inlineCallbacks def tearDown(self): yield self.client.remove('test', CF) yield self.client.remove('test2', CF) yield self.client.remove('test', SCF) yield self.client.remove('test2', SCF) self.factory.shutDown() for conn in self.conns: yield conn.disconnect() @defer.inlineCallbacks def test_insert_get(self): yield self.client.insert('test', ColumnPath(CF, None, COLUMN), 'testval') yield self.client.insert('test2', CF, 'testval2', column=COLUMN) yield self.client.insert('test', ColumnPath(SCF, SCOLUMN, COLUMN), 'superval') yield self.client.insert('test2', SCF, 'superval2', column=COLUMN, super_column=SCOLUMN) res = yield self.client.get('test', CF, column=COLUMN) self.assertEqual(res.column.value, 'testval') res = yield self.client.get('test2', CF, column=COLUMN) self.assertEqual(res.column.value, 'testval2') res = yield self.client.get('test', SCF, column=COLUMN, super_column=SCOLUMN) self.assertEqual(res.column.value, 'superval') res = yield self.client.get('test2', SCF, column=COLUMN, super_column=SCOLUMN) self.assertEqual(res.column.value, 'superval2') @defer.inlineCallbacks def test_batch_insert_get_slice_and_count(self): yield self.client.batch_insert('test', CF, {COLUMN: 'test', COLUMN2: 'test2'}) yield self.client.batch_insert('test', SCF, {SCOLUMN: {COLUMN: 'test', COLUMN2: 'test2'}}) res = yield self.client.get_slice('test', CF, names=(COLUMN, COLUMN2)) self.assertEqual(res[0].column.value, 'test') self.assertEqual(res[1].column.value, 'test2') res = yield self.client.get_slice('test', SCF, names=(COLUMN, COLUMN2), super_column=SCOLUMN) self.assertEqual(res[0].column.value, 'test') self.assertEqual(res[1].column.value, 'test2') res = yield self.client.get_count('test', CF) self.assertEqual(res, 2) @defer.inlineCallbacks def test_multiget_slice_remove(self): yield self.client.insert('test', CF, 'testval', column=COLUMN) yield self.client.insert('test', CF, 'testval', column=COLUMN2) yield self.client.insert('test2', CF, 'testval2', column=COLUMN) res = yield self.client.multiget(['test', 'test2'], CF, column=COLUMN) self.assertEqual(res['test'].column.value, 'testval') self.assertEqual(res['test2'].column.value, 'testval2') res = yield self.client.multiget_slice(['test', 'test2'], CF) self.assertEqual(res['test'][0].column.value, 'testval') self.assertEqual(res['test'][1].column.value, 'testval') self.assertEqual(res['test2'][0].column.value, 'testval2') yield self.client.remove('test', CF, column=COLUMN) yield self.client.remove('test2', CF, column=COLUMN) res = yield self.client.multiget(['test', 'test2'], CF, column=COLUMN) self.assertEqual(res['test'].column, None) self.assertEqual(res['test2'].column, None)