toaster/tests: Add and use wait_until_element_visible()
PATCH 1/2 toaster/tests: Add and use wait_until_element_visible()
In this test case there are multiple elements matching the selector so the usual wait function isn't effective. Switch to waiting on the element directly, adding a new function to allow us to do so.
This function is probably needed in other unreliable places in the tests too.
Signed-off-by Richard Purdie <[email protected]>
--- lib/toaster/tests/browser/selenium_helpers_base.py | 7 +++++++ lib/toaster/tests/browser/test_layerdetails_page.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)
lib/toaster/tests/browser/selenium_helpers_base.py +7 -0
@@ -218,6 +218,13 @@ class SeleniumTestCaseBase(unittest.TestCase): element = Wait(self.driver, timeout=timeout).until(is_present, msg) return element + def wait_until_element_visible(self, element, timeout=Wait._TIMEOUT): + """ Wait until element matching CSS selector is visible on the page """ + is_visible = lambda driver: element.is_displayed() + msg = 'An element should be visible' + Wait(self.driver, timeout=timeout).until(is_visible, msg) + return + def wait_until_visible(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is visible on the page """ is_visible = lambda driver: self.find(selector).is_displayed()
lib/toaster/tests/browser/test_layerdetails_page.py +1 -1
@@ -100,7 +100,7 @@ class TestLayerDetailsPage(SeleniumTestCase): (self.initial_values, value)) # Make sure the input visible beofre sending keys - self.wait_until_clickable("#layer-git input[type=text]") + self.wait_until_element_visible(inputs) inputs.send_keys("-edited") # Save the new values
PATCH 2/2 toaster/orm/lsupdates: Improve error handling
Recent layer index changes are causing a KeyError in this code. Rather than crash and break everything, show a warning and move on, which unbreaks everything else, just skipping the problematic distro entry.
Signed-off-by Richard Purdie <[email protected]>
--- .../orm/management/commands/lsupdates.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-)
lib/toaster/orm/management/commands/lsupdates.py +12 -8
@@ -226,14 +226,18 @@ class Command(BaseCommand): total = len(index.distros) for i, id in enumerate(index.distros): - distro, created = Distro.objects.get_or_create( - name=index.distros[id].name, - layer_version=Layer_Version.objects.get( - pk=li_layer_branch_id_to_toaster_lv_id[index.distros[id].layerbranch_id])) - distro.up_date = index.distros[id].updated - distro.name = index.distros[id].name - distro.description = index.distros[id].description - distro.save() + try: + distro, created = Distro.objects.get_or_create( + name=index.distros[id].name, + layer_version=Layer_Version.objects.get( + pk=li_layer_branch_id_to_toaster_lv_id[index.distros[id].layerbranch_id])) + distro.up_date = index.distros[id].updated + distro.name = index.distros[id].name + distro.description = index.distros[id].description + distro.save() + except KeyError as e: + logger.warning("Couldn't process %s (%s)" % (i, repr(e))) + continue self.mini_progress("distros", i, total) # update machines