def test_create_one_object(self): with ContextLogger() as context_logger: bar = self.Bar(_id=1) bar.save() report = context_logger.report() self.assertEqual(report[('bar', 'insert')][0], 1)
def test_load_object_in_cache(self): bar = self.Bar(_id=1) bar.save() with ContextLogger() as context_logger: self.Bar.load(1) report = context_logger.report() self.assertNotIn(('bar', 'load'), report)
def test_load_object_not_in_cache(self): bar = self.Bar(_id=1) bar.save() self.Bar._clear_caches(1) with ContextLogger() as context_logger: self.Bar.load(1) report = context_logger.report() self.assertEqual(report[('bar', 'get')][0], 1)
def test_create_several_objects(self): with ContextLogger() as context_logger: bar1 = self.Bar(_id=1) bar2 = self.Bar(_id=2) bar3 = self.Bar(_id=3) bar4 = self.Bar(_id=4) bar5 = self.Bar(_id=5) bar1.save() bar2.save() bar3.save() bar4.save() bar5.save() report = context_logger.report() self.assertEqual(report[('bar', 'insert')][0], 5)
def test_create_linked_objects(self): bar1 = self.Bar(_id=1) bar2 = self.Bar(_id=2) bar3 = self.Bar(_id=3) bar1.save() bar2.save() bar3.save() with ContextLogger() as context_logger: foo1 = self.Foo(_id=4) foo1.my_bar = [bar1, bar2, bar3] foo1.save() report = context_logger.report() self.assertEqual(report[('foo', 'insert')][0], 1) self.assertEqual(report[('bar', 'update')][0], 3)
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_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)
# blog1.tags = [tag1, tag1] # blog1.tag = tag1 # import pdb; pdb.set_trace() blog1.save() blog1.tags.pop() blog1.save() # import pdb; pdb.set_trace() logging.debug("foo") with ContextLogger(): blog2.tag = tag1 # blog2.tags.append(tag1) blog2.save() blog3.tag = tag1 blog3.save() blog4 = Blog(title='tbdtbdtbd', tags=[tag1, tag2, tag3, tag4, tag5]) blog4.save() logging.debug("bar")