summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-28 01:16:02 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-11-16 17:04:41 +0100
commitac787b47e28c09f7cfd8ff4636e7928988bcf16e (patch)
tree8efbcc1456a00c57e896691a9e27360fad389b3c /ishtar_common/tests.py
parent10b70e48f0bbf8b37a9073749b530ab3180c399d (diff)
downloadIshtar-ac787b47e28c09f7cfd8ff4636e7928988bcf16e.tar.bz2
Ishtar-ac787b47e28c09f7cfd8ff4636e7928988bcf16e.zip
synthethic functions for tests and improvement of their robustness
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py77
1 files changed, 61 insertions, 16 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 2049b7828..08b28d8de 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -3621,10 +3621,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(
@@ -3634,29 +3633,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
@@ -3675,6 +3719,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: