Skip to content

Commit

Permalink
Test case for link_to_files during upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Jan 6, 2018
1 parent dd86476 commit 73ff3df
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 23 deletions.
4 changes: 4 additions & 0 deletions test/base/populators.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ def create_dataset_request(self, library, **kwds):
"file_type": kwds.get("file_type", "auto"),
"db_key": kwds.get("db_key", "?"),
}
if kwds.get("link_data"):
create_data["link_data_only"] = "link_to_files"

if upload_option == "upload_file":
files = {
Expand All @@ -553,7 +555,9 @@ def new_library_dataset(self, name, **create_dataset_kwds):
library = self.new_private_library(name)
payload, files = self.create_dataset_request(library, **create_dataset_kwds)
dataset = self.raw_library_contents_create(library["id"], payload, files=files).json()[0]
return self.wait_on_library_dataset(library, dataset)

def wait_on_library_dataset(self, library, dataset):
def show():
return self.galaxy_interactor.get("libraries/%s/contents/%s" % (library["id"], dataset["id"]))

Expand Down
81 changes: 58 additions & 23 deletions test/integration/test_upload_configuration_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ def fetch_target(self, target, assert_ok=False, attach_test_file=False):
response = self.dataset_populator.fetch(payload, assert_ok=assert_ok)
return response

@classmethod
def temp_config_dir(cls, name):
return os.path.join(cls._test_driver.galaxy_test_tmp_dir, name)

def _write_file(self, dir_path, content, filename="test"):
"""Helper for writing ftp/server dir files."""
self._ensure_directory(dir_path)
path = os.path.join(dir_path, filename)
with open(path, "w") as f:
f.write(content)
return path

def _ensure_directory(self, path):
if not os.path.exists(path):
os.makedirs(path)


class InvalidFetchRequestsTestCase(BaseUploadContentConfigurationTestCase):

Expand Down Expand Up @@ -314,25 +330,14 @@ def handle_extra_ftp_config(cls, config):

@classmethod
def ftp_dir(cls):
return os.path.join(cls._test_driver.galaxy_test_tmp_dir, "ftp")
return cls.temp_config_dir("ftp")

def _check_content(self, dataset, content, ext="txt"):
dataset = self.dataset_populator.get_history_dataset_details(self.history_id, dataset=dataset)
assert dataset["file_ext"] == ext, dataset
content = self.dataset_populator.get_history_dataset_content(self.history_id, dataset=dataset)
assert content == content, content

def _write_ftp_file(self, dir_path, content, filename="test"):
self._ensure_directory(dir_path)
path = os.path.join(dir_path, filename)
with open(path, "w") as f:
f.write(content)
return path

def _ensure_directory(self, path):
if not os.path.exists(path):
os.makedirs(path)

def _get_user_ftp_path(self):
return os.path.join(self.ftp_dir(), TEST_USER)

Expand All @@ -342,7 +347,7 @@ class SimpleFtpUploadConfigurationTestCase(BaseFtpUploadConfigurationTestCase):
def test_ftp_upload(self):
content = "hello world\n"
dir_path = self._get_user_ftp_path()
ftp_path = self._write_ftp_file(dir_path, content)
ftp_path = self._write_file(dir_path, content)
ftp_files = self.dataset_populator.get_remote_files()
assert len(ftp_files) == 1, ftp_files
assert ftp_files[0]["path"] == "test"
Expand All @@ -358,7 +363,7 @@ def test_ftp_upload(self):
def test_ftp_fetch(self):
content = "hello world\n"
dir_path = self._get_user_ftp_path()
ftp_path = self._write_ftp_file(dir_path, content)
ftp_path = self._write_file(dir_path, content)
ftp_files = self.dataset_populator.get_remote_files()
assert len(ftp_files) == 1, ftp_files
assert ftp_files[0]["path"] == "test"
Expand Down Expand Up @@ -412,7 +417,7 @@ def handle_extra_ftp_config(cls, config):
def test_ftp_uploads_not_purged(self):
content = "hello world\n"
dir_path = os.path.join(self.ftp_dir(), TEST_USER)
ftp_path = self._write_ftp_file(dir_path, content)
ftp_path = self._write_file(dir_path, content)
ftp_files = self.dataset_populator.get_remote_files()
assert len(ftp_files) == 1
assert ftp_files[0]["path"] == "test"
Expand All @@ -430,9 +435,9 @@ class AdvancedFtpUploadFetchTestCase(BaseFtpUploadConfigurationTestCase):

def test_fetch_ftp_directory(self):
dir_path = self._get_user_ftp_path()
self._write_ftp_file(os.path.join(dir_path, "subdir"), "content 1", filename="1")
self._write_ftp_file(os.path.join(dir_path, "subdir"), "content 22", filename="2")
self._write_ftp_file(os.path.join(dir_path, "subdir"), "content 333", filename="3")
self._write_file(os.path.join(dir_path, "subdir"), "content 1", filename="1")
self._write_file(os.path.join(dir_path, "subdir"), "content 22", filename="2")
self._write_file(os.path.join(dir_path, "subdir"), "content 333", filename="3")
target = {
"destination": {"type": "hdca"},
"elements_from": "directory",
Expand All @@ -450,9 +455,9 @@ def test_fetch_ftp_directory(self):

def test_fetch_nested_elements_from(self):
dir_path = self._get_user_ftp_path()
self._write_ftp_file(os.path.join(dir_path, "subdir1"), "content 1", filename="1")
self._write_ftp_file(os.path.join(dir_path, "subdir1"), "content 22", filename="2")
self._write_ftp_file(os.path.join(dir_path, "subdir2"), "content 333", filename="3")
self._write_file(os.path.join(dir_path, "subdir1"), "content 1", filename="1")
self._write_file(os.path.join(dir_path, "subdir1"), "content 22", filename="2")
self._write_file(os.path.join(dir_path, "subdir2"), "content 333", filename="3")
elements = [
{"name": "subdirel1", "src": "ftp_import", "ftp_path": "subdir1", "elements_from": "directory", "collection_type": "list"},
{"name": "subdirel2", "src": "ftp_import", "ftp_path": "subdir2", "elements_from": "directory", "collection_type": "list"},
Expand Down Expand Up @@ -578,7 +583,7 @@ def _copy_to_user_ftp_file(self, test_data_path):
shutil.copyfile(input_path, os.path.join(target_dir, test_data_path))

def _write_user_ftp_file(self, path, content):
return self._write_ftp_file(os.path.join(self.ftp_dir(), TEST_USER), content, filename=path)
return self._write_file(os.path.join(self.ftp_dir(), TEST_USER), content, filename=path)


class ServerDirectoryOffByDefaultTestCase(BaseUploadContentConfigurationTestCase):
Expand All @@ -603,12 +608,42 @@ class ServerDirectoryValidUsageTestCase(BaseUploadContentConfigurationTestCase):

require_admin_user = True

@classmethod
def handle_galaxy_config_kwds(cls, config):
server_dir = cls.server_dir()
os.makedirs(server_dir)
config["library_import_dir"] = server_dir

@classmethod
def server_dir(cls):
return cls.temp_config_dir("server")

def test_valid_server_dir_uploads_okay(self):
content = "hello world\n"
dir_path = os.path.join(self.server_dir(), "lib1")
self._write_file(dir_path, content)
library = self.library_populator.new_private_library("serverdirupload")
# upload $GALAXY_ROOT/test-data/library
payload, files = self.library_populator.create_dataset_request(library, upload_option="upload_directory", server_dir="library")
payload, files = self.library_populator.create_dataset_request(library, upload_option="upload_directory", server_dir="lib1")
response = self.library_populator.raw_library_contents_create(library["id"], payload, files=files)
assert response.status_code == 200, response.json()
dataset = response.json()[0]
ok_dataset = self.library_populator.wait_on_library_dataset(library, dataset)
assert ok_dataset["file_size"] == 12, ok_dataset

def link_data_only(self):
content = "hello world\n"
dir_path = os.path.join(self.server_dir(), "lib1")
file_path = self._write_file(dir_path, content)
library = self.library_populator.new_private_library("serverdirupload")
# upload $GALAXY_ROOT/test-data/library
payload, files = self.library_populator.create_dataset_request(library, upload_option="upload_directory", server_dir="lib1", link_data=True)
response = self.library_populator.raw_library_contents_create(library["id"], payload, files=files)
assert response.status_code == 200, response.json()
dataset = response.json()[0]
ok_dataset = self.library_populator.wait_on_library_dataset(library, dataset)
assert ok_dataset["file_size"] == 12, ok_dataset
assert ok_dataset["file_name"] == file_path, ok_dataset


class ServerDirectoryRestrictedToAdminsUsageTestCase(BaseUploadContentConfigurationTestCase):
Expand Down

0 comments on commit 73ff3df

Please sign in to comment.