Skip to contentSkip to conversation

toaster/tests: Add and use wait_until_element_visible()

PATCH New Richard Purdie 1 participant 2 messages Aug 28

lore
Share & tools
lore
#0 lore raw

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.

---
 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
index 6953541ab55..a901791aa16 100644
@@ -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
index 6abfdef6999..0b45ca6e0f1 100644
@@ -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
#1 lore raw

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.

---
 .../orm/management/commands/lsupdates.py      | 20 +++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
lib/toaster/orm/management/commands/lsupdates.py +12 -8
index 153b26f60a5..1f36906eeef 100644
@@ -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