Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_install_data_managers(self, start_container): # noqa: F811 Prevent start_container unused warning.
"""Install the data_managers on galaxy"""
container = start_container
data_managers = [
dict(name="data_manager_fetch_genome_dbkeys_all_fasta",
owner="devteam"),
dict(name="data_manager_sam_fasta_index_builder",
owner="devteam"),
dict(name="data_manager_bwa_mem_index_builder",
owner="devteam")
]
irm = InstallRepositoryManager(container.gi)
irm.install_repositories(data_managers)
# Galaxy is restarted because otherwise data tables are not watched.
container.container.exec_run("supervisorctl restart galaxy:")
time.sleep(10) # give time for the services to go down
galaxy_wait(container.url)
"""Install the data_managers on galaxy"""
container = start_container
data_managers = [
dict(name="data_manager_fetch_genome_dbkeys_all_fasta",
owner="devteam"),
dict(name="data_manager_sam_fasta_index_builder",
owner="devteam"),
dict(name="data_manager_bwa_mem_index_builder",
owner="devteam")
]
irm = InstallRepositoryManager(container.gi)
irm.install_repositories(data_managers)
# Galaxy is restarted because otherwise data tables are not watched.
container.container.exec_run("supervisorctl restart galaxy:")
time.sleep(10) # give time for the services to go down
galaxy_wait(container.url)
# But alas, the trappings of a proprietary BSD kernel compel us to do ugly workarounds.
container = client.containers.run(GALAXY_IMAGE, detach=True, ports={'80/tcp': None}, **kwargs)
container_id = container.attrs.get('Id')
print(container_id)
# This seems weird as we also can just get container.attrs but for some reason
# the network settings are not loaded in container.attrs. With the get request
# these attributes are loaded
container_attributes = client.containers.get(container_id).attrs
# Venturing into deep nested dictionaries.
exposed_port = container_attributes.get('NetworkSettings').get('Ports').get('80/tcp')[0].get('HostPort')
container_url = "http://localhost:{0}".format(exposed_port)
galaxy_wait(container_url,
timeout=60) # We are only going to wait 60 seconds. These are tests, and we are impatient!
yield GalaxyContainer(url=container_url,
container=container,
attributes=container_attributes,
gi=GalaxyInstance(container_url, key="admin"))
container.remove(force=True)
def test_invalid_keys_in_repo_list(self, caplog, start_container): # noqa: F811 Prevent start_container unused warning.
container = start_container
irm = InstallRepositoryManager(container.gi)
caplog.set_level(logging.WARNING)
irm.install_repositories([
dict(name="bwa",
owner="devteam",
tool_panel_section_name="NGS: Alignment",
sesame_ouvre_toi="Invalid key")
], log=logging.getLogger())
assert "'sesame_ouvre_toi' not a valid key. Will be skipped during parsing" in caplog.text
def test_tool_tests(self, caplog, start_container, parallel_tests): # noqa: F811
container = start_container
irm = InstallRepositoryManager(container.gi)
caplog.set_level(logging.WARNING)
repos = [{'name': 'collection_element_identifiers', 'owner': 'iuc', 'tool_panel_section_label': "NGS: Alignment"}]
log = logging.getLogger()
irm.install_repositories(
repositories=repos,
log=log
)
fd, test_result_file = tempfile.mkstemp()
os.close(fd)
irm.test_tools(test_json=test_result_file, repositories=repos, log=log, parallel_tests=parallel_tests)
with open(test_result_file) as test_result:
result = json.load(test_result)
assert 'tests' in result
def test_run_data_managers_installation_skipped(self, start_container): # noqa: F811 Prevent start_container unused warning.
container = start_container
with open("tests/run_data_managers.yaml.test") as config_file:
configuration = yaml.safe_load(config_file)
dm = DataManagers(container.gi, configuration)
install_results = dm.run()
assert (len(install_results.successful_jobs) == 0)
assert (len(install_results.skipped_jobs) == 9)
assert (len(install_results.failed_jobs) == 0)
{'dbkey_source|dbkey': 'INVALID'},
{'dbkey_source|dbkey_name': 'INVALID_KEY'},
{'sequence_name': 'INVALID'},
{'sequence_id': 'INVALID'},
{'reference_source|reference_source_selector': 'ncbi'},
{'reference_source|requested_identifier': 'INVALID0123'}
],
data_table_reload=[
"all_fasta",
"__dbkeys__"
]
)
]
)
dm = DataManagers(container.gi, configuration)
with pytest.raises(RuntimeError):
dm.run()
assert ("HTTP Error 404" in caplog.text)
assert ("Not all jobs successful! aborting..." in caplog.text)
assert ("finished with exit code: 1. Stderr: " in caplog.text)
def test_run_data_managers(self, start_container): # noqa: F811 Prevent start_container unused warning.
"""Tests an installation using the command line"""
container = start_container
sys.argv = ["run-data-managers",
"--user", "admin@galaxy.org",
"-p", "admin",
"-g", container.url,
"--config", "tests/run_data_managers.yaml.test"]
run_data_managers.main()
def test_flatten_repo_info_invalid_key():
test_repositories = [
dict(name="bwa",
owner="devteam",
tool_panel_section_label="NGS: Alignment",
tool_shed_url="toolshed.g2.bx.psu.edu",
sesame_ouvre_toi="This is an invalid key")
]
flattened_repos = flatten_repo_info(test_repositories)
assert "sesame_ouvre_toi" not in flattened_repos[0].keys()
assert "tool_shed_url" in flattened_repos[0].keys()
def test_flatten_repo_info():
test_repositories = [
dict(name="bwa",
owner="devteam",
tool_panel_section_label="NGS: Alignment",
revisions=["1", "2"]),
dict(name="bowtie2",
owner="devteam",
tool_panel_section_label="NGS: Alignment",
changeset_revisions=["3", "4"])
]
flattened_repos = flatten_repo_info(test_repositories)
assert (flattened_repos == [
dict(name="bwa",
owner="devteam",
tool_panel_section_label="NGS: Alignment",
changeset_revision="1"),
dict(name="bwa",
owner="devteam",
tool_panel_section_label="NGS: Alignment",
changeset_revision="2"),
dict(name="bowtie2",
owner="devteam",
tool_panel_section_label="NGS: Alignment")
])