diff --git a/test/base/api.py b/test/base/api.py index c882f010163..116a5c83c14 100644 --- a/test/base/api.py +++ b/test/base/api.py @@ -10,7 +10,7 @@ from .api_asserts import ( ) from .api_util import get_master_api_key, get_user_api_key from .interactor import GalaxyInteractorApi as BaseInteractor -from .twilltestcase import FunctionalTestCase +from .testcase import FunctionalTestCase TEST_USER = "user@bx.psu.edu" ADMIN_TEST_USER = "test@bx.psu.edu" diff --git a/test/base/driver_util.py b/test/base/driver_util.py index d816f78cb6e..ec1411a4c21 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -21,7 +21,6 @@ import nose.loader import nose.plugins.manager from paste import httpserver -from functional import database_contexts from galaxy.app import UniverseApplication as GalaxyUniverseApplication from galaxy.util import asbool, download_to_file from galaxy.util.properties import load_app_properties @@ -54,6 +53,13 @@ DEFAULT_LOCALES = "en" log = logging.getLogger("test_driver") +# Global variables to pass database contexts around - only needed for older +# Tool Shed twill tests that didn't utilize the API for such interactions. +galaxy_context = None +tool_shed_context = None +install_context = None + + def setup_tool_shed_tmp_dir(): tool_shed_test_tmp_dir = os.environ.get('TOOL_SHED_TEST_TMP_DIR', None) if tool_shed_test_tmp_dir is None: @@ -480,8 +486,12 @@ def build_galaxy_app(simple_kwargs): # Build the Universe Application app = GalaxyUniverseApplication(**simple_kwargs) log.info("Embedded Galaxy application started") - database_contexts.galaxy_context = app.model.context - database_contexts.install_context = app.install_model.context + + global galaxy_context + global install_context + galaxy_context = app.model.context + install_context = app.install_model.context + return app @@ -497,8 +507,11 @@ def build_shed_app(simple_kwargs): simple_kwargs['global_conf'] = get_webapp_global_conf() app = ToolshedUniverseApplication(**simple_kwargs) - database_contexts.tool_shed_context = app.model.context log.info("Embedded Toolshed application started") + + global tool_shed_context + tool_shed_context = app.model.context + return app diff --git a/test/base/test_db_util.py b/test/base/test_db_util.py deleted file mode 100644 index 3c0af06053c..00000000000 --- a/test/base/test_db_util.py +++ /dev/null @@ -1,224 +0,0 @@ -from sqlalchemy import and_, desc, false - -import galaxy.model -from functional import database_contexts - -# Deprecated - import database_contexts and use galaxy_context -sa_session = database_contexts.galaxy_context - - -def gx_context(): - return database_contexts.galaxy_context - - -def delete_obj(obj): - gx_context().delete(obj) - gx_context().flush() - - -def delete_request_type_permissions(id): - rtps = gx_context().query(galaxy.model.RequestTypePermissions) \ - .filter(and_(galaxy.model.RequestTypePermissions.table.c.request_type_id == id)) \ - .order_by(desc(galaxy.model.RequestTypePermissions.table.c.create_time)) - for rtp in rtps: - gx_context().delete(rtp) - gx_context().flush() - - -def delete_user_roles(user): - for ura in user.roles: - gx_context().delete(ura) - gx_context().flush() - - -def flush(obj): - gx_context().add(obj) - gx_context().flush() - - -def get_all_histories_for_user(user): - return gx_context().query(galaxy.model.History) \ - .filter(and_(galaxy.model.History.table.c.user_id == user.id, - galaxy.model.History.table.c.deleted == false())) \ - .all() - - -def get_dataset_permissions_by_dataset(dataset): - return gx_context().query(galaxy.model.DatasetPermissions) \ - .filter(galaxy.model.DatasetPermissions.table.c.dataset_id == dataset.id) \ - .all() - - -def get_dataset_permissions_by_role(role): - return gx_context().query(galaxy.model.DatasetPermissions) \ - .filter(galaxy.model.DatasetPermissions.table.c.role_id == role.id) \ - .first() - - -def get_default_history_permissions_by_history(history): - return gx_context().query(galaxy.model.DefaultHistoryPermissions) \ - .filter(galaxy.model.DefaultHistoryPermissions.table.c.history_id == history.id) \ - .all() - - -def get_default_history_permissions_by_role(role): - return gx_context().query(galaxy.model.DefaultHistoryPermissions) \ - .filter(galaxy.model.DefaultHistoryPermissions.table.c.role_id == role.id) \ - .all() - - -def get_default_user_permissions_by_role(role): - return gx_context().query(galaxy.model.DefaultUserPermissions) \ - .filter(galaxy.model.DefaultUserPermissions.table.c.role_id == role.id) \ - .all() - - -def get_default_user_permissions_by_user(user): - return gx_context().query(galaxy.model.DefaultUserPermissions) \ - .filter(galaxy.model.DefaultUserPermissions.table.c.user_id == user.id) \ - .all() - - -def get_form(name): - fdc_list = gx_context().query(galaxy.model.FormDefinitionCurrent) \ - .filter(galaxy.model.FormDefinitionCurrent.table.c.deleted == false()) \ - .order_by(galaxy.model.FormDefinitionCurrent.table.c.create_time.desc()) - for fdc in fdc_list: - gx_context().refresh(fdc) - gx_context().refresh(fdc.latest_form) - if fdc.latest_form.name == name: - return fdc.latest_form - return None - - -def get_folder(parent_id, name, description): - return gx_context().query(galaxy.model.LibraryFolder) \ - .filter(and_(galaxy.model.LibraryFolder.table.c.parent_id == parent_id, - galaxy.model.LibraryFolder.table.c.name == name, - galaxy.model.LibraryFolder.table.c.description == description)) \ - .first() - - -def get_group_by_name(name): - return gx_context().query(galaxy.model.Group).filter(galaxy.model.Group.table.c.name == name).first() - - -def get_group_role_associations_by_group(group): - return gx_context().query(galaxy.model.GroupRoleAssociation) \ - .filter(galaxy.model.GroupRoleAssociation.table.c.group_id == group.id) \ - .all() - - -def get_group_role_associations_by_role(role): - return gx_context().query(galaxy.model.GroupRoleAssociation) \ - .filter(galaxy.model.GroupRoleAssociation.table.c.role_id == role.id) \ - .all() - - -def get_latest_dataset(): - return gx_context().query(galaxy.model.Dataset) \ - .order_by(desc(galaxy.model.Dataset.table.c.create_time)) \ - .first() - - -def get_latest_hda(): - return gx_context().query(galaxy.model.HistoryDatasetAssociation) \ - .order_by(desc(galaxy.model.HistoryDatasetAssociation.table.c.create_time)) \ - .first() - - -def get_latest_history_for_user(user): - return gx_context().query(galaxy.model.History) \ - .filter(and_(galaxy.model.History.table.c.deleted == false(), - galaxy.model.History.table.c.user_id == user.id)) \ - .order_by(desc(galaxy.model.History.table.c.create_time)) \ - .first() - - -def get_latest_ldda_by_name(name): - return gx_context().query(galaxy.model.LibraryDatasetDatasetAssociation) \ - .filter(and_(galaxy.model.LibraryDatasetDatasetAssociation.table.c.name == name, - galaxy.model.LibraryDatasetDatasetAssociation.table.c.deleted == false())) \ - .order_by(desc(galaxy.model.LibraryDatasetDatasetAssociation.table.c.create_time)) \ - .first() - - -def get_latest_lddas(limit): - return gx_context().query(galaxy.model.LibraryDatasetDatasetAssociation) \ - .order_by(desc(galaxy.model.LibraryDatasetDatasetAssociation.table.c.update_time)) \ - .limit(limit) - - -def get_library(name, description, synopsis): - return gx_context().query(galaxy.model.Library) \ - .filter(and_(galaxy.model.Library.table.c.name == name, - galaxy.model.Library.table.c.description == description, - galaxy.model.Library.table.c.synopsis == synopsis, - galaxy.model.Library.table.c.deleted == false())) \ - .first() - - -def get_private_role(user): - for role in user.all_roles(): - if role.name == user.email and role.description == 'Private Role for %s' % user.email: - return role - raise AssertionError("Private role not found for user '%s'" % user.email) - - -def get_request_by_name(name): - return gx_context().query(galaxy.model.Request) \ - .filter(and_(galaxy.model.Request.table.c.name == name, - galaxy.model.Request.table.c.deleted == false())) \ - .first() - - -def get_request_type_by_name(name): - return gx_context().query(galaxy.model.RequestType) \ - .filter(and_(galaxy.model.RequestType.table.c.name == name)) \ - .order_by(desc(galaxy.model.RequestType.table.c.create_time)) \ - .first() - - -def get_role_by_name(name): - return gx_context().query(galaxy.model.Role).filter(galaxy.model.Role.table.c.name == name).first() - - -def get_user(email): - return gx_context().query(galaxy.model.User) \ - .filter(galaxy.model.User.table.c.email == email) \ - .first() - - -def get_user_address(user, short_desc): - return gx_context().query(galaxy.model.UserAddress) \ - .filter(and_(galaxy.model.UserAddress.table.c.user_id == user.id, - galaxy.model.UserAddress.table.c.desc == short_desc, - galaxy.model.UserAddress.table.c.deleted == false())) \ - .order_by(desc(galaxy.model.UserAddress.table.c.create_time)) \ - .first() - - -def get_user_group_associations_by_group(group): - return gx_context().query(galaxy.model.UserGroupAssociation) \ - .filter(galaxy.model.UserGroupAssociation.table.c.group_id == group.id) \ - .all() - - -def get_user_info_form_definition(): - return galaxy.model.FormDefinition.types.USER_INFO - - -def get_user_role_associations_by_role(role): - return gx_context().query(galaxy.model.UserRoleAssociation) \ - .filter(galaxy.model.UserRoleAssociation.table.c.role_id == role.id) \ - .all() - - -def mark_obj_deleted(obj): - obj.deleted = True - gx_context().add(obj) - gx_context().flush() - - -def refresh(obj): - gx_context().refresh(obj) diff --git a/test/base/testcase.py b/test/base/testcase.py new file mode 100644 index 00000000000..8eaac18f2ca --- /dev/null +++ b/test/base/testcase.py @@ -0,0 +1,148 @@ +from __future__ import print_function + +import logging +import os +import time +import unittest +from json import loads + +from galaxy.tools.verify import verify +from galaxy.tools.verify.test_data import TestDataResolver +from galaxy.web import security + +from .driver_util import GalaxyTestDriver + +log = logging.getLogger(__name__) + +DEFAULT_TOOL_TEST_WAIT = os.environ.get("GALAXY_TEST_DEFAULT_WAIT", 86400) + + +class FunctionalTestCase(unittest.TestCase): + + def setUp(self): + # Security helper + self.security = security.SecurityHelper(id_secret='changethisinproductiontoo') + self.history_id = os.environ.get('GALAXY_TEST_HISTORY_ID', None) + self.host = os.environ.get('GALAXY_TEST_HOST') + self.port = os.environ.get('GALAXY_TEST_PORT') + default_url = "http://%s:%s" % (self.host, self.port) + self.url = os.environ.get('GALAXY_TEST_EXTERNAL', default_url) + self.test_data_resolver = TestDataResolver() + tool_shed_test_file = os.environ.get('GALAXY_TOOL_SHED_TEST_FILE', None) + if tool_shed_test_file: + f = open(tool_shed_test_file, 'r') + text = f.read() + f.close() + self.shed_tools_dict = loads(text) + else: + self.shed_tools_dict = {} + self.keepOutdir = os.environ.get('GALAXY_TEST_SAVE', '') + if self.keepOutdir > '': + try: + os.makedirs(self.keepOutdir) + except: + pass + + @classmethod + def setUpClass(cls): + """Configure and start Galaxy for a test.""" + cls._test_driver = None + + if not os.environ.get("GALAXY_TEST_ENVIRONMENT_CONFIGURED"): + cls._test_driver = GalaxyTestDriver() + cls._test_driver.setup(config_object=cls) + + @classmethod + def tearDownClass(cls): + """Shutdown Galaxy server and cleanup temp directory.""" + if cls._test_driver: + cls._test_driver.tear_down() + + def get_filename(self, filename, shed_tool_id=None): + # For tool tests override get_filename to point at an installed tool if shed_tool_id is set. + if shed_tool_id and getattr(self, "shed_tools_dict", None): + file_dir = self.shed_tools_dict[shed_tool_id] + if file_dir: + return os.path.abspath(os.path.join(file_dir, filename)) + return self.test_data_resolver.get_filename(filename) + + # TODO: Make this more generic, shouldn't be related to tool stuff I guess. + def wait_for(self, func, **kwd): + sleep_amount = 0.2 + slept = 0 + walltime_exceeded = kwd.get("maxseconds", None) + if walltime_exceeded is None: + walltime_exceeded = DEFAULT_TOOL_TEST_WAIT + + exceeded = True + while slept <= walltime_exceeded: + result = func() + if result: + time.sleep(sleep_amount) + slept += sleep_amount + sleep_amount *= 2 + else: + exceeded = False + break + + if exceeded: + message = 'Tool test run exceeded walltime [total %s, max %s], terminating.' % (slept, walltime_exceeded) + log.info(message) + raise AssertionError(message) + + # TODO: Move verify_xxx into GalaxyInteractor or some relevant mixin. + def verify_hid(self, filename, hda_id, attributes, shed_tool_id, hid="", dataset_fetcher=None): + assert dataset_fetcher is not None + + def get_filename(test_filename): + return self.get_filename(test_filename, shed_tool_id=shed_tool_id) + + def verify_extra_files(extra_files): + self._verify_extra_files_content(extra_files, hda_id, shed_tool_id=shed_tool_id, dataset_fetcher=dataset_fetcher) + + data = dataset_fetcher(hda_id) + item_label = "History item %s" % hid + verify( + item_label, + data, + attributes=attributes, + filename=filename, + get_filename=get_filename, + keep_outputs_dir=self.keepOutdir, + verify_extra_files=verify_extra_files, + ) + + def _verify_composite_datatype_file_content(self, file_name, hda_id, base_name=None, attributes=None, dataset_fetcher=None, shed_tool_id=None): + assert dataset_fetcher is not None + + def get_filename(test_filename): + return self.get_filename(test_filename, shed_tool_id=shed_tool_id) + + data = dataset_fetcher(hda_id, base_name) + item_label = "History item %s" % hda_id + try: + verify( + item_label, + data, + attributes=attributes, + filename=file_name, + get_filename=get_filename, + keep_outputs_dir=self.keepOutdir, + ) + except AssertionError as err: + errmsg = 'Composite file (%s) of %s different than expected, difference:\n' % (base_name, item_label) + errmsg += str(err) + raise AssertionError(errmsg) + + def _verify_extra_files_content(self, extra_files, hda_id, dataset_fetcher, shed_tool_id=None): + files_list = [] + for extra_type, extra_value, extra_name, extra_attributes in extra_files: + if extra_type == 'file': + files_list.append((extra_name, extra_value, extra_attributes)) + elif extra_type == 'directory': + for filename in os.listdir(self.get_filename(extra_value, shed_tool_id=shed_tool_id)): + files_list.append((filename, os.path.join(extra_value, filename), extra_attributes)) + else: + raise ValueError('unknown extra_files type: %s' % extra_type) + for filename, filepath, attributes in files_list: + self._verify_composite_datatype_file_content(filepath, hda_id, base_name=filename, attributes=attributes, dataset_fetcher=dataset_fetcher, shed_tool_id=shed_tool_id) diff --git a/test/base/tool_shed_util.py b/test/base/tool_shed_util.py index 5782003b21f..f783e11c479 100644 --- a/test/base/tool_shed_util.py +++ b/test/base/tool_shed_util.py @@ -1,11 +1,7 @@ import logging import os -import sys -galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) -sys.path.insert(1, os.path.join(galaxy_root, 'lib')) - -from galaxy.util import parse_xml +from galaxy.util import galaxy_root_path, parse_xml log = logging.getLogger(__name__) @@ -64,7 +60,7 @@ def parse_tool_panel_config(config, shed_tools_dict): has_test_data = True if galaxy_test_file_dir != last_galaxy_test_file_dir: if not os.path.isabs(galaxy_test_file_dir): - galaxy_test_file_dir = os.path.join(galaxy_root, galaxy_test_file_dir) + galaxy_test_file_dir = os.path.join(galaxy_root_path, galaxy_test_file_dir) guid = elem.get('guid') shed_tools_dict[guid] = galaxy_test_file_dir last_galaxy_test_file_dir = galaxy_test_file_dir @@ -83,7 +79,7 @@ def parse_tool_panel_config(config, shed_tools_dict): has_test_data = True if galaxy_test_file_dir != last_galaxy_test_file_dir: if not os.path.isabs(galaxy_test_file_dir): - galaxy_test_file_dir = os.path.join(galaxy_root, galaxy_test_file_dir) + galaxy_test_file_dir = os.path.join(galaxy_root_path, galaxy_test_file_dir) guid = section_elem.get('guid') shed_tools_dict[guid] = galaxy_test_file_dir last_galaxy_test_file_dir = galaxy_test_file_dir diff --git a/test/functional/database_contexts.py b/test/functional/database_contexts.py deleted file mode 100644 index 502f303333c..00000000000 --- a/test/functional/database_contexts.py +++ /dev/null @@ -1,6 +0,0 @@ -# Global variables to pass database contexts around. Fairly hackish that they -# are shared this way, but at least they have been moved out of Galaxy's lib/ -# code base. -galaxy_context = None -tool_shed_context = None -install_context = None diff --git a/test/functional/test_library_templates.py b/test/functional/test_library_templates.py deleted file mode 100644 index 72c20ce179d..00000000000 --- a/test/functional/test_library_templates.py +++ /dev/null @@ -1,1132 +0,0 @@ -import time - -import pyparsing # noqa: F401 -import twill.commands as tc -from markupsafe import escape - -import galaxy.model -from base.test_db_util import ( - get_folder, - get_form, - get_latest_hda, - get_latest_ldda_by_name, - get_library, - get_private_role, - get_user, - get_user_address, - mark_obj_deleted, - refresh -) -from base.twilltestcase import TwillTestCase - -AddressField_form = None -CheckboxField_form = None -SelectField_form = None -TextArea_form = None -TextField_form = None -WorkflowField_form = None -address_field_name = checkbox_field_name = select_field_name = None -workflow_field_name = textfield_name = textarea_name = None -user_address1 = user_address2 = None -ldda1 = library1 = library2 = library3 = library4 = library5 = library6 = None -folder1 = folder2 = folder3 = folder4 = folder5 = folder6 = None -admin_user = None -regular_user1 = regular_user2 = regular_user3 = None - - -class TestLibraryFeatures(TwillTestCase): - - def add_folder(self, cntrller, library_id, folder_id, name='Folder One', description='This is Folder One'): - """Create a new folder""" - url = "%s/library_common/create_folder?cntrller=%s&library_id=%s&parent_id=%s" % (self.url, cntrller, library_id, folder_id) - self.visit_url(url) - self.check_page_for_string('Create a new folder') - tc.fv("1", "name", name) - tc.fv("1", "description", description) - tc.submit("new_folder_button") - check_str = escape("The new folder named '%s' has been added to the data library." % name) - self.check_page_for_string(check_str) - - def add_template(self, cntrller, item_type, form_type, form_id, form_name, - library_id=None, folder_id=None, ldda_id=None, request_type_id=None, sample_id=None): - """ - Add a new template to an item - for library items, the template will ALWAYS BE SET TO INHERITABLE here. If you want to - dis-inherit your template, call the manage_library_template_inheritance() below immediately after you call this - method in your test code. Templates added to Requesttype objects are always inherited to samples. - """ - params = dict(cntrller=cntrller, item_type=item_type, form_type=form_type, library_id=library_id) - url = "/library_common/add_template" - if item_type == 'folder': - params['folder_id'] = folder_id - elif item_type == 'ldda': - params['ldda_id'] = ldda_id - self.visit_url(url, params) - self.check_page_for_string("Select a template for the") - self.refresh_form("form_id", form_id) - # For some unknown reason, twill barfs if the form number ( 1 ) is used in the following - # rather than the form anme ( select_template ), so we have to use the form name. - tc.fv("select_template", "inheritable", '1') - tc.submit("add_template_button") - self.check_page_for_string = 'A template based on the form "%s" has been added to this' % form_name - - def browse_library(self, cntrller, library_id, show_deleted=False, strings_displayed=[], strings_not_displayed=[]): - self.visit_url('%s/library_common/browse_library?cntrller=%s&id=%s&show_deleted=%s' % (self.url, cntrller, library_id, str(show_deleted))) - for check_str in strings_displayed: - self.check_page_for_string(check_str) - for check_str in strings_not_displayed: - try: - self.check_page_for_string(check_str) - raise AssertionError("String (%s) incorrectly displayed when browsing library." % check_str) - except: - pass - - def create_library(self, name='Library One', description='This is Library One', synopsis='Synopsis for Library One'): - """Create a new library""" - self.visit_url("%s/library_admin/create_library" % self.url) - self.check_page_for_string('Create a new data library') - tc.fv("1", "name", name) - tc.fv("1", "description", description) - tc.fv("1", "synopsis", synopsis) - tc.submit("create_library_button") - check_str = escape("The new library named '%s' has been created" % name) - self.check_page_for_string(check_str) - - def create_form(self, name, description, form_type, field_type='TextField', form_layout_name='', - num_fields=1, num_options=0, field_name='1_field_name', strings_displayed=[], - strings_displayed_after_submit=[]): - """Create a new form definition.""" - self.visit_url("%s/forms/create_form_definition" % self.url) - for check_str in strings_displayed: - self.check_page_for_string(check_str) - tc.fv("create_form_definition", "name", name) - tc.fv("create_form_definition", "description", description) - tc.fv("create_form_definition", "form_type_select_field", form_type) - tc.submit("create_form_button") - if form_type == "Sequencing Sample Form": - tc.submit("add_layout_grid") - tc.fv("edit_form_definition", "grid_layout0", form_layout_name) - # if not adding any fields at this time, remove the default empty field - if num_fields == 0: - tc.submit("remove_button") - # Add fields to the new form definition - for index1 in range(num_fields): - field_label = 'field_label_%i' % index1 - field_contents = field_type - field_help_name = 'field_helptext_%i' % index1 - field_help_contents = 'Field %i help' % index1 - field_default = 'field_default_0' - field_default_contents = '%s default contents' % form_type - tc.fv("edit_form_definition", field_label, field_contents) - tc.fv("edit_form_definition", field_help_name, field_help_contents) - if field_type == 'SelectField': - # SelectField field_type requires a refresh_on_change - self.refresh_form('field_type_0', field_type) - # Add options so our select list is functional - if num_options == 0: - # Default to 2 options - num_options = 2 - for index2 in range(1, num_options + 1): - tc.submit("addoption_0") - # Add contents to the new options fields - for index2 in range(num_options): - option_field_name = 'field_0_option_%i' % index2 - option_field_value = 'Option%i' % index2 - tc.fv("edit_form_definition", option_field_name, option_field_value) - else: - tc.fv("edit_form_definition", "field_type_0", field_type) - tc.fv("edit_form_definition", 'field_name_0', field_name) - tc.fv("edit_form_definition", field_default, field_default_contents) - # All done... now save - tc.submit("save_changes_button") - for check_str in strings_displayed_after_submit: - self.check_page_for_string(check_str) - - def delete_library_item(self, cntrller, library_id, item_id, item_name, item_type='library_dataset'): - """Mark a library item as deleted""" - params = dict(cntrller=cntrller, library_id=library_id, item_id=item_id, item_type=item_type) - self.visit_url("/library_common/delete_library_item", params) - if item_type == 'library_dataset': - item_desc = 'Dataset' - else: - item_desc = item_type.capitalize() - check_str = "marked deleted" - self.check_for_strings(strings_displayed=[item_desc, check_str]) - - def edit_template(self, cntrller, item_type, form_type, library_id, field_type, field_label_1, field_helptext_1, field_default_1, - folder_id='', ldda_id='', action='add_field'): - """Edit the form fields defining a library template""" - params = dict(cntrller=cntrller, item_type=item_type, form_type=form_type, library_id=library_id) - self.visit_url("/library_common/edit_template", params=params) - self.check_page_for_string("Edit form definition") - if action == 'add_field': - tc.submit("add_field_button") - tc.fv("edit_form", "field_label_1", field_label_1) - tc.fv("edit_form", "field_helptext_1", field_helptext_1) - if field_type == 'SelectField': - # Performs a refresh_on_change in this case - self.refresh_form("field_type_1", field_type) - else: - tc.fv("edit_form", "field_type_1", field_type) - tc.fv("edit_form", "field_default_1", field_default_1) - tc.submit('save_changes_button') - self.check_page_for_string("The template for this data library has been updated with your changes.") - - def folder_info(self, cntrller, folder_id, library_id, name='', new_name='', description='', template_refresh_field_name='1_field_name', - template_refresh_field_contents='', template_fields=[], strings_displayed=[], strings_not_displayed=[], - strings_displayed_after_submit=[], strings_not_displayed_after_submit=[]): - """Add information to a library using an existing template with 2 elements""" - self.visit_url("%s/library_common/folder_info?cntrller=%s&id=%s&library_id=%s" % - (self.url, cntrller, folder_id, library_id)) - if name and new_name and description: - tc.fv('1', "name", new_name) - tc.fv('1', "description", description) - tc.submit('rename_folder_button') - for check_str in strings_displayed: - self.check_page_for_string(check_str) - for check_str in strings_not_displayed: - try: - self.check_page_for_string(check_str) - raise AssertionError("String (%s) incorrectly displayed." % check_str) - except: - pass - if template_refresh_field_contents: - # A template containing an AddressField is displayed on the form, so we need to refresh the form - # with the received template_refresh_field_contents. There are 2 forms on the folder_info page - # when in edit mode, and the 2nd one is the one we want. - self.refresh_form(template_refresh_field_name, template_refresh_field_contents, form_no=2) - if template_fields: - # We have an information template associated with the folder, so - # there are 2 forms on this page and the template is the 2nd form - for field_name, field_value in template_fields: - tc.fv("edit_info", field_name, field_value) - tc.submit('edit_info_button') - for check_str in strings_displayed_after_submit: - self.check_page_for_string(check_str) - for check_str in strings_not_displayed_after_submit: - try: - self.check_page_for_string(check_str) - raise AssertionError("String (%s) incorrectly displayed." % check_str) - except: - pass - - def ldda_edit_info(self, cntrller, library_id, folder_id, ldda_id, ldda_name, new_ldda_name='', template_refresh_field_name='1_field_name', - template_refresh_field_contents='', template_fields=[], strings_displayed=[], strings_not_displayed=[]): - """Edit library_dataset_dataset_association information, optionally template element information""" - self.visit_url("%s/library_common/ldda_edit_info?cntrller=%s&library_id=%s&folder_id=%s&id=%s" % - (self.url, cntrller, library_id, folder_id, ldda_id)) - check_str = 'Edit attributes of %s' % ldda_name - self.check_page_for_string(check_str) - if new_ldda_name: - tc.fv('1', 'name', new_ldda_name) - tc.submit('save') - check_str = escape("Attributes updated for library dataset '%s'." % new_ldda_name) - self.check_page_for_string(check_str) - if template_refresh_field_contents: - # A template containing an AddressField is displayed on the upload form, so we need to refresh the form - # with the received template_refresh_field_contents. There are 4 forms on this page, and the template is - # contained in the 4th form named "edit_info". - self.refresh_form(template_refresh_field_name, template_refresh_field_contents, form_no=4) - if template_fields: - # We have an information template associated with the folder, so - # there are 2 forms on this page and the template is the 2nd form - for field_name, field_value in template_fields: - tc.fv("edit_info", field_name, field_value) - tc.submit('edit_info_button') - for check_str in strings_displayed: - self.check_page_for_string(check_str) - for check_str in strings_not_displayed: - try: - self.check_page_for_string(check_str) - raise AssertionError("String (%s) should not have been displayed on ldda Edit Attributes page." % check_str) - except: - pass - - def library_info(self, cntrller, library_id, library_name='', new_name='', new_description='', new_synopsis='', - template_fields=[], strings_displayed=[]): - """Edit information about a library, optionally using an existing template with up to 2 elements""" - self.visit_url("%s/library_common/library_info?cntrller=%s&id=%s" % (self.url, cntrller, library_id)) - for check_str in strings_displayed: - self.check_page_for_string(check_str) - if new_name and new_description and new_synopsis: - tc.fv('1', 'name', new_name) - tc.fv('1', 'description', new_description) - tc.fv('1', 'synopsis', new_synopsis) - tc.submit('library_info_button') - self.check_page_for_string("Information updated for library") - if template_fields: - for field_name, field_value in template_fields: - # The 2nd form on the page contains the template, and the form is named edit_info. - # Set the template field value - tc.fv("edit_info", field_name, field_value) - tc.submit('edit_info_button') - - def library_wait(self, library_id, cntrller='library_admin', maxiter=90): - """Waits for the tools to finish""" - count = 0 - sleep_amount = 1 - while count < maxiter: - count += 1 - self.visit_url("%s/library_common/browse_library?cntrller=%s&id=%s" % (self.url, cntrller, library_id)) - page = tc.browser.get_html() - if page.find('') > -1: - time.sleep(sleep_amount) - sleep_amount += 1 - else: - break - self.assertNotEqual(count, maxiter) - - def manage_library_template_inheritance(self, cntrller, item_type, library_id, folder_id=None, ldda_id=None, inheritable=True): - # If inheritable is True, the item is currently inheritable. - if item_type == 'library': - url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s" % \ - (self.url, cntrller, item_type, library_id) - elif item_type == 'folder': - url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s" % \ - (self.url, cntrller, item_type, library_id, folder_id) - elif item_type == 'ldda': - url = "%s/library_common/manage_template_inheritance?cntrller=%s&item_type=%s&library_id=%s&folder_id=%s&ldda_id=%s" % \ - (self.url, cntrller, item_type, library_id, folder_id, ldda_id) - self.visit_url(url) - if inheritable: - self.check_page_for_string = 'will no longer be inherited to contained folders and datasets' - else: - self.check_page_for_string = 'will now be inherited to contained folders and datasets' - - def mark_form_deleted(self, form_id): - """Mark a form_definition as deleted""" - url = "%s/forms/delete_form_definition?id=%s" % (self.url, form_id) - self.visit_url(url) - check_str = "1 forms have been deleted." - self.check_page_for_string(check_str) - - def purge_library(self, library_id, library_name): - """Purge a library""" - params = dict(id=library_id) - self.visit_url("/library_admin/purge_library", params) - check_str = "Library '%s' and all of its contents have been purged" % library_name - self.check_page_for_string(check_str) - - def upload_library_dataset(self, cntrller, library_id, folder_id, filename='', server_dir='', replace_id='', - upload_option='upload_file', file_type='auto', dbkey='hg18', space_to_tab='', - link_data_only='copy_files', preserve_dirs='Yes', filesystem_paths='', roles=[], - ldda_message='', hda_ids='', template_refresh_field_name='1_field_name', - template_refresh_field_contents='', template_fields=[], show_deleted='False', strings_displayed=[]): - """Add datasets to library using any upload_option""" - # NOTE: due to the library_wait() method call at the end of this method, no tests should be done - # for strings_displayed_after_submit. - params = dict(cntrller=cntrller, library_id=library_id, folder_id=folder_id) - url = "/library_common/upload_library_dataset" - if replace_id: - # If we're uploading a new version of a library dataset, we have to include the replace_id param in the - # request because the form field named replace_id will not be displayed on the upload form if we dont. - params['replace_id'] = replace_id - self.visit_url(url, params=params) - if template_refresh_field_contents: - # A template containing an AddressField is displayed on the upload form, so we need to refresh the form - # with the received template_refresh_field_contents. - self.refresh_form(template_refresh_field_name, template_refresh_field_contents) - for tup in template_fields: - tc.fv("1", tup[0], tup[1]) - tc.fv("upload_library_dataset", "library_id", library_id) - tc.fv("upload_library_dataset", "folder_id", folder_id) - tc.fv("upload_library_dataset", "show_deleted", show_deleted) - tc.fv("upload_library_dataset", "ldda_message", ldda_message) - tc.fv("upload_library_dataset", "file_type", file_type) - tc.fv("upload_library_dataset", "dbkey", dbkey) - if space_to_tab: - tc.fv("upload_library_dataset", "space_to_tab", space_to_tab) - for role_id in roles: - tc.fv("upload_library_dataset", "roles", role_id) - # Refresh the form by selecting the upload_option - we do this here to ensure - # all previously entered form contents are retained. - self.refresh_form('upload_option', upload_option) - if upload_option == 'import_from_history': - for check_str in strings_displayed: - self.check_page_for_string(check_str) - if hda_ids: - # Twill cannot handle multi-checkboxes, so the form can only have 1 hda_ids checkbox - try: - tc.fv("add_history_datasets_to_library", "hda_ids", hda_ids) - except: - tc.fv("add_history_datasets_to_library", "hda_ids", '1') - tc.submit('add_history_datasets_to_library_button') - else: - if upload_option in ['upload_paths', 'upload_directory']: - tc.fv("upload_library_dataset", "link_data_only", link_data_only) - if upload_option == 'upload_paths': - tc.fv("upload_library_dataset", "filesystem_paths", filesystem_paths) - if upload_option == 'upload_directory' and server_dir: - tc.fv("upload_library_dataset", "server_dir", server_dir) - if upload_option == 'upload_file': - if filename: - filename = self.get_filename(filename) - tc.formfile("upload_library_dataset", "files_0|file_data", filename) - for check_str in strings_displayed: - self.check_page_for_string(check_str) - tc.submit("runtool_btn") - # Give the files some time to finish uploading - self.library_wait(library_id) - - def view_form(self, id, form_type='', form_name='', form_desc='', form_layout_name='', field_dicts=[]): - '''View form details''' - self.visit_url("%s/forms/view_latest_form_definition?id=%s" % (self.url, id)) - # self.check_page_for_string( form_type ) - self.check_page_for_string(form_name) - # self.check_page_for_string( form_desc ) - self.check_page_for_string(form_layout_name) - for i, field_dict in enumerate(field_dicts): - self.check_page_for_string(field_dict['label']) - self.check_page_for_string(field_dict['desc']) - self.check_page_for_string(field_dict['type']) - if field_dict['type'].lower() == 'selectfield': - for option_index, option in enumerate(field_dict['selectlist']): - self.check_page_for_string(option) - - def upload_file(self, filename, ftype='auto', dbkey='unspecified (?)', space_to_tab=False, metadata=None, composite_data=None, name=None, wait=True): - """ - Uploads a file. If shed_tool_id has a value, we're testing tools migrated from the distribution to the tool shed, - so the tool-data directory of test data files is contained in the installed tool shed repository. - """ - self.visit_url("%s/tool_runner?tool_id=upload1" % self.url) - try: - self.refresh_form("file_type", ftype) # Refresh, to support composite files - tc.fv("tool_form", "dbkey", dbkey) - if metadata: - for elem in metadata: - tc.fv("tool_form", "files_metadata|%s" % elem.get('name'), elem.get('value')) - if composite_data: - for i, composite_file in enumerate(composite_data): - filename = self.get_filename(composite_file.get('value')) - tc.formfile("tool_form", "files_%i|file_data" % i, filename) - tc.fv("tool_form", "files_%i|space_to_tab" % i, composite_file.get('space_to_tab', False)) - else: - filename = self.get_filename(filename) - tc.formfile("tool_form", "file_data", filename) - tc.fv("tool_form", "space_to_tab", space_to_tab) - if name: - # NAME is a hidden form element, so the following prop must - # set to use it. - tc.config("readonly_controls_writeable", 1) - tc.fv("tool_form", "NAME", name) - tc.submit("runtool_btn") - except AssertionError as err: - errmsg = "Uploading file resulted in the following exception. Make sure the file (%s) exists. " % filename - errmsg += str(err) - raise AssertionError(errmsg) - if not wait: - return - # Make sure every history item has a valid hid - hids = self.get_hids_in_history(self.get_latest_history()['id']) - for hid in hids: - try: - int(hid) - except: - raise AssertionError("Invalid hid (%s) created when uploading file %s" % (hid, filename)) - # Wait for upload processing to finish (TODO: this should be done in each test case instead) - self.wait() - - def test_000_initiate_users(self): - """Ensuring all required user accounts exist""" - self.login(email='test1@bx.psu.edu', username='regular-user1') - global regular_user1 - regular_user1 = get_user('test1@bx.psu.edu') - assert regular_user1 is not None, 'Problem retrieving user with email "test1@bx.psu.edu" from the database' - global regular_user1_private_role - regular_user1_private_role = get_private_role(regular_user1) - self.login(email='test2@bx.psu.edu', username='regular-user2') - global regular_user2 - regular_user2 = get_user('test2@bx.psu.edu') - assert regular_user2 is not None, 'Problem retrieving user with email "test2@bx.psu.edu" from the database' - global regular_user2_private_role - regular_user2_private_role = get_private_role(regular_user2) - self.login(email='test3@bx.psu.edu', username='regular-user3') - global regular_user3 - regular_user3 = get_user('test3@bx.psu.edu') - assert regular_user3 is not None, 'Problem retrieving user with email "test3@bx.psu.edu" from the database' - global regular_user3_private_role - regular_user3_private_role = get_private_role(regular_user3) - self.login(email='test@bx.psu.edu', username='admin-user') - global admin_user - admin_user = get_user('test@bx.psu.edu') - assert admin_user is not None, 'Problem retrieving user with email "test@bx.psu.edu" from the database' - global admin_user_private_role - admin_user_private_role = get_private_role(admin_user) - - def test_005_create_library_templates(self): - """Testing creating several LibraryInformationTemplate form definitions""" - # Logged in as admin_user - for type in ['AddressField', 'CheckboxField', 'SelectField', 'TextArea', 'TextField', 'WorkflowField']: - field_name = type.lower() - form_desc = '%s description' % type - num_options = 0 - if type == 'SelectField': - # Pass number of options we want in our SelectField - num_options = 2 - # Create form for library template - strings_displayed_after_submit = ["The form '%s' has been updated with the changes." % type] - self.create_form(name=type, - description=form_desc, - form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE, - field_type=type, - num_options=num_options, - field_name=field_name, - strings_displayed_after_submit=strings_displayed_after_submit) - # Get all of the new form definitions for later use - global AddressField_form - AddressField_form = get_form('AddressField') - # NOTE: each of these names need to be the same as field_name defined above - # for each type. - global address_field_name - address_field_name = 'addressfield' - - global CheckboxField_form - CheckboxField_form = get_form('CheckboxField') - global checkbox_field_name - checkbox_field_name = 'checkboxfield' - - global SelectField_form - SelectField_form = get_form('SelectField') - global select_field_name - select_field_name = 'selectfield' - - global TextArea_form - TextArea_form = get_form('TextArea') - global textarea_name - textarea_name = 'textarea' - - global TextField_form - TextField_form = get_form('TextField') - global textfield_name - textfield_name = 'textfield' - - global WorkflowField_form - WorkflowField_form = get_form('WorkflowField') - global workflow_field_name - workflow_field_name = 'workflowfield' - - def test_010_create_libraries(self): - """Testing creating a new library for each template""" - # Logged in as admin_user - # library1 -> AddressField - # library2 -> CheckboxField - # library3 -> SelectField - # library4 -> TextArea - # library5 -> TextField - # library6 -> WorkflowField - for index, form in enumerate([AddressField_form, CheckboxField_form, SelectField_form, TextArea_form, TextField_form, WorkflowField_form]): - name = 'library%s' % str(index + 1) - description = '%s description' % name - synopsis = '%s synopsis' % name - self.create_library(name=name, description=description, synopsis=synopsis) - # Get the libraries for later use - global library1 - library1 = get_library('library1', 'library1 description', 'library1 synopsis') - global library2 - library2 = get_library('library2', 'library2 description', 'library2 synopsis') - global library3 - library3 = get_library('library3', 'library3 description', 'library3 synopsis') - global library4 - library4 = get_library('library4', 'library4 description', 'library4 synopsis') - global library5 - library5 = get_library('library5', 'library5 description', 'library5 synopsis') - global library6 - library6 = get_library('library6', 'library6 description', 'library6 synopsis') - - def test_015_add_template_to_library1(self): - """Testing add an inheritable template containing an AddressField to library1""" - # Logged in as admin_user - # Add a template containing an AddressField to library1 - self.add_template(cntrller='library_admin', - item_type='library', - form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE, - form_id=self.security.encode_id(AddressField_form.id), - form_name=AddressField_form.name, - library_id=self.security.encode_id(library1.id)) - - def test_020_add_folder_to_library1(self): - """Testing adding a folder to library1""" - # Logged in as admin_user - # Add a folder to library1 - folder = library1.root_folder - name = "folder" - description = "folder description" - self.add_folder('library_admin', - self.security.encode_id(library1.id), - self.security.encode_id(folder.id), - name=name, - description=description) - global folder1 - folder1 = get_folder(folder.id, name, description) - - def test_025_check_library1(self): - """Checking library1 and its root folder""" - # Logged in as admin_user - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library1.id), - strings_displayed=[folder1.name, folder1.description]) - # Make sure the template and contents were inherited to folder1 - self.folder_info(cntrller='library_admin', - folder_id=self.security.encode_id(folder1.id), - library_id=self.security.encode_id(library1.id), - template_refresh_field_name=address_field_name, - strings_displayed=[AddressField_form.name, - 'This is an inherited template and is not required to be used with this folder']) - - def test_030_add_dataset_to_folder1(self): - """Testing adding a ldda1 to folder1, and adding a new UserAddress on the upload form.""" - # Logged in as admin_user - # The AddressField template should be inherited to the library dataset upload form. Passing - # the value 'new' should submit the form via refresh_on_change and allow new UserAddress information - # to be posted as part of the upload. - filename = '1.bed' - ldda_message = '1.bed message' - short_desc = 'Office' - self.upload_library_dataset(cntrller='library_admin', - library_id=self.security.encode_id(library1.id), - folder_id=self.security.encode_id(folder1.id), - filename=filename, - file_type='bed', - dbkey='hg18', - template_refresh_field_name=address_field_name, - ldda_message=ldda_message, - template_refresh_field_contents='new', - template_fields=[('%s_short_desc' % address_field_name, short_desc), - ('%s_name' % address_field_name, 'Dick'), - ('%s_institution' % address_field_name, 'PSU'), - ('%s_address' % address_field_name, '32 O Street'), - ('%s_city' % address_field_name, 'Anywhere'), - ('%s_state' % address_field_name, 'AK'), - ('%s_postal_code' % address_field_name, '0000000'), - ('%s_country' % address_field_name, 'USA')], - strings_displayed=['Upload files']) - global user_address1 - user_address1 = get_user_address(admin_user, short_desc) - assert user_address1 is not None, 'Problem retrieving user_address1 from the database' - global ldda1 - ldda1 = get_latest_ldda_by_name(filename) - assert ldda1 is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda1 from the database' - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library1.id), - strings_displayed=[ldda1.name, ldda1.message, 'bed']) - # Make sure the library template contents were correctly saved - self.ldda_edit_info('library_admin', - self.security.encode_id(library1.id), - self.security.encode_id(folder1.id), - self.security.encode_id(ldda1.id), - ldda1.name, - strings_displayed=['Dick']) - - def test_035_edit_contents_of_ldda1_tempplate(self): - """Testing editing the contents of ldda1 AddressField template by adding a new user_address""" - short_desc = 'Home' - # Now add a new user_address to ldda1 - self.ldda_edit_info('library_admin', - self.security.encode_id(library1.id), - self.security.encode_id(folder1.id), - self.security.encode_id(ldda1.id), - ldda1.name, - template_refresh_field_name=address_field_name, - template_refresh_field_contents='new', - template_fields=[('%s_short_desc' % address_field_name, short_desc), - ('%s_name' % address_field_name, 'Richard'), - ('%s_institution' % address_field_name, 'PSU'), - ('%s_address' % address_field_name, '32 O Street'), - ('%s_city' % address_field_name, 'Anywhere'), - ('%s_state' % address_field_name, 'AK'), - ('%s_postal_code' % address_field_name, '0000000'), - ('%s_country' % address_field_name, 'USA')], - strings_displayed=[short_desc]) - global user_address2 - user_address2 = get_user_address(admin_user, short_desc) - assert user_address2 is not None, 'Problem retrieving user_address2 from the database' - - def test_040_edit_contents_of_folder1_template(self): - """Testing editing the contents of folder1 AddressField template""" - # Make sure the template and contents were inherited to folder1 - self.folder_info(cntrller='library_admin', - folder_id=self.security.encode_id(folder1.id), - library_id=self.security.encode_id(library1.id), - template_refresh_field_name=address_field_name, - template_refresh_field_contents=str(user_address2.id), - strings_displayed=[AddressField_form.name, - 'This is an inherited template and is not required to be used with this folder'], - strings_displayed_after_submit=['Richard']) - - def test_045_add_dataset_to_folder1(self): - """Testing adding another ldda to folder1""" - # The upload form should now inherit user_address2 on the upload form - filename = '2.bed' - ldda_message = '2.bed message' - self.upload_library_dataset(cntrller='library_admin', - library_id=self.security.encode_id(library1.id), - folder_id=self.security.encode_id(folder1.id), - filename=filename, - file_type='bed', - dbkey='hg18', - template_refresh_field_name=address_field_name, - ldda_message=ldda_message, - strings_displayed=['Upload files']) - # Make sure user_address2 is associated with ldda. - self.ldda_edit_info(cntrller='library_admin', - library_id=self.security.encode_id(library1.id), - folder_id=self.security.encode_id(folder1.id), - ldda_id=self.security.encode_id(ldda1.id), - ldda_name=ldda1.name, - template_refresh_field_name=address_field_name, - strings_displayed=[user_address2.desc]) - - def test_050_add_template_to_library2(self): - """ Testing add an inheritable template containing an CheckboxField to library2""" - # Add a template containing an CheckboxField to library1 - self.add_template(cntrller='library_admin', - item_type='library', - form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE, - form_id=self.security.encode_id(CheckboxField_form.id), - form_name=CheckboxField_form.name, - library_id=self.security.encode_id(library2.id)) - # Check the CheckboxField to make sure the template contents are inherited - self.library_info('library_admin', - self.security.encode_id(library2.id), - template_fields=[(checkbox_field_name, '1')]) - - def test_055_add_folder2_to_library2(self): - """Testing adding a folder to library2""" - # Logged in as admin_user - # Add a folder to library2 - folder = library2.root_folder - name = "folder" - description = "folder description" - self.add_folder('library_admin', - self.security.encode_id(library2.id), - self.security.encode_id(folder.id), - name=name, - description=description) - global folder2 - folder2 = get_folder(folder.id, name, description) - - def test_060_check_library2(self): - """Checking library2 and its root folder""" - # Logged in as admin_user - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library2.id), - strings_displayed=[folder2.name, folder2.description]) - - def test_065_save_folder2_inherited_template(self): - """Saving the inherited template for folder2""" - # Logged in as admin_user - # Save the inherited template - self.folder_info(cntrller='library_admin', - folder_id=self.security.encode_id(folder2.id), - library_id=self.security.encode_id(library2.id), - template_fields=[(checkbox_field_name, '1')], - strings_displayed=[CheckboxField_form.name, - 'This is an inherited template and is not required to be used with this folder']) - - def test_070_add_ldda_to_folder2(self): - """ - Testing adding a new library dataset to library2's folder, making sure the CheckboxField is - checked on the upload form. - """ - # Logged in as admin_user - filename = '1.bed' - ldda_message = '1.bed message' - self.upload_library_dataset(cntrller='library_admin', - library_id=self.security.encode_id(library2.id), - folder_id=self.security.encode_id(folder2.id), - filename=filename, - file_type='bed', - dbkey='hg18', - ldda_message=ldda_message, - strings_displayed=['CheckboxField', 'checked']) - ldda = get_latest_ldda_by_name(filename) - assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library2.id), - strings_displayed=[ldda.name, ldda.message, 'bed']) - # Make sure the library template contents were correctly saved - self.ldda_edit_info('library_admin', - self.security.encode_id(library2.id), - self.security.encode_id(folder2.id), - self.security.encode_id(ldda.id), - ldda.name, - strings_displayed=['CheckboxField', 'checked']) - - def test_080_add_template_to_library3(self): - """ Testing add an inheritable template containing an SelectField to library3""" - # Logged in as admin_user - self.add_template(cntrller='library_admin', - item_type='library', - form_type=galaxy.model.FormDefinition.types.LIBRARY_INFO_TEMPLATE, - form_id=self.security.encode_id(SelectField_form.id), - form_name=SelectField_form.name, - library_id=self.security.encode_id(library3.id)) - # Select the 2nd option in the SelectField to make sure the template contents are inherited - # SelectField option names are zero-based - self.library_info('library_admin', - self.security.encode_id(library3.id), - template_fields=[(select_field_name, 'Option1')]) - - def test_085_add_folder3_to_library3(self): - """Testing adding a folder to library3""" - # Logged in as admin_user - # Add a folder to library3 - folder = library3.root_folder - name = "folder" - description = "folder description" - self.add_folder('library_admin', - self.security.encode_id(library3.id), - self.security.encode_id(folder.id), - name=name, - description=description) - global folder3 - folder3 = get_folder(folder.id, name, description) - - def test_090_check_library3(self): - """Checking library3 and its root folder""" - # Logged in as admin_user - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library3.id), - strings_displayed=[folder3.name, folder3.description]) - - def test_095_save_folder3_inherited_template(self): - """Saving the inherited template for folder3""" - # Logged in as admin_user - # Save the inherited template - self.folder_info(cntrller='library_admin', - folder_id=self.security.encode_id(folder3.id), - library_id=self.security.encode_id(library3.id), - template_fields=[(select_field_name, 'Option1')], - strings_displayed=[SelectField_form.name, - 'This is an inherited template and is not required to be used with this folder', - 'Option1']) - - def test_100_add_ldda_to_folder3(self): - """ - Testing adding a new library dataset to library3's folder, making sure the SelectField setting is correct on the upload form. - """ - filename = '3.bed' - ldda_message = '3.bed message' - # Logged in as admin_user - self.upload_library_dataset(cntrller='library_admin', - library_id=self.security.encode_id(library3.id), - folder_id=self.security.encode_id(folder3.id), - filename=filename, - file_type='bed', - dbkey='hg18', - ldda_message=ldda_message, - strings_displayed=['SelectField', 'selected>Option1']) - ldda = get_latest_ldda_by_name(filename) - assert ldda is not None, 'Problem retrieving LibraryDatasetDatasetAssociation ldda from the database' - self.browse_library(cntrller='library_admin', - library_id=self.security.encode_id(library3.id), - strings_displayed=[ldda.name, ldda.message, 'bed']) - # Make sure the library template contents were correctly saved - self.ldda_edit_info('library_admin', - self.security.encode_id(library3.id), - self.security.encode_id(folder3.id), - self.security.encode_id(ldda.id), - ldda.name, - strings_displayed=['SelectField', 'Option1']) - # Import a dataset from the current history - filename = '8.bed' - self.new_history(name='import+with+SelectField') - self.upload_file(filename) - hda = get_latest_hda() - self.upload_library_dataset(cntrller='library_admin', - library_id=self.security.encode_id(library3.id), - folder_id=self.security.encode_id(folder3.id), - upload_option='import_from_history', - hda_ids=self.security.encode_id(hda.id), - strings_displayed=['