diff options
| author | Quentin André <quentin.andre@imt-atlantique.net> | 2021-08-28 01:16:02 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:48 +0200 | 
| commit | daf84f5465aa3a29e268dc6a2d6b50f64bfae341 (patch) | |
| tree | 3a2f1ac43f256fc52a04a0ef67f1ec424d9c94cb /ishtar_common | |
| parent | c1f12a9f4b6d724b6db3bed8e429118288933584 (diff) | |
| download | Ishtar-daf84f5465aa3a29e268dc6a2d6b50f64bfae341.tar.bz2 Ishtar-daf84f5465aa3a29e268dc6a2d6b50f64bfae341.zip  | |
synthethic functions for tests and improvement of their robustness
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/tests.py | 77 | 
1 files changed, 61 insertions, 16 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 8aef93b32..736deb1e4 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -3701,10 +3701,9 @@ class SeleniumTests(StaticLiveServerTestCase):      def setUpDefaultGeoItems(self):          return GeomaticTest.setUpDefaultGeoItems(self.user) -    def pks_and_geojson(self): +    def default_geojson(self):          geoms, pks = self.setUpDefaultGeoItems() -        geojsons = GeomaticTest.geojson_geo_items(geoms, pks) -        return pks, geojsons +        return GeomaticTest.geojson_geo_items(geoms, pks)      def scroll(self, element):          self.selenium.execute_script( @@ -3714,29 +3713,74 @@ class SeleniumTests(StaticLiveServerTestCase):              element,          ) -    def access_from_dropdown(self, slug): -        if slug == 'contextrecord': -            slug = 'record' -        if slug == 'basefind': -            slug = 'find' +    def wait_and_click(self, xpath):          self.WebDriverWait(self.selenium, self.waiting_time).until( -            lambda driver: driver.find_element_by_xpath( -                '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]' -            ) +            self.EC.visibility_of_element_located((self.By.XPATH, xpath))          ) -        dropdown = self.selenium.find_element_by_xpath( +        el = self.selenium.find_element_by_xpath(xpath) +        self.scroll(el) +        el.click() + +    def access_from_dropdown(self, slug): +        if slug == "contextrecord": +            slug = "record" +        if slug == "basefind": +            slug = "find" +        self.wait_and_click(              '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]'          ) -        self.scroll(dropdown) -        dropdown.click()          self.selenium.find_element_by_xpath(              '//div[@class="dropdown-menu show"]/a[@href="/' + slug + '_search/"]'          ).click() +    def pks_and_details_from_table(self, slug, source=None): +        res = [] +        xpath = "//table" +        keywords = ["find", "record", "operation"] +        for key in keywords: +            if key in slug or (source and key in source): +                xpath += '[contains(@id, "' + key + '")]' +            else: +                xpath += '[not(contains(@id, "' + key + '"))]' +        xpath += ( +            '/tbody/tr/td/a[@class="display_details"][@href="#"][contains(@onclick, "' +            + slug +            + '")]' +        ) +        for el in self.selenium.find_elements_by_xpath(xpath): +            pk = int(re.findall(r"\d+", el.get_attribute("onclick"))[-1]) +            res.append([pk, xpath + '[contains(@onclick, "' + str(pk) + '")]']) +        return res + +    def label_from_internal_id(self, slug_pk): +        xpath = '//div[contains(@id, "' +        if slug_pk[:3] == "ope": +            xpath += slug_pk + '")]' + "/div" * 5 +        elif slug_pk[:7] == "context": +            xpath += slug_pk + '")]' + "/div" * 3 +        else: +            xpath += slug_pk[4:] + '")]' +        xpath += '/p/small[@title="ID interne" or @title="Internal ID"]' +        self.WebDriverWait(self.selenium, self.waiting_time).until( +            self.EC.visibility_of_element_located((self.By.XPATH, xpath)) +        ) +        label = self.selenium.find_element_by_xpath(xpath).text +        if slug_pk[:3] == "ope": +            if label == "2": +                label = "Poly" +            else: +                label = "Pt" +        elif slug_pk[:7] == "context": +            label = label[1:] +        else: +            label = label.split("-") +            label = label[2] +        return label +      def assertNotInDOM(self, xpath): -        self.selenium.implicitly_wait(self.waiting_time / 5) +        self.selenium.implicitly_wait(self.waiting_time / 10)          try: -            self.WebDriverWait(self.selenium, self.waiting_time / 5).until( +            self.WebDriverWait(self.selenium, self.waiting_time / 10).until(                  self.EC.visibility_of_element_located((self.By.XPATH, xpath))              )              found = True @@ -3755,6 +3799,7 @@ class SeleniumTests(StaticLiveServerTestCase):                  if slug_pk in mapdiv.get_attribute("id"):                      mapid = mapdiv.get_attribute("id")                      break +        self.assertIsNotNone(mapid, "Timeout, no mapid found")          id = int(re.search(r"\d+$", mapid).group())          # TODO: use the map and not the map_features in the js function          if features_collecs:  | 
