diff options
Diffstat (limited to 'archaeological_finds/tests.py')
-rw-r--r-- | archaeological_finds/tests.py | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 2870dfae9..4a1a005c6 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -23,6 +23,7 @@ import json import os import shutil import tempfile +from time import time from rest_framework.test import APITestCase from rest_framework.authtoken.models import Token @@ -2841,16 +2842,33 @@ class TemplateTest(FindInit, TestCase): class SeleniumTestsBaseFinds(SeleniumTests): fixtures = FIND_FIXTURES - def _test_bf(self, i, pks, geojsons): - bf_infos = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') - self.scroll(bf_infos) - bf_infos.click() - - bf_label = self.selenium.find_element_by_xpath('//small[@title="ID interne" or @title="Internal ID"]').text - bf_label = bf_label.split('-') - self.assertEqual(len(bf_label), 3) - bf_label = bf_label[2] - bf = models.BaseFind.objects.get(pk=pks[bf_label]) + 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 + timeout = 20 + t = time() + while not label and time()-t < timeout: + 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 = '//small[@title="ID interne" or @title="Internal ID"][contains(text(), "Find")]' + self.WebDriverWait(self.selenium, 2).until( + lambda driver: driver.find_element_by_xpath(label)) + label = self.selenium.find_element_by_xpath(label).text''' + label = label.split('-') + self.assertEqual(len(label), 3) + label = label[2] + + bf = models.BaseFind.objects.get(pk=pks[label]) slug_pk = str(bf.SLUG) + "-" + str(bf.pk) print('ACHTUNG: ', bf.most_precise_geo()) print(bf.multi_polygon.coords) @@ -2861,9 +2879,9 @@ class SeleniumTestsBaseFinds(SeleniumTests): print(bf.point_source_item) if False: #geojsons[bf_label]['precise'] - bf_base = geojsons[bf_label]['get_pts'] + bf_base = geojsons[label]['get_pts'] else: - bf_base = geojsons[bf_label]['get_polys'] + bf_base = geojsons[label]['get_polys'] self.assertMap(bf_base, slug_pk) title = '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]' @@ -2876,6 +2894,41 @@ class SeleniumTestsBaseFinds(SeleniumTests): def test_geo_items(self): pks, geojsons = self.pks_and_geojson() + # from operation + for i in range(1, 3): + self.WebDriverWait(self.selenium, 2).until( + lambda driver: driver.find_element_by_xpath( + '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]')) + dropdown = self.selenium.find_element_by_xpath( + '//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="/operation_search/"]').click() + details = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') + self.scroll(details) + details.click() + self.selenium.find_element_by_xpath( + '//ul[@role="tablist"]/li/a[contains(text(), "Mobilier") or contains(text(), "Finds")]').click() + for j in range(1, 5): + self._test_bf(j, pks, copy.deepcopy(geojsons)) + # from context record + for i in range(1, 5): + self.WebDriverWait(self.selenium, 2).until( + lambda driver: driver.find_element_by_xpath( + '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]')) + dropdown = self.selenium.find_element_by_xpath( + '//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="/record_search/"]').click() + details = self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]') + self.scroll(details) + details.click() + self.selenium.find_element_by_xpath( + '//ul[@role="tablist"]/li/a[contains(text(), "Mobilier") or contains(text(), "Finds")]').click() + for j in range(1, 3): + self._test_bf(j, pks, copy.deepcopy(geojsons)) + # from search for i in range(1, 9): self.WebDriverWait(self.selenium, 2).until( lambda driver: driver.find_element_by_xpath( @@ -2884,4 +2937,7 @@ class SeleniumTestsBaseFinds(SeleniumTests): self.scroll(dropdown) dropdown.click() self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/find_search/"]').click() - self._test_bf(i, pks, geojsons) + 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) |