def __init__(self, test_directory, mock_model=True): # The following line is needed in order to create # HistoryDatasetAssociations - ideally the model classes would be # usable without the ORM infrastructure in place. in_memomry_model = mapping.init("/tmp", "sqlite:///:memory:", create_tables=True) self.datatypes_registry = Bunch( integrated_datatypes_configs= '/galaxy/integrated_datatypes_configs.xml', get_datatype_by_extension=lambda ext: Bunch(), ) self.config = Bunch( outputs_to_working_directory=False, commands_in_new_shell=True, new_file_path=os.path.join(test_directory, "new_files"), tool_data_path=os.path.join(test_directory, "tools"), root=os.path.join(test_directory, "galaxy"), admin_users="*****@*****.**", len_file_path=os.path.join('tool-data', 'shared', 'ucsc', 'chrom'), builds_file_path=os.path.join('tool-data', 'shared', 'ucsc', 'builds.txt.sample'), migrated_tools_config=os.path.join(test_directory, "migrated_tools_conf.xml"), ) # Setup some attributes for downstream extension by specific tests. self.job_config = Bunch(dynamic_params=None, ) # Two ways to handle model layer, one is to stub out some objects that # have an interface similar to real model (mock_model) and can keep # track of 'persisted' objects in a map. The other is to use a real # sqlalchemy layer but target an in memory database. Depending on what # is being tested. if mock_model: # Create self.model to mimic app.model. self.model = Bunch(context=MockContext()) for module_member_name in dir(galaxy.model): module_member = getattr(galaxy.model, module_member_name) if type(module_member) == type: self.model[module_member_name] = module_member else: self.model = in_memomry_model self.genome_builds = GenomeBuilds(self) self.toolbox = None self.object_store = None self.security = SecurityHelper(id_secret="testing") from galaxy.security import GalaxyRBACAgent self.job_queue = NoopQueue() self.security_agent = GalaxyRBACAgent(self.model) self.tool_data_tables = {} self.dataset_collections_service = None self.container_finder = NullContainerFinder() self.name = "galaxy"
sys.path.insert(1,'/galaxy-central') sys.path.insert(1,'/galaxy-central/lib') from scripts.db_shell import * from galaxy.util.bunch import Bunch from galaxy.security import GalaxyRBACAgent from sqlalchemy.orm import sessionmaker from sqlalchemy import * import argparse bunch = Bunch( **globals() ) engine = create_engine('postgres://*****:*****@localhost:5432/galaxy') bunch.session = sessionmaker(bind=engine) # For backward compatibility with "model.context.current" bunch.context = sessionmaker(bind=engine) security_agent = GalaxyRBACAgent( bunch ) security_agent.sa_session = sa_session def add_user(email, password, key=None): """ Add Galaxy User. From John https://gist.github.com/jmchilton/4475646 """ query = sa_session.query( User ).filter_by( email=email ) if query.count() > 0: return query.first() else: User.use_pbkdf2 = False user = User(email) user.set_password_cleartext(password)
# FROM https://github.com/bgruening/docker-galaxy-stable/blob/master/galaxy/create_galaxy_user.py from scripts.db_shell import * from galaxy.util.bunch import Bunch from galaxy.security import GalaxyRBACAgent from sqlalchemy.orm import sessionmaker from sqlalchemy import * import argparse bunch = Bunch(**globals()) #engine = create_engine('postgres://*****:*****@localhost:5432/galaxy') engine = create_engine( 'sqlite:///home/vagrant/galaxy/database/universe.sqlite') bunch.session = sessionmaker(bind=engine) # For backward compatibility with "model.context.current" bunch.context = sessionmaker(bind=engine) security_agent = GalaxyRBACAgent(bunch) security_agent.sa_session = sa_session def add_user(email, password, key=None): """ Add Galaxy User. From John https://gist.github.com/jmchilton/4475646 """ query = sa_session.query(User).filter_by(email=email) if query.count() > 0: return query.first() else: user = User(email) user.set_password_cleartext(password) sa_session.add(user)