def _raw_update_history_item(self, history_id, item_id, data): update_url = self._api_url("histories/%s/contents/%s" % (history_id, item_id), use_key=True) update_response = requests.put(update_url, json=data) assert_status_code_is_ok(update_response) return update_response
def test_page_encoding_markdown(self): dataset = self.dataset_populator.new_dataset(self.history_id) dataset_id = dataset["id"] request = dict( slug="mypage-markdown", title="MY PAGE", content='''```galaxy history_dataset_display(history_dataset_id=%s) ```''' % dataset["id"], content_format="markdown", ) page_response = self._post("pages", request, json=True) api_asserts.assert_status_code_is_ok(page_response) sa_session = self._app.model.context page_revision = sa_session.query( model.PageRevision).filter_by(content_format="markdown").all()[0] assert '''```galaxy history_dataset_display(history_dataset_id=1) ```''' in page_revision.content, page_revision.content assert '''::: history_dataset_display history_dataset_id=%s''' % dataset_id not in page_revision.content, page_revision.content show_page_response = self._get("pages/%s" % page_response.json()["id"]) api_asserts.assert_status_code_is_ok(show_page_response) content = show_page_response.json()["content"] assert '''```galaxy history_dataset_display(history_dataset_id=1) ```''' not in content, content assert '''```galaxy history_dataset_display(history_dataset_id=%s) ```''' % dataset_id in content, content
def test_vault_secret_per_user_in_file_source(self): """ This file source performs a user vault lookup. The secret stored for the first user is a valid path and should succeed, while the second user's stored secret should fail. """ with self._different_user(email=self.USER_1_APP_VAULT_ENTRY): app = self._app user = app.model.context.query(app.model.User).filter( app.model.User.email == self.USER_1_APP_VAULT_ENTRY).first() user_vault = UserVaultWrapper(self._app.vault, user) # use a valid symlink path so the posix list succeeds user_vault.write_secret( 'posix/root_path', app.config.user_library_import_symlink_allowlist[0]) data = {"target": "gxfiles://test_user_vault"} list_response = self.galaxy_interactor.get("remote_files", data) api_asserts.assert_status_code_is_ok(list_response) remote_files = list_response.json() print(remote_files) with self._different_user(email=self.USER_2_APP_VAULT_ENTRY): app = self._app user = app.model.context.query(app.model.User).filter( app.model.User.email == self.USER_2_APP_VAULT_ENTRY).first() user_vault = UserVaultWrapper(self._app.vault, user) # use an invalid symlink path so the posix list fails user_vault.write_secret('posix/root_path', '/invalid/root') data = {"target": "gxfiles://test_user_vault"} list_response = self.galaxy_interactor.get("remote_files", data) api_asserts.assert_status_code_is(list_response, 404)
def test_plugin_config(self): plugin_config_response = self.galaxy_interactor.get( "remote_files/plugins") api_asserts.assert_status_code_is_ok(plugin_config_response) plugins = plugin_config_response.json() assert len(plugins) == 1 assert plugins[0]["type"] == "posix" assert plugins[0]["uri_root"] == "gxfiles://posix_test" assert plugins[0]["writable"] is True assert plugins[0]["requires_roles"] == REQUIRED_ROLE assert plugins[0]["requires_groups"] == REQUIRED_GROUP
def _assert_list_response_matches_fixtures(self, list_response): api_asserts.assert_status_code_is_ok(list_response) remote_files = list_response.json() assert len(remote_files) == 2 if remote_files[0]["class"] == "Directory": dir = remote_files[0] file = remote_files[1] else: dir = remote_files[1] file = remote_files[0] assert file["name"] == "a" assert dir["name"] == "subdir1"
def test_plugin_config(self): # Default user has required role but not required group, so cannot see plugin plugin_config_response = self.galaxy_interactor.get( "remote_files/plugins") api_asserts.assert_status_code_is_ok(plugin_config_response) plugins = plugin_config_response.json() assert len(plugins) == 0 # Admins can see plugins plugin_config_response = self.galaxy_interactor.get( "remote_files/plugins", admin=True) api_asserts.assert_status_code_is_ok(plugin_config_response) plugins = plugin_config_response.json() assert len(plugins) == 1 assert plugins[0]["type"] == "posix" assert plugins[0]["uri_root"] == "gxfiles://posix_test" assert plugins[0]["writable"] is True assert plugins[0]["requires_roles"] == REQUIRED_ROLE assert plugins[0]["requires_groups"] == REQUIRED_GROUP
def test_simple_usage(self): plugin_config_response = self.galaxy_interactor.get("remote_files/plugins") api_asserts.assert_status_code_is_ok(plugin_config_response) plugins = plugin_config_response.json() assert len(plugins) == 1 assert plugins[0]["type"] == "webdav" assert plugins[0]["uri_prefix"] == "gxfiles://test1" data = {"target": "gxfiles://test1"} list_response = self.galaxy_interactor.get("remote_files", data) api_asserts.assert_status_code_is_ok(list_response) remote_files = list_response.json() print(remote_files) with self.dataset_populator.test_history() as history_id: new_dataset = self.dataset_populator.new_dataset(history_id, content="gxfiles://test1/a", assert_ok=True) content = self.dataset_populator.get_history_dataset_content(history_id, dataset=new_dataset) assert content == "a\n", content
def test_page_encoding(self): request = dict( slug="mypage", title="MY PAGE", content= '''<p>Page!<div class="embedded-item" id="History-%s"></div></p>''' % self.history_id, ) page_response = self._post("pages", request, json=True) api_asserts.assert_status_code_is_ok(page_response) sa_session = self._app.model.context page_revision = sa_session.query( model.PageRevision).filter_by(content_format="html").all()[0] assert '''id="History-1"''' in page_revision.content, page_revision.content assert '''id="History-%s"''' % self.history_id not in page_revision.content, page_revision.content show_page_response = self._get("pages/%s" % page_response.json()["id"]) api_asserts.assert_status_code_is_ok(show_page_response) content = show_page_response.json()["content"] assert '''id="History-1"''' not in content, content assert '''id="History-%s"''' % self.history_id in content, content
def test_upload_file_from_remote_source(self): with self._different_user(email=self.USER_1_APP_VAULT_ENTRY): app = self._app user = app.model.context.query(app.model.User).filter( app.model.User.email == self.USER_1_APP_VAULT_ENTRY).first() user_vault = UserVaultWrapper(self._app.vault, user) # use a valid symlink path so the posix list succeeds user_vault.write_secret( 'posix/root_path', app.config.user_library_import_symlink_allowlist[0]) data = {"target": "gxfiles://test_user_vault"} with open( os.path.join( app.config.user_library_import_symlink_allowlist[0], 'a_file'), 'w') as fh: fh.write('I require access to the vault') list_response = self.galaxy_interactor.get("remote_files", data) api_asserts.assert_status_code_is_ok(list_response) remote_files = list_response.json() assert len(remote_files) == 1 with self.dataset_populator.test_history() as history_id: element = dict(src="url", url="gxfiles://test_user_vault/a_file") target = { "destination": { "type": "hdas" }, "elements": [element], } targets = json.dumps([target]) payload = { "history_id": history_id, "targets": targets, } new_dataset = self.dataset_populator.fetch( payload, assert_ok=True).json()["outputs"][0] content = self.dataset_populator.get_history_dataset_content( history_id, dataset=new_dataset) assert content == "I require access to the vault", content
def _get_history_item_as_admin(self, history_id, item_id): response = self._get("histories/%s/contents/%s?view=detailed" % (history_id, item_id), admin=True) assert_status_code_is_ok(response) return response.json()
def _assert_status_code_is_ok(self, response): assert_status_code_is_ok(response)