Skip to content

Instantly share code, notes, and snippets.

@brentp
Created March 12, 2009 17:37
Show Gist options
  • Save brentp/78183 to your computer and use it in GitHub Desktop.
Save brentp/78183 to your computer and use it in GitHub Desktop.
diff --git a/lib/tc/test/__init__.py b/lib/tc/test/__init__.py
index 60722cd..d7e3f7a 100644
--- a/lib/tc/test/__init__.py
+++ b/lib/tc/test/__init__.py
@@ -3,9 +3,10 @@ import unittest, sys, os
def suite():
suites = []
- import hdb, bdb
+ import hdb, bdb, tdb
suites.append(hdb.suite())
suites.append(bdb.suite())
+ suites.append(tdb.suite())
return unittest.TestSuite(suites)
def test(*va, **kw):
diff --git a/lib/tc/test/tdb.py b/lib/tc/test/tdb.py
index d6ddbcd..3d9b58b 100644
--- a/lib/tc/test/tdb.py
+++ b/lib/tc/test/tdb.py
@@ -106,7 +106,37 @@ class TestTDB(unittest.TestCase):
self.assertEquals(pks[0], 'torgny')
self.assertEquals(pks[1], 'rosa')
self.assertEquals(pks[2], 'jdoe')
+
+ q = db.query()
+ q.order('age', tc.TDBQONUMDESC)
+ # get thos with ages < 40
+ q.filter('age', tc.TDBQCNUMLE, '40')
+ pks = q.keys()
+ self.assertEquals(pks[0], 'torgny')
+ self.assertEquals(pks[1], 'rosa')
+ self.assertEquals(len(pks), 2)
+ # add to the filter only those > 30 ( and < 40 from before)
+ q.filter('age', tc.TDBQCNUMGE, '30')
+ pks = q.keys()
+ self.assertEquals(pks[0], 'torgny')
+ self.assertEquals(len(pks), 1)
+
+ # filter out those who have blue in the colors
+ q = db.query()
+ q.order('age', tc.TDBQONUMDESC)
+ q.filter('colors', tc.TDBQCSTRINC, 'blue')
+ pks = q.keys()
+ self.assertEquals(pks[0], 'torgny')
+ self.assertEquals(pks[1], 'rosa')
+ self.assertEquals(len(pks), 2)
+
+ # add a filter to the existing:
+ q.filter('colors', tc.TDBQCSTRINC, 'pink')
+ pks = q.keys()
+ self.assertEquals(pks[0], 'rosa')
+ self.assertEquals(len(pks), 1)
+
def suite():
return unittest.TestSuite([
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment