Skip to content

Commit

Permalink
Selenium - implement managed_history decorator for tests.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jmchilton committed Oct 2, 2017
1 parent 14d4367 commit 395eefc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions test/galaxy_selenium/navigates_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def api_get(self, endpoint, data={}, raw=False):
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":
Expand Down Expand Up @@ -215,6 +223,15 @@ def history_becomes_terminal(driver):
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)

Expand Down
22 changes: 22 additions & 0 deletions test/selenium_tests/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ def nottest(x):
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):

Expand Down
3 changes: 1 addition & 2 deletions test/selenium_tests/test_published_histories_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def setup_shared_state(self):

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')
Expand Down
3 changes: 1 addition & 2 deletions test/selenium_tests/test_saved_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ def setup_shared_state(self):

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"]' % \
Expand Down

0 comments on commit 395eefc

Please sign in to comment.