def run(self): db.drop_all() # Setup the database db.create_all() # Rollback any lingering transactions db.session.rollback() # Construct a list of paths within which fixtures may reside default_fixtures_dir = os.path.join(current_app.root_path, 'fixtures') # All relative paths should be relative to the app's root directory. fixtures_dirs = [default_fixtures_dir] # Load all of the fixtures for filename in config.FIXTURES_LIST.split(","): for directory in fixtures_dirs: filepath = os.path.join(directory, filename) if not os.path.exists(filepath): continue load_fixtures(db, loaders.load(filepath)) break else: raise IOError( "Error loading '{0}'. File could not be found".format( filename))
def load_fixtures(self, file_name): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() for document in Document.all(): index_document(document) self.update_index()
def test_custom_loader_is_used_first(self): add(CustomJSONLoader) path = os.path.join(app.root_path, "fixtures", "authors.json") data = load(path) remove(CustomJSONLoader) assert ["foo"] == data
def load_fixtures(self, file_name): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() update_collections() for doc in Document.all(): process_document(doc) self.flush_index()
def load_fixtures(self, file_name, process_documents=True): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() reindex_entities() if process_documents: for doc in Document.all(): analyze_document(doc) optimize_search()
def load_fixtures(self, file_name, process_documents=True): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() reindex_entities() if process_documents: for doc in Document.all(): process_document(doc) self.flush_index()
def load_fixtures(self, file_name): filepath = self.get_fixture_path(file_name) load_fixtures(db, loaders.load(filepath)) db.session.commit() self.update_index()
def _load_fixtures(app, db): for fixture in app.config.get('STARTUP_FIXTURES', []): load_fixtures( db, loaders.load(os.path.join(app.root_path, 'fixtures', fixture)))