def runTest(self): # Create some Movie data-sets. terminator = Movie(title="Terminator 2") inf = get_inst_info(terminator) # Before an instance is saved it is put in the QuerySet's # store. It has to be in either store._dirty or store._cache # to be kept alive. self.assert_(terminator is store._alive[(inf.model_info.model, inf.get_pk_as_key())].get_inst()) # ... and marked dirty (i.e. altered, unsaved). self.assert_(terminator is store._dirty[inf]) # It has not been put in the database store yet self.assert_(terminator not in store._cache._instances.values()) # Now save. terminator.save() # Instance is still an alive (in-memory) object self.assert_(terminator is store._alive[(inf.model_info.model, inf.get_pk_as_key())].get_inst()) self.assert_(len(store._alive) == 1) # Instance is not dirty anymore ... self.assert_(not store._dirty) # ... and is now in the database store. self.assert_(terminator in store._cache._instances.values()) self.assert_(terminator is store._cache._instances[inf]) self.assert_(len(store._cache._instances) == 1)
def runTest(self): print "-------------------------hi-------------------" for i in xrange(20): m = Movie(title="Debug %s" %i) m.save() qs = Movie.objects.filter(title__startswith="Debug") self.assert_(len(qs) == 20 == len(list(Movie.objects)))
def runTest(self): # Create some Movie data-sets. terminator = Movie(title="Terminator 2") terminator.save() totalrecall, created, = Movie(title="Total Recall").save() twins, created = Movie(title="Twins").save() movies = Movie.objects.all() # evaluate the query, hit the store/database. movies_list = list(movies) # the instances have been set as expected. self.assert_([terminator, totalrecall, twins] == movies_list) self.assert_(set(movies) == set(store._cache._instances.values())) # now make a QuerySet for only one instance of the above Movie instances. fltrqs = Movie.objects.filter(title__contains="Term") # now eval it. term_movies = list(fltrqs) # see if the instances have been set as expected. self.assert_([terminator] == term_movies) # misc inf = get_inst_info(terminator) self.assert_(list(fltrqs)[0] is terminator) self.assert_(store._cache._instances[inf] is terminator) # add a little confusion ... list(movies) self.assert_(list(fltrqs)[0] is terminator is movies[0]) # after all this experimenting, make sure there are no excess instances # in the store self.assert_(len(store._cache._instances) == 3)