diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-08-25 15:32:23 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-07-08 09:58:48 +0200 |
commit | 82893c90a90eec6718de7bed10962f68712a41a6 (patch) | |
tree | c4c4d8ce1815e5873aab1c0af607a48f8a13f3ea /archaeological_finds | |
parent | ac73c65cd3309e797c8c495454a8e48648f47090 (diff) | |
download | Ishtar-82893c90a90eec6718de7bed10962f68712a41a6.tar.bz2 Ishtar-82893c90a90eec6718de7bed10962f68712a41a6.zip |
clean version of get_geo_items with ui integration and tests
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/tests.py | 122 |
1 files changed, 66 insertions, 56 deletions
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index 734f4f66f..597cc29cc 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -91,7 +91,8 @@ from ishtar_common.tests import ( WAREHOUSE_FIXTURES, COMMON_FIXTURES, GenericSerializationTest, - SearchText, SeleniumTests, + SearchText, + SeleniumTests, ) from archaeological_operations.tests import ImportTest, create_operation from archaeological_context_records.tests import ContextRecordInit @@ -2524,15 +2525,10 @@ class GeomaticTest(FindInit, TestCase): def test_get_geo_items(self): from ishtar_common.tests import GeomaticTest as BaseGeomaticTest - #profile = models.get_current_profile() + # profile = models.get_current_profile() profile = get_current_profile() profile.mapping = True profile.save() - '''username, password, user = create_superuser() - client = Client() - client.login(username=username, password=password) - print("is_authenticated") - print(user.is_authenticated())''' geoms, pks = BaseGeomaticTest.setUpDefaultGeoItems(self.user) dics = BaseGeomaticTest.geojson_geo_items(geoms, pks, test_get_geo_items=True) @@ -2541,22 +2537,22 @@ class GeomaticTest(FindInit, TestCase): for label in dics.keys(): dic = dics[label] - get_pk = dic['get_pk'] + get_pk = dic["get_pk"] pk = pks[label] - self.assertEqual(dic['res_polys'], dic['get_polys']) + self.assertEqual(dic["res_polys"], dic["get_polys"]) response = self.client.get(url_polys + get_pk + "0") self.assertEqual(response.status_code, 404) response = self.client.get(url_polys + get_pk + str(pk)) self.assertEqual(response.status_code, 200) - self.assertEqual(dic['get_polys'], json.loads(response.content)) + self.assertEqual(dic["get_polys"], json.loads(response.content)) - self.assertEqual(dic['get_pts'], dic['res_pts']) + self.assertEqual(dic["get_pts"], dic["res_pts"]) response = self.client.get(url_pts + get_pk + "0") self.assertEqual(response.status_code, 404) response = self.client.get(url_pts + get_pk + str(pk)) self.assertEqual(response.status_code, 200) - self.assertEqual(dic['get_pts'], json.loads(response.content)) + self.assertEqual(dic["get_pts"], json.loads(response.content)) @@ -2856,50 +2852,42 @@ class TemplateTest(FindInit, TestCase): if os.path.exists(tpl): os.remove(tpl) + @tag("ui") 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('./..') + 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' + 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"]') + 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: + 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 = '//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('-') + 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) - print(bf.multi_polygon_source) - print(bf.multi_polygon_source_item) - print(bf.point_2d.coords) - print(bf.point_source) - print(bf.point_source_item) - - if False: #geojsons[bf_label]['precise'] - bf_base = geojsons[label]['get_pts'] - else: - bf_base = geojsons[label]['get_polys'] + slug_pk = bf.SLUG + "-" + str(bf.pk) + + 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"]' @@ -2914,48 +2902,70 @@ class SeleniumTestsBaseFinds(SeleniumTests): pks, geojsons = self.pks_and_geojson() # from operation for i in range(1, 3): - self.WebDriverWait(self.selenium, 2).until( + 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"]')) + '//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"]') + '//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.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() + '//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( + 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"]')) + '//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"]') + '//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.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() + '//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( + 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"]')) - dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]') + '//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="/find_search/"]').click() + self.selenium.find_element_by_xpath( + '//div[@class="dropdown-menu show"]/a[@href="/find_search/"]' + ).click() self._test_bf(i, pks, copy.deepcopy(geojsons), from_search=True) # from bottom table - for i in range(1,8): + for i in range(1, 8): self._test_bf(i, pks, copy.deepcopy(geojsons), from_search=True) |