adding tests around update and related debugging

This commit is contained in:
Blake Eggleston
2013-10-25 14:25:30 -07:00
parent 70e446631b
commit 89c20ef6c5
2 changed files with 38 additions and 3 deletions

View File

@@ -11,6 +11,9 @@ class BaseClause(object):
self.value = value
self.context_id = None
def __unicode__(self):
raise NotImplementedError
def __str__(self):
return str(unicode(self))
@@ -40,12 +43,15 @@ class WhereClause(BaseClause):
self.operator = operator
def __unicode__(self):
return u'"{}" {} {}'.format(self.field, self.operator, self.context_id)
return u'"{}" {} :{}'.format(self.field, self.operator, self.context_id)
class AssignmentClause(BaseClause):
""" a single variable st statement """
def __unicode__(self):
return u'"{}" = :{}'.format(self.field, self.context_id)
def insert_tuple(self):
return self.field, self.context_id
@@ -85,6 +91,9 @@ class BaseCQLStatement(object):
clause.update_context(ctx)
return ctx
def __unicode__(self):
raise NotImplementedError
def __str__(self):
return str(unicode(self))
@@ -204,8 +213,8 @@ class UpdateStatement(AssignmentStatement):
def __unicode__(self):
qs = ['UPDATE', self.table]
qs += 'SET'
qs += ', '.join([unicode(c) for c in self.assignments])
qs += ['SET']
qs += [', '.join([unicode(c) for c in self.assignments])]
if self.where_clauses:
qs += [self._where]

View File

@@ -0,0 +1,26 @@
from unittest import TestCase
from cqlengine.statements import UpdateStatement, WhereClause, AssignmentClause
from cqlengine.operators import *
class UpdateStatementTests(TestCase):
def test_table_rendering(self):
""" tests that fields are properly added to the select statement """
us = UpdateStatement('table')
self.assertTrue(unicode(us).startswith('UPDATE table SET'), unicode(us))
self.assertTrue(str(us).startswith('UPDATE table SET'), str(us))
def test_rendering(self):
us = UpdateStatement('table')
us.add_assignment_clause(AssignmentClause('a', 'b'))
us.add_assignment_clause(AssignmentClause('c', 'd'))
us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
self.assertEqual(unicode(us), 'UPDATE table SET "a" = :0, "c" = :1 WHERE "a" = :2', unicode(us))
def test_context(self):
us = UpdateStatement('table')
us.add_assignment_clause(AssignmentClause('a', 'b'))
us.add_assignment_clause(AssignmentClause('c', 'd'))
us.add_where_clause(WhereClause('a', EqualsOperator(), 'x'))
self.assertEqual(us.get_context(), {0: 'b', 1: 'd', 2: 'x'})