def setupListTest(store, klass): # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass and put it into the list in foo obj = klass() getattr(foo, 'addToListOf%s' % klass.__name__)(obj) store.saveChanges() return obj, foo, bar
def setupListTest(store, klass): # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass and put it into the list in foo obj = klass() getattr(foo, 'addToListOf%s' % klass.__name__)(obj) store.saveChanges() return obj, foo, bar
def setupListTest(store, klass): """ Setup 3 objects: one of the specified klass, pointing to a Foo, pointing to a Bar. Returns tuple (object of specified klass, foo, bar). """ # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass and put it into the list in foo object = klass() getattr(foo, 'addToListOf%s' % klass.__name__)(object) store.saveChanges() return object, foo, bar
def setupTest(store, klass): """ Setup 3 objects: one of the specified klass, pointing to a Foo, pointing to a Bar. Returns tuple (object of specified klass, foo, bar). """ # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass pointing to Foo object = klass() object.setFoo(foo) store.addObject(object) store.saveChanges() return object, foo, bar
def setupListTest(store, klass): """Setup list test. Setup 3 objects: one of the specified klass, pointing to a Foo, pointing to a Bar. Returns tuple (object of specified klass, foo, bar). """ # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass and put it into the list in foo obj = klass() getattr(foo, 'addToListOf%s' % klass.__name__)(obj) store.saveChanges() return obj, foo, bar
def setupTest(store, klass): """Setup test. Setup 3 objects: one of the specified klass, pointing to a Foo, pointing to a Bar. Returns tuple (object of specified klass, foo, bar). """ # Create a Foo and a Bar, with the Foo pointing to the Bar bar = Bar() bar.setX(42) foo = Foo() foo.setBar(bar) store.addObject(foo) store.addObject(bar) store.saveChanges() # create an instance of klass pointing to Foo obj = klass() obj.setFoo(foo) store.addObject(obj) store.saveChanges() return obj, foo, bar
def test(store): # We invoke testAddToBars twice on purpose, just to see that # the second time around, things are stable enough to pass again testAddToBars(store) testAddToBars(store) # Test 2: do not use addToBars() f = Foo() store.addObject(f) b = Bar() b.setFoo(f) b.setX(7) store.addObject(b) store.saveChanges() store.clear() f = store.fetchObjectsOfClass(Foo)[0] assert f._mk_store assert f._mk_inStore bars = f.bars() assert isinstance(bars, list) assert len(bars) == 1, 'bars=%r' % bars assert bars[0].x() == 7 # Test addToXYZ() method bar = Bar() bar.setX(42) f.addToBars(bar) assert bar.foo() == f store.saveChanges() store.clear() f = store.fetchObjectsOfClass(Foo)[0] bars = f.bars() assert isinstance(bars, list) assert len(bars) == 2, 'bars=%r' % bars assert bars[0].x() == 7 assert bars[1].x() == 42 # Test the assertion checking in addToXYZ() try: f.addToBars(None) except Exception: pass else: NoException('f.addToBars(None) # None not allowed') try: f.addToBars(5) except Exception: pass else: NoException('f.addToBars(5) # not an object') try: f.addToBars(f) except Exception: pass else: NoException('f.addToBars(f) # wrong class') try: f.addToBars(bar) except Exception: pass else: NoException('f.addToBars(bar) # already added') # Test delFromXYZ() method bar = bars[1] f.delFromBars(bar) assert len(bars) == 1 assert bar.foo() is None store.saveChanges() store.clear() f = store.fetchObjectsOfClass(Foo)[0] bars = f.bars() assert isinstance(bars, list) assert len(bars) == 1, 'bars=%r' % bars assert bars[0].x() == 7 # Test the assertion checking in delFromXYZ() try: f.delFromBars(None) except Exception: pass else: NoException('f.delFromBars(None) # None not allowed') try: f.delFromBars(5) except Exception: pass else: NoException('f.delFromBars(5) # not an object') try: f.delFromBars(f) except Exception: pass else: NoException('f.delFromBars(f) # wrong class') try: f.delFromBars(bar) except Exception: pass else: NoException('f.delFromBars(bar) # already deleted')
def test(store): # We invoke testAddToBars twice on purpose, just to see that # the second time around, things are stable enough to pass again testAddToBars(store) testAddToBars(store) # Test 2: do not use addToBars() # @@ 2001-02-11 ce: this is probably not a valid test in the long run f = Foo() f.setX( 0 ) # @@ 2000-11-25 ce: take out after fixing default value bug in gen py code store.addObject(f) b = Bar() b.setFoo(f) b.setX(7) store.addObject(b) store.saveChanges() store.clear() f = store.fetchObjectsOfClass(Foo)[0] assert f._mk_store assert f._mk_inStore bars = f.bars() assert type(bars) is ListType assert len(bars) == 1, 'bars=%r' % bars assert bars[0].x() == 7 # Test addToXYZ() method bar = Bar() bar.setX(7) f.addToBars(bar) assert bar.foo() == f store.saveChanges() store.clear() f = store.fetchObjectsOfClass(Foo)[0] bars = f.bars() assert type(bars) is ListType assert len(bars) == 2, 'bars=%r' % bars assert bars[0].x() == 7 assert bars[1].x() == 7 # Test the assertion checking in addToXYZ() try: f.addToBars(None) except: pass else: NoException('f.addToBars(None) # None not allowed') try: f.addToBars(5) except: pass else: NoException('f.addToBars(5) # not an object') try: f.addToBars(f) except: pass else: NoException('f.addToBars(f) # wrong class') try: f.addToBars(bar) except: pass else: NoException('f.addToBars(bar) # already added')