def test_condition_multi(self): names, values = ['first', 'last'], ['foo', 'bar'] conditions = [eq(name, value) for name, value in zip(names, values)] where = Where(*conditions) self.assertEquals(where.cql, ' AND '.join(cond.cql for cond in conditions)) self.assertEquals(where.values, values)
def test_valid(self): assignment = Set(first='foo') condition = eq('last', 'bar') op = (Update( self.column_family).set(**assignment.kwargs).where(condition)) cql, args = op.statement() self.assertEquals(cql, self.get_query(assignment, condition)) self.assertEquals(args, assignment.values + condition.values)
def test_no_selection(self): condition = eq('name', 'foo') op = (Delete(self.column_family) .where(condition) ) cql, args = op.statement() self.assertEquals(cql, self.get_query(condition)) self.assertEquals(args, condition.values)
def test_selection(self): condition = eq('name', 'foo') selection = Columns('first', 'last') op = (Delete( self.column_family).columns(*selection.args).where(condition)) cql, args = op.statement() self.assertEquals(cql, self.get_query(condition, selection)) self.assertEquals(args, condition.values + selection.values)
def test_condition(self): selection = Columns('first', 'last') condition = eq('name', 'foo') op = (Select(self.column_family) .columns(*selection.args) .where(condition) ) cql, args = op.statement() self.assertEquals(cql, self.get_query(selection, condition)) self.assertEquals(args, selection.values + condition.values)
def test_valid(self): assignment = Set(first='foo') condition = eq('last', 'bar') op = (Update(self.column_family) .set(**assignment.kwargs) .where(condition) ) cql, args = op.statement() self.assertEquals(cql, self.get_query(assignment, condition)) self.assertEquals(args, assignment.values + condition.values)
def test_options(self): assignment = Set(first='foo') condition = eq('last', 'bar') using = Using(ttl=10800) op = (Update(self.column_family).using(**using.options).set( **assignment.kwargs).where(condition)) cql, args = op.statement() self.assertEquals(cql, self.get_query(assignment, condition, using)) self.assertEquals(args, using.values + assignment.values + condition.values)
def test_options(self): assignment = Set(first='foo') condition = eq('last', 'bar') using = Using(ttl=10800) op = (Update(self.column_family) .using(**using.options) .set(**assignment.kwargs) .where(condition) ) cql, args = op.statement() self.assertEquals(cql, self.get_query(assignment, condition, using)) self.assertEquals(args, using.values + assignment.values + condition.values)
def test_condition_single(self): cond = eq('name', 'foo') where = Where(cond) self.assertEquals(where.cql, cond.cql) self.assertEquals(where.values, cond.values)
def test_eq(self): name, value = 'x', 13 comp = eq(name, value) self.assertEquals(comp.cql, '{}=%s'.format(name)) self.assertEquals(comp.values, [value])
def test_no_assignment(self): op = (Update(self.column_family).where(eq('name', 'foo'))) self.assertRaises(ValidationError, op.statement)
def test_none_condition(self): conditions = [eq('name', 'foo'), None] self.assertRaises(ValidationError, Where, *conditions)
def test_no_assignment(self): op = (Update(self.column_family) .where(eq('name', 'foo')) ) self.assertRaises(ValidationError, op.statement)
def test_invalid_instance_value(self): op = Assignments() op.add(Set(name='foo')) op.add(eq('name', 'bar')) self.assertRaises(ValidationError, op.validate)