summaryrefslogtreecommitdiff
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-09-01 12:36:46 +0200
commit46d9f7a8eb6df547ecdfb441ff60efdd34f13296 (patch)
treeecdd8ad3966eb7e182258840f6c501c50b1505c4
parent2433d6ad42e3347706b55b5f482d68e1ee1e4653 (diff)
downloadIshtar-46d9f7a8eb6df547ecdfb441ff60efdd34f13296.tar.bz2
Ishtar-46d9f7a8eb6df547ecdfb441ff60efdd34f13296.zip
synthethic functions for tests and improvement of their robustness
-rw-r--r--archaeological_context_records/tests.py75
-rw-r--r--archaeological_finds/tests.py114
-rw-r--r--archaeological_operations/tests.py43
-rw-r--r--ishtar_common/tests.py77
4 files changed, 161 insertions, 148 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index a99fbefe6..85011a7bf 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -1380,40 +1380,9 @@ class GraphGenerationTest(ContextRecordInit, TestCase):
class SeleniumTestsContextRecords(SeleniumTests):
fixtures = CONTEXT_RECORD_FIXTURES
- def _test_cr(self, i, pks, geojsons, method=None):
- if method == "from operation":
- tbody = "." + "/div" * 6 + "/table/tbody"
- title = self.selenium.find_element_by_xpath(
- '//h3[contains(text(), "Unité d\'Enregistrement") or contains(text(), "Context record")]'
- )
- panel = title.find_element_by_xpath("./..")
- details = panel.find_element_by_xpath(
- tbody + "/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- label = panel.find_element_by_xpath(
- tbody + "/tr[" + str(i) + "]/td[2]"
- ).text
- details.click()
- else:
- tbody = "./form" + "/div" * 7 + "/table/tbody"
- title = '//h3[text()="Rechercher une unité d\'enregistrement" or text()="Context record search"]'
- self.WebDriverWait(self.selenium, self.waiting_time).until(
- lambda driver: driver.find_element_by_xpath(title)
- )
- title = self.selenium.find_element_by_xpath(title)
- panel = title.find_element_by_xpath("./..")
- details = panel.find_element_by_xpath(
- tbody + "/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
- label = self.selenium.find_element_by_xpath(
- '//small[@title="ID interne" or @title="Internal ID"]'
- ).text
- label = label[1:]
- cr = models.ContextRecord.objects.get(pk=pks[label])
- slug_pk = str(cr.SLUG) + "-" + str(cr.pk)
+ def _test_cr(self, xpath, slug_pk, geojsons):
+ self.wait_and_click(xpath)
+ label = self.label_from_internal_id(slug_pk)
base = copy.deepcopy(geojsons[label]["get_polys"])
@@ -1497,24 +1466,30 @@ class SeleniumTestsContextRecords(SeleniumTests):
self.assertMap(base, slug_pk)
def test_geo_items(self):
- pks, geojsons = self.pks_and_geojson()
+ geojsons = self.default_geojson()
# from operation
- for i in range(1, 3):
- self.access_from_dropdown('operation')
- details = self.selenium.find_element_by_xpath(
- "//tbody/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
+ self.access_from_dropdown("operation")
+ for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
+ self.access_from_dropdown("operation")
+ self.wait_and_click(ope_xpath)
self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(text(), "Unités d\'Enregistrement") or contains(text(), "Context records")]'
+ '//ul[@role="tablist"]/li/a[contains(@id, "cr-tab")][contains(@id, "operation-'
+ + str(ope_pk)
+ + '")]'
).click()
- for j in range(1, 3):
- self._test_cr(j, pks, copy.deepcopy(geojsons), method="from operation")
+ for pk, xpath in self.pks_and_details_from_table(
+ "contextrecord", "operation"
+ ):
+ slug_pk = "contextrecord-" + str(pk)
+ self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
# from search bar
- for i in range(1, 5):
- self.access_from_dropdown('record')
- self._test_cr(i, pks, copy.deepcopy(geojsons))
+ self.access_from_dropdown("record")
+ from_table = self.pks_and_details_from_table("contextrecord")
+ for pk, xpath in from_table:
+ self.access_from_dropdown("record")
+ slug_pk = "contextrecord-" + str(pk)
+ self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
# from bottom table, multiple displays
- for i in range(1, 4):
- self._test_cr(i, pks, copy.deepcopy(geojsons))
+ for pk, xpath in from_table:
+ slug_pk = "contextrecord-" + str(pk)
+ self._test_cr(xpath, slug_pk, copy.deepcopy(geojsons))
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index afc8a0f7e..4c640b88a 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -2839,35 +2839,9 @@ class TemplateTest(FindInit, TestCase):
class SeleniumTestsBaseFinds(SeleniumTests):
fixtures = FIND_FIXTURES
- def _test_bf(self, i, pks, geojsons, from_search=False):
- title = self.selenium.find_element_by_xpath(
- '//h3[contains(text(), "Mobilier") or contains(text(), "Find")]'
- )
- panel = title.find_element_by_xpath("./..")
- if from_search:
- tbody = "./form" + "/div" * 7 + "/table/tbody"
- else:
- tbody = "." + "/div" * 6 + "/table/tbody"
- details = panel.find_element_by_xpath(
- tbody + "/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
- label = None
- t = time()
- while not label and time() - t < self.waiting_time:
- for internalId in self.selenium.find_elements_by_xpath(
- '//small[@title="ID interne" or @title="Internal ID"]'
- ):
- if "Find" in internalId.text:
- label = internalId.text
- break
- label = label.split("-")
- self.assertEqual(len(label), 3)
- label = label[2]
-
- bf = models.BaseFind.objects.get(pk=pks[label])
- slug_pk = bf.SLUG + "-" + str(bf.pk)
+ def _test_bf(self, xpath, slug_pk, geojsons):
+ self.wait_and_click(xpath)
+ label = self.label_from_internal_id(slug_pk)
bf_base = geojsons[label]["get_polys"]
self.assertMap(bf_base, slug_pk)
@@ -2881,37 +2855,63 @@ class SeleniumTestsBaseFinds(SeleniumTests):
self.assertNotInDOM(get_poly)
def test_geo_items(self):
- pks, geojsons = self.pks_and_geojson()
+ geojsons = self.default_geojson()
# from operation
- for i in range(1, 3):
- self.access_from_dropdown('operation')
- details = self.selenium.find_element_by_xpath(
- "//tbody/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
+ self.access_from_dropdown("operation")
+ for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
+ self.access_from_dropdown("operation")
+ self.wait_and_click(ope_xpath)
self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(text(), "Mobilier") or contains(text(), "Finds")]'
+ '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "operation-'
+ + str(ope_pk)
+ + '")]'
).click()
- for j in range(1, 5):
- self._test_bf(j, pks, copy.deepcopy(geojsons))
+ for pk, xpath in self.pks_and_details_from_table("find", "operation"):
+ slug_pk = "find-" + str(pk)
+ self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
# from context record
- for i in range(1, 5):
- self.access_from_dropdown('record')
- details = self.selenium.find_element_by_xpath(
- "//tbody/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
+ self.access_from_dropdown("record")
+ for cr_pk, cr_xpath in self.pks_and_details_from_table("record"):
+ self.access_from_dropdown("record")
+ self.wait_and_click(cr_xpath)
+ self.selenium.find_element_by_xpath(
+ '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "contextrecord-'
+ + str(cr_pk)
+ + '")]'
+ ).click()
+ for pk, xpath in self.pks_and_details_from_table("find", "record"):
+ slug_pk = "find-" + str(pk)
+ self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
+ # from context record from operation
+ self.access_from_dropdown("operation")
+ for ope_pk, ope_xpath in self.pks_and_details_from_table("operation"):
+ self.access_from_dropdown("operation")
+ self.wait_and_click(ope_xpath)
self.selenium.find_element_by_xpath(
- '//ul[@role="tablist"]/li/a[contains(text(), "Mobilier") or contains(text(), "Finds")]'
+ '//ul[@role="tablist"]/li/a[contains(@id, "cr-tab")][contains(@id, "operation-'
+ + str(ope_pk)
+ + '")]'
).click()
- for j in range(1, 3):
- self._test_bf(j, pks, copy.deepcopy(geojsons))
- # from search
- for i in range(1, 9):
- self.access_from_dropdown('find')
- self._test_bf(i, pks, copy.deepcopy(geojsons), from_search=True)
- # from bottom table
- for i in range(1, 8):
- self._test_bf(i, pks, copy.deepcopy(geojsons), from_search=True)
+ for cr_pk, cr_xpath in self.pks_and_details_from_table(
+ "record", "operation"
+ ):
+ self.wait_and_click(cr_xpath)
+ self.selenium.find_element_by_xpath(
+ '//ul[@role="tablist"]/li/a[contains(@id, "finds-tab")][contains(@id, "contextrecord-'
+ + str(cr_pk)
+ + '")]'
+ ).click()
+ for pk, xpath in self.pks_and_details_from_table("find", "record"):
+ slug_pk = "find-" + str(pk)
+ self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
+ # from search bar
+ self.access_from_dropdown("find")
+ from_table = self.pks_and_details_from_table("find")
+ for pk, xpath in from_table:
+ self.access_from_dropdown("find")
+ slug_pk = "find-" + str(pk)
+ self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
+ # from bottom table, multiple displays
+ for pk, xpath in from_table:
+ slug_pk = "find-" + str(pk)
+ self._test_bf(xpath, slug_pk, copy.deepcopy(geojsons))
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 75ded665c..4112fc91b 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -4193,7 +4193,10 @@ class DocumentQATest(OperationInitTest, TestCase):
class SeleniumTestsOperations(SeleniumTests):
fixtures = OPERATION_FIXTURES
- def _test_operation(self, i, slug_pk, geojsons, label):
+ def _test_operation(self, xpath, slug_pk, geojsons):
+ self.wait_and_click(xpath)
+ label = self.label_from_internal_id(slug_pk)
+
get_poly_id = "get-poly-for-" + slug_pk
get_poly_label_id = "get-poly-label-for-" + slug_pk
disp_cr_id = "disp-cr-for-" + slug_pk
@@ -4226,16 +4229,7 @@ class SeleniumTestsOperations(SeleniumTests):
}
ope_base = geojsons[label]["get_polys"]
- title = self.selenium.find_element_by_xpath(
- '//h3[text()="Rechercher une opération" or text()="Operation search"]'
- )
- panel = title.find_element_by_xpath("./..")
- tbody = "./form" + "/div" * 7 + "/table/tbody"
- details = panel.find_element_by_xpath(
- tbody + "/tr[" + str(i) + ']/td/a[@class="display_details"]'
- )
- self.scroll(details)
- details.click()
+
self.WebDriverWait(self.selenium, self.waiting_time).until(
lambda driver: driver.find_element_by_xpath(
'//dl[@class="col-12"]/dt[@id="display-geo-items-for-' + slug_pk + '"]'
@@ -4337,17 +4331,16 @@ class SeleniumTestsOperations(SeleniumTests):
self.assertMap(ope_base, slug_pk)
def test_geo_items(self):
- pks, geojsons = self.pks_and_geojson()
-
- self.access_from_dropdown('operation')
- ope = models.Operation.objects.get(pk=pks["Poly"])
- slug_pk_poly = ope.SLUG + "-" + str(ope.pk)
- self._test_operation(2, slug_pk_poly, copy.deepcopy(geojsons), "Poly")
-
- self.access_from_dropdown('operation')
- ope = models.Operation.objects.get(pk=pks["Pt"])
- slug_pk_pt = ope.SLUG + "-" + str(ope.pk)
- self._test_operation(1, slug_pk_pt, copy.deepcopy(geojsons), "Pt")
-
- # display both at the same time (1 is already displayed)
- self._test_operation(2, slug_pk_poly, geojsons, "Poly")
+ geojsons = self.default_geojson()
+ slug = "operation"
+ self.access_from_dropdown(slug)
+ from_table = self.pks_and_details_from_table(slug)
+ for pk, xpath in from_table:
+ self.access_from_dropdown(slug)
+ slug_pk = slug + "-" + str(pk)
+ self._test_operation(xpath, slug_pk, copy.deepcopy(geojsons))
+ # display both at the same time
+ self.access_from_dropdown(slug)
+ for pk, xpath in from_table:
+ slug_pk = slug + "-" + str(pk)
+ self._test_operation(xpath, slug_pk, copy.deepcopy(geojsons))
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: