def test_update_foreign_referee_loaded(self): """Update the PK of a record with a saved foreign field; assert that the foreign object includes the new PK but not the old PK. """ bar = self.Bar(ref=self.foos[0]) bar.save() prev_key = bar._primary_key StoredObject._clear_caches() bar_loaded = self.Bar.load(bar._primary_key) bar_loaded._id = 'changed' bar_loaded.save() self.foos[0].reload() assert_in( 'changed', self.foos[0]._backrefs['my_ref']['bar']['ref'] ) assert_not_in( prev_key, self.foos[0]._backrefs['my_ref']['bar']['ref'] )
def setUp(self): super(ModularOdmTestCase, self).setUp() test_objects = self.define_test_objects() or tuple() for obj in test_objects: obj.set_storage(self.make_storage()) self.__setattr__(obj.__name__, obj) StoredObject._clear_caches() self.set_up_test_objects()
def setUp(self): super(ModularOdmTestCase, self).setUp() test_objects = self.define_objects() or tuple() for obj in test_objects: obj.set_storage(self.make_storage()) self.__setattr__(obj.__name__, obj) StoredObject._clear_caches() self.set_up_objects()
def setUp(self): super(ModularOdmTestCase, self).setUp() test_objects = self.define_objects() or tuple() for obj in test_objects: # Create storage backend if not explicitly set if not getattr(obj, '_storage', None): obj.set_storage(self.make_storage()) self.__setattr__(obj.__name__, obj) StoredObject._clear_caches() self.set_up_objects()
def setUp(self): super(ModularOdmTestCase, self).setUp() test_objects = self.define_objects() or tuple() for obj in test_objects: # Create storage backend if not explicitly set if not getattr(obj, '_storage', None): obj.set_storage(self.make_storage()) self.__setattr__(obj.__name__, obj) StoredObject._clear_caches() self.set_up_objects()
def test_pk_changed(self): bar = self.Bar() bar.save() prev_key = bar._primary_key bar._id = 'changed' bar.save() StoredObject._clear_caches() assert_true(self.Bar.load(prev_key) is None) assert_true(self.Bar.load('changed') is not None)
def test_update_abstract_list_referent(self): """ """ baz = self.Baz(abs_ref_list=self.bars) baz.save() self.bars[0]._id = 'changed' self.bars[0].save() StoredObject._clear_caches() baz = self.Baz.load(baz._primary_key) assert_equal(list(baz.abs_ref_list), list(self.bars))
def test_pk_changed(self): bar = self.Bar() bar.save() prev_key = bar._primary_key bar._id = 'changed' bar.save() StoredObject._clear_caches() assert_true(self.Bar.load(prev_key) is None) assert_true(self.Bar.load('changed') is not None)
def test_update_foreign_referent(self): """Update the PK of a record (bar) referred to by another record (baz); assert that second record (baz) points to changed record (bar). """ baz = self.Baz(ref=self.bars[0]) baz.save() self.bars[0]._id = 'changed' self.bars[0].save() StoredObject._clear_caches() baz = self.Baz.load(baz._primary_key) assert_equal(baz.ref, self.bars[0])
def test_update_abstract_referent(self): """ """ baz = self.Baz(abs_ref=self.bars[0]) baz.save() self.bars[0]._id = 'changed' self.bars[0].save() StoredObject._clear_caches() baz = self.Baz.load(baz._primary_key) assert_equal( baz.abs_ref, self.bars[0] )
def test_dunder_br_laziness(self): StoredObject._clear_caches() with ContextLogger() as c: # get the Bar object bar = self.Bar.find_one() # access the ForeignList bar.foo__my_foos # Two calls so far - .find_one() and .find() self.assertNotIn("foo", [k[0] for k, v in six.iteritems(c.report())]) # access a member of the ForeignList, forcing that member to load bar.foo__my_foos[0] # now there should be a call to Foo.get() self.assertEqual(c.report()[("foo", "get")][0], 1)
def test_update_foreign_list_referent(self): """ """ baz = self.Baz(ref_list=self.bars) baz.save() self.bars[0]._id = 'changed' self.bars[0].save() StoredObject._clear_caches() baz = self.Baz.load(baz._primary_key) assert_equal( list(baz.ref_list), list(self.bars) )
def test_update_foreign_referent(self): """Update the PK of a record (bar) referred to by another record (baz); assert that second record (baz) points to changed record (bar). """ baz = self.Baz(ref=self.bars[0]) baz.save() self.bars[0]._id = 'changed' self.bars[0].save() StoredObject._clear_caches() baz = self.Baz.load(baz._primary_key) assert_equal( baz.ref, self.bars[0] )
def test_dunder_br_laziness(self): StoredObject._clear_caches() with ContextLogger() as c: # get the Bar object bar = self.Bar.find_one() # access the ForeignList bar.foo__my_foos # Two calls so far - .find_one() and .find() self.assertNotIn( 'foo', [k[0] for k, v in six.iteritems(c.report())], ) # access a member of the ForeignList, forcing that member to load bar.foo__my_foos[0] # now there should be a call to Foo.get() self.assertEqual(c.report()[('foo', 'get')][0], 1)
def test_update_foreign_referee_loaded(self): """Update the PK of a record with a saved foreign field; assert that the foreign object includes the new PK but not the old PK. """ bar = self.Bar(ref=self.foos[0]) bar.save() prev_key = bar._primary_key StoredObject._clear_caches() bar_loaded = self.Bar.load(bar._primary_key) bar_loaded._id = 'changed' bar_loaded.save() self.foos[0].reload() assert_in('changed', self.foos[0]._backrefs['my_ref']['bar']['ref']) assert_not_in(prev_key, self.foos[0]._backrefs['my_ref']['bar']['ref'])
def test_load_linked_objects_not_in_cache(self): bar1 = self.Bar(_id=1) bar2 = self.Bar(_id=2) bar3 = self.Bar(_id=3) bar1.save() bar2.save() bar3.save() foo1 = self.Foo(_id=4) foo1.my_bar = [bar1, bar2, bar3] foo1.save() StoredObject._clear_caches() with ContextLogger() as context_logger: self.Foo.load(4) report = context_logger.report() self.assertEqual(report[('foo', 'get')][0], 1) self.assertNotIn(('bar', 'get'), report)
def test_load_linked_objects_not_in_cache(self): bar1 = self.Bar(_id=1) bar2 = self.Bar(_id=2) bar3 = self.Bar(_id=3) bar1.save() bar2.save() bar3.save() foo1 = self.Foo(_id=4) foo1.my_bar = [bar1, bar2, bar3] foo1.save() StoredObject._clear_caches() with ContextLogger() as context_logger: self.Foo.load(4) report = context_logger.report() self.assertEqual(report[('foo', 'get')][0], 1) self.assertNotIn(('bar', 'get'), report)
def get_foreign_object(self, value): from modularodm import StoredObject return StoredObject.get_collection(value[1])\ .load(value[0])
def test_subscribe_from_base_schema(self, mock_connect_via): StoredObject.subscribe('save', weak=False) mock_connect_via.assert_called_once_with(None, False)
def get_foreign_object(self, value): from modularodm import StoredObject return StoredObject.get_collection(value[1])\ .load(value[0])
def test_subscribe_from_base_schema(self, mock_connect_via): StoredObject.subscribe('save', weak=False) mock_connect_via.assert_called_once_with( None, False )