def test_clone(self): pk = Key(keyspace='eggs', key='spam', column_family='bacon') ppkk = pk.clone() self.assert_(isinstance(ppkk, Key)) self.assert_(repr(pk) == repr(ppkk)) for k in ('keyspace', 'key', 'column_family'): self.assert_(getattr(pk, k) == getattr(ppkk, k)) # Changes override base keys, but don't change them. _pk = pk.clone(key='sausage') self.assert_(hasattr(_pk, 'keyspace')) self.assert_(hasattr(_pk, 'column_family')) self.assert_(hasattr(_pk, 'key')) self.assert_(_pk.key == 'sausage') self.assert_(pk.key == 'spam') _pk = pk.clone(super_column='tomato') self.assert_(_pk.super_column == 'tomato') self.assertRaises(AttributeError, _pk.__getattr__, 'sopdfj') self.assert_(hasattr(pk, 'key')) # Changes to the base propagate to cloned PKs. pk.keyspace = 'beans' self.assert_(_pk.keyspace == 'beans') __pk = _pk.clone() self.assert_(__pk.keyspace == 'beans') pk.keyspace = 'tomato' self.assert_(__pk.keyspace == 'tomato')
def test_get_path(self): base_key = dict(keyspace='eggs', key='spam', column_family='bacon') key = Key(**base_key) path = key.get_path() self.assert_(isinstance(path, ColumnPath)) self.assert_(path.column_family == key.column_family) self.assert_(base_key['keyspace'] == key.keyspace) keey = key.clone() path2 = keey.get_path() self.assert_(path2 == path) path = key.get_path(column="foo") self.assert_(path.column == "foo")
def test_sparse_multiget(self): """Test sparse_multiget.""" key = Key(keyspace="eggs", column_family="bacon", key="tomato") row_keys = ['cleese', 'jones', 'gilliam', 'chapman', 'idle', 'palin'] keys = (key.clone(key=row_key) for row_key in row_keys) cols = self.client.get_slice() res = dict((row_key, cols) for row_key in row_keys) self.client.multiget_slice = lambda *args: res getter = iterators.sparse_multiget(keys, ['eggs', 'bacon']) for (row_key, cols) in getter.iteritems(): self.assert_(isinstance(row_key, str)) self.assert_(row_key in row_keys) self.assert_(isinstance(cols, list)) for col in cols: self.assert_(isinstance(col, ttypes.Column))