adding where clause equality method

This commit is contained in:
Blake Eggleston
2013-10-27 16:32:59 -07:00
parent cbbef483b2
commit 88804adaf9
4 changed files with 19 additions and 1 deletions

View File

@@ -540,7 +540,6 @@ class AbstractQuerySet(object):
if self._batch:
raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")
#TODO: check for previous query execution and return row count if it exists
if self._result_cache is None:
query = self._select_query()
query.count = True

View File

@@ -50,6 +50,14 @@ class BaseClause(object):
def __str__(self):
return unicode(self).encode('utf-8')
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.field == other.field and self.value == other.value
return False
def __ne__(self, other):
return not self.__eq__(other)
def get_context_size(self):
""" returns the number of entries this clause will add to the query context """
return 1
@@ -78,6 +86,11 @@ class WhereClause(BaseClause):
def __unicode__(self):
return u'"{}" {} :{}'.format(self.field, self.operator, self.context_id)
def __eq__(self, other):
if super(WhereClause, self).__eq__(other):
return self.operator.__class__ == other.operator.__class__
return False
def update_context(self, ctx):
if isinstance(self.operator, InOperator):
ctx[str(self.context_id)] = InQuoter(self.value)

View File

@@ -16,3 +16,9 @@ class TestWhereClause(TestCase):
wc.set_context_id(5)
self.assertEqual('"a" = :5', unicode(wc))
self.assertEqual('"a" = :5', str(wc))
def test_equality_method(self):
""" tests that 2 identical where clauses evaluate as == """
wc1 = WhereClause('a', EqualsOperator(), 'c')
wc2 = WhereClause('a', EqualsOperator(), 'c')
assert wc1 == wc2