def test_gen_reload_queries_with_compound_primary_keys(self): # gen_reload_queries() does not like compound primary keys. db_queries = bulk.gen_reload_queries([BugAffectsPerson()]) self.assertRaisesWithContent( AssertionError, 'Compound primary keys are not supported: BugAffectsPerson.', list, db_queries)
def test_gen_reload_queries_with_single_object(self): # gen_reload_queries() should generate a single query for a # single object. db_objects = [self.factory.makeSourcePackageName()] db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(1, len(db_queries)) db_query = db_queries[0] self.failUnlessEqual(db_objects, list(db_query))
def test_gen_reload_queries_with_multiple_similar_objects(self): # gen_reload_queries() should generate a single query to load # multiple objects of the same type. db_objects = set( self.factory.makeSourcePackageName() for i in range(5)) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(1, len(db_queries)) db_query = db_queries[0] self.failUnlessEqual(db_objects, set(db_query))
def test_gen_reload_queries_with_multiple_similar_objects(self): # gen_reload_queries() should generate a single query to load # multiple objects of the same type. db_objects = set(self.factory.makeSourcePackageName() for i in range(5)) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(1, len(db_queries)) db_query = db_queries[0] self.failUnlessEqual(db_objects, set(db_query))
def test_gen_reload_queries_with_mixed_objects(self): # gen_reload_queries() should return one query for each # distinct object type in the given objects. db_objects = set(self.factory.makeSourcePackageName() for i in range(5)) db_objects.update(self.factory.makeComponent() for i in range(5)) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(2, len(db_queries)) db_objects_loaded = set() for db_query in db_queries: objects = set(db_query) # None of these objects should have been loaded before. self.failUnlessEqual(set(), objects.intersection(db_objects_loaded)) db_objects_loaded.update(objects) self.failUnlessEqual(db_objects, db_objects_loaded)
def test_gen_reload_queries_with_mixed_objects(self): # gen_reload_queries() should return one query for each # distinct object type in the given objects. db_objects = set( self.factory.makeSourcePackageName() for i in range(5)) db_objects.update( self.factory.makeComponent() for i in range(5)) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(2, len(db_queries)) db_objects_loaded = set() for db_query in db_queries: objects = set(db_query) # None of these objects should have been loaded before. self.failUnlessEqual( set(), objects.intersection(db_objects_loaded)) db_objects_loaded.update(objects) self.failUnlessEqual(db_objects, db_objects_loaded)
def test_gen_reload_queries_with_mixed_stores(self): # gen_reload_queries() returns one query for each distinct # store even for the same object type. db_object = self.factory.makeComponent() db_object_type = bulk.get_type(db_object) # Commit so the database object is available in both master # and slave stores. transaction.commit() db_objects = set( (IMasterStore(db_object).get(db_object_type, db_object.id), ISlaveStore(db_object).get(db_object_type, db_object.id))) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(2, len(db_queries)) db_objects_loaded = set() for db_query in db_queries: objects = set(db_query) # None of these objects should have been loaded before. self.failUnlessEqual( set(), objects.intersection(db_objects_loaded)) db_objects_loaded.update(objects) self.failUnlessEqual(db_objects, db_objects_loaded)
def test_gen_reload_queries_with_mixed_stores(self): # gen_reload_queries() returns one query for each distinct # store even for the same object type. db_object = self.factory.makeComponent() db_object_type = bulk.get_type(db_object) # Commit so the database object is available in both master # and slave stores. transaction.commit() db_objects = set( (IMasterStore(db_object).get(db_object_type, db_object.id), ISlaveStore(db_object).get(db_object_type, db_object.id))) db_queries = list(bulk.gen_reload_queries(db_objects)) self.failUnlessEqual(2, len(db_queries)) db_objects_loaded = set() for db_query in db_queries: objects = set(db_query) # None of these objects should have been loaded before. self.failUnlessEqual(set(), objects.intersection(db_objects_loaded)) db_objects_loaded.update(objects) self.failUnlessEqual(db_objects, db_objects_loaded)
def test_gen_reload_queries_with_empty_list(self): self.failUnlessEqual([], list(bulk.gen_reload_queries([])))
def test_gen_reload_queries_with_non_Storm_objects(self): # gen_reload_queries() does not like non-Storm objects. self.assertRaises( ClassInfoError, list, bulk.gen_reload_queries(['bogus']))
def test_gen_reload_queries_with_non_Storm_objects(self): # gen_reload_queries() does not like non-Storm objects. self.assertRaises(ClassInfoError, list, bulk.gen_reload_queries(['bogus']))