From 395eefcbb250ea682f27b4056a48ed416abd935c Mon Sep 17 00:00:00 2001 From: John Chilton Date: Sun, 24 Sep 2017 15:13:17 -0400 Subject: [PATCH] Selenium - implement managed_history decorator for tests. Creates and deletes a history for tests - good for tests meant to aim at production servers that need to have useful metadata and need to be cleaned up. --- test/galaxy_selenium/navigates_galaxy.py | 17 ++++++++++++++ test/selenium_tests/framework.py | 22 +++++++++++++++++++ .../test_published_histories_grid.py | 3 +-- test/selenium_tests/test_saved_histories.py | 3 +-- 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/test/galaxy_selenium/navigates_galaxy.py b/test/galaxy_selenium/navigates_galaxy.py index 0a90a39ae31..e7b39eb378e 100644 --- a/test/galaxy_selenium/navigates_galaxy.py +++ b/test/galaxy_selenium/navigates_galaxy.py @@ -162,6 +162,14 @@ class NavigatesGalaxy(HasDriver): else: return response.json() + def api_delete(self, endpoint, raw=False): + full_url = self.build_url("api/" + endpoint, for_selenium=False) + response = requests.get(full_url, cookies=self.selenium_to_requests_cookies()) + if raw: + return response + else: + return response.json() + def get_galaxy_session(self): for cookie in self.driver.get_cookies(): if cookie["name"] == "galaxysession": @@ -215,6 +223,15 @@ class NavigatesGalaxy(HasDriver): assert final_state == "ok", final_state return final_state + def history_panel_create_new_with_name(self, name): + self.history_panel_create_new() + self.history_panel_rename(name) + + def history_panel_create_new(self): + """Click create new and pause a bit for the history to begin to refresh.""" + self.click_history_option('Create New') + self.sleep_for(WAIT_TYPES.UX_RENDER) + def history_panel_wait_for_hid_ok(self, hid, allowed_force_refreshes=0): self.history_panel_wait_for_hid_state(hid, 'ok', allowed_force_refreshes=allowed_force_refreshes) diff --git a/test/selenium_tests/framework.py b/test/selenium_tests/framework.py index d99f0d0dc24..3cc9a5f35b3 100644 --- a/test/selenium_tests/framework.py +++ b/test/selenium_tests/framework.py @@ -60,6 +60,28 @@ except ImportError: return x +def managed_history(f): + """Ensure a Selenium test has a distinct, named history. + + Cleanup the history after the job is complete as well unless + GALAXY_TEST_NO_CLEANUP is set in the environment. + """ + + @wraps(f) + def func_wrapper(self, *args, **kwds): + self.home() + history_name = f.__name__ + datetime.datetime.now().strftime("%Y%m%d%H%M%s") + self.history_panel_create_new_with_name(history_name) + try: + f(self, *args, **kwds) + finally: + if "GALAXY_TEST_NO_CLEANUP" not in os.environ: + current_history_id = self.current_history_id() + self.api_delete("histories/%s" % current_history_id) + + return func_wrapper + + @nottest def selenium_test(f): diff --git a/test/selenium_tests/test_published_histories_grid.py b/test/selenium_tests/test_published_histories_grid.py index 85c6a654567..a3a313e914a 100644 --- a/test/selenium_tests/test_published_histories_grid.py +++ b/test/selenium_tests/test_published_histories_grid.py @@ -200,8 +200,7 @@ class HistoryGridTestCase(SharedStateSeleniumTestCase): def create_history(self, name): self.home() - self.click_history_option('Create New') - self.history_panel_rename(name) + self.history_panel_create_new_with_name(name) def publish_current_history(self): self.click_history_option('Share or Publish') diff --git a/test/selenium_tests/test_saved_histories.py b/test/selenium_tests/test_saved_histories.py index a05d6946699..09df23619eb 100644 --- a/test/selenium_tests/test_saved_histories.py +++ b/test/selenium_tests/test_saved_histories.py @@ -297,8 +297,7 @@ class SavedHistoriesTestCase(SharedStateSeleniumTestCase): def create_history(self, name): self.home() - self.click_history_option('Create New') - self.history_panel_rename(name) + self.history_panel_create_new_with_name(name) def select_filter(self, filter_key, filter_value): filter_selector = 'a[filter_key="%s"][filter_val="%s"]' % \