Browse files

added 2 extra tests in load_related

  • Loading branch information...
1 parent c34cdd2 commit d2bab16596cbb53d311a3754883b3787f4f6e566 quantmind committed Jul 31, 2012
Showing with 29 additions and 12 deletions.
  1. +29 −12 tests/regression/query/load_related.py
View
41 tests/regression/query/load_related.py
@@ -5,7 +5,7 @@
class load_related(FinanceTest):
-
+
def testMeta(self):
self.data.makePositions(self)
session = self.session()
@@ -25,7 +25,7 @@ def testMeta(self):
self.assertEqual(pos2.select_related['instrument'],set(('name','ccy')))
self.assertEqual(pos3.select_related['instrument'],set(('name','ccy')))
self.assertEqual(pos3.select_related['fund'],set(('name',)))
-
+
def testSingle(self):
self.data.makePositions(self)
session = self.session()
@@ -43,7 +43,7 @@ def testSingle(self):
cache = fund.get_cache_name()
val = getattr(p,cache,None)
self.assertFalse(val)
-
+
def testSingle_withFields(self):
self.data.makePositions(self)
session = self.session()
@@ -61,7 +61,7 @@ def testSingle_withFields(self):
self.assertTrue(val.name)
self.assertTrue(val.ccy)
self.assertFalse(hasattr(val,'type'))
-
+
def testDouble(self):
self.data.makePositions(self)
session = self.session()
@@ -80,7 +80,7 @@ def testDouble(self):
val = getattr(p,cache,None)
self.assertTrue(val)
self.assertTrue(isinstance(val,fund.relmodel))
-
+
def testError(self):
self.data.makePositions(self)
session = self.session()
@@ -90,7 +90,7 @@ def testError(self):
pos = query.load_related('instrument','id')
self.assertEqual(len(pos.select_related),1)
self.assertEqual(pos.select_related['instrument'],set())
-
+
def testLoadRelatedLoadOnly(self):
self.data.makePositions(self)
session = self.session()
@@ -105,11 +105,29 @@ def testLoadRelatedLoadOnly(self):
val = getattr(p, cache, None)
self.assertTrue(val)
self.assertTrue(isinstance(val,inst.relmodel))
-
-
+
+ def testEmpty(self):
+ session = self.session()
+ instruments = session.query(Position).load_related('instrument').all()
+ self.assertEqual(instruments, [])
+
+ def testWithFilter(self):
+ self.data.makePositions(self)
+ session = self.session()
+ instruments = session.query(Instrument).filter(ccy='EUR')
+ qs = session.query(Position).filter(instrument=instruments)\
+ .load_related('instrument')
+ inst = Position._meta.dfields['instrument']
+ for p in qs:
+ cache = inst.get_cache_name()
+ val = getattr(p, cache, None)
+ self.assertTrue(val)
+ self.assertTrue(isinstance(val, inst.relmodel))
+ self.assertEqual(p.instrument.ccy, 'EUR')
+
class load_related_structure(test.TestCase):
-
+
def setUp(self):
session = self.session()
with session.begin():
@@ -122,7 +140,7 @@ def setUp(self):
d2.data.update((('palla','ball'),
('nave','boat'),
('gatto','cat')))
-
+
def testGet(self):
session = self.session()
query = session.query(Dictionary)
@@ -137,5 +155,4 @@ def testGet(self):
cache = data.cache.cache
self.assertEqual(len(cache),3)
self.assertEqual(cache,remote)
-
-
+

0 comments on commit d2bab16

Please sign in to comment.