diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-08-25 15:32:23 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-09-01 12:36:46 +0200 |
commit | 40be360e184b4cac81a0666c6238282c7d0c9301 (patch) | |
tree | 288ebb25954beece9da8e98336715297bbd3be22 /archaeological_operations | |
parent | e41bf915709fb45f05c6c79a4f758e50b3ce3683 (diff) | |
download | Ishtar-40be360e184b4cac81a0666c6238282c7d0c9301.tar.bz2 Ishtar-40be360e184b4cac81a0666c6238282c7d0c9301.zip |
clean version of get_geo_items with ui integration and tests
Diffstat (limited to 'archaeological_operations')
-rw-r--r-- | archaeological_operations/tests.py | 220 |
1 files changed, 119 insertions, 101 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 5927e769f..45cdc93dd 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -96,7 +96,8 @@ from ishtar_common.tests import ( COMMON_FIXTURES, GenericSerializationTest, WAREHOUSE_FIXTURES, - SearchText, SeleniumTests, + SearchText, + SeleniumTests, ) from ishtar_common.serializers import restore_serialized @@ -195,8 +196,8 @@ class ImportTest(object): # target for this import target = ( TargetKey.objects.filter(target__target="operation_type") - .order_by("-pk") - .all()[0] + .order_by("-pk") + .all()[0] ) target.value = models.OperationType.objects.get(txt_idx="prog_excavation").pk target.is_set = True @@ -301,7 +302,7 @@ class ImportTest(object): mcc = ImporterType.objects.get(name="MCC - UE") mcc_file = open( settings.ROOT_PATH + "../archaeological_context_records/tests/" - "MCC-context-records-example.csv", + "MCC-context-records-example.csv", "rb", ) file_dict = { @@ -1579,12 +1580,12 @@ class ParcelTest(ImportTest, TestCase): self.assertTrue( (values["section"], values["parcel_number"]) in result[year], msg='Section - Parcel number: "%s - %s" is not ' - 'in "%s"' - % ( - values["section"], - values["parcel_number"], - str(result[year]), - ), + 'in "%s"' + % ( + values["section"], + values["parcel_number"], + str(result[year]), + ), ) parcels.pop(parcels.index(values)) result[year].pop( @@ -1595,14 +1596,14 @@ class ParcelTest(ImportTest, TestCase): parcels, [], msg='Parcel(s): "%s" haven\'t be ' - 'recognized in "%s"' % (str(parcels), value), + 'recognized in "%s"' % (str(parcels), value), ) not_imported = [data for data in result.values() if data] self.assertEqual( not_imported, [], msg='Parcel(s): "%s" haven\'t be ' - 'recognized in "%s"' % (str(not_imported), value), + 'recognized in "%s"' % (str(not_imported), value), ) @@ -1912,14 +1913,14 @@ class OperationTest(TestCase, OperationInitTest): operation.save() self.assertIsNotNone(operation.search_vector) for key in ( - "old", - "dirty", - "daisy", - "'2010'", - "zardoz", - "huiaaa5", - "{}42huiaaa5".format(profile.operation_prefix.lower()), - "42huiaaa5", + "old", + "dirty", + "daisy", + "'2010'", + "zardoz", + "huiaaa5", + "{}42huiaaa5".format(profile.operation_prefix.lower()), + "42huiaaa5", ): self.assertIn(key, operation.search_vector) @@ -2082,8 +2083,8 @@ class OperationTest(TestCase, OperationInitTest): f = BytesIO(response.content) filetype = ( Popen("/usr/bin/file -b --mime -", shell=True, stdout=PIPE, stdin=PIPE) - .communicate(f.read(1024))[0] - .strip() + .communicate(f.read(1024))[0] + .strip() ) self.assertTrue(filetype.startswith(b"application/pdf")) @@ -2535,19 +2536,22 @@ class CustomFormTest(TestCase, OperationInitTest): response = c.get( reverse("get-operation"), - {"search_vector": "{}=endormie".format(slugify(cf1.label))}) + {"search_vector": "{}=endormie".format(slugify(cf1.label))}, + ) result = json.loads(response.content.decode()) self.assertEqual(result["recordsTotal"], 0) response = c.get( reverse("get-operation"), - {"search_vector": "{}=réveillée".format(slugify(cf1.label))}) + {"search_vector": "{}=réveillée".format(slugify(cf1.label))}, + ) result = json.loads(response.content.decode()) self.assertEqual(result["recordsTotal"], 1) response = c.get( reverse("get-operation"), - {"search_vector": "{}=oui".format(slugify(cf2.label))}) + {"search_vector": "{}=oui".format(slugify(cf2.label))}, + ) result = json.loads(response.content.decode()) self.assertEqual(result["recordsTotal"], 1) @@ -4184,6 +4188,7 @@ class DocumentQATest(OperationInitTest, TestCase): models.Document.objects.get(pk=document_1.pk).source_type, source_type ) + @tag("ui") class SeleniumTestsOperations(SeleniumTests): fixtures = OPERATION_FIXTURES @@ -4194,47 +4199,61 @@ class SeleniumTestsOperations(SeleniumTests): disp_cr_id = "disp-cr-for-" + slug_pk disp_bf_id = "disp-bf-for-" + slug_pk - ope_polys = geojsons[label]['get_polys'] - cr_labels_polys = ope_polys['properties'].pop('context-records') - bf_labels_polys = ope_polys['properties'].pop('base-finds') - cr_polys = {'type': 'FeatureCollection', 'features': []} + ope_polys = geojsons[label]["get_polys"] + cr_labels_polys = ope_polys["properties"].pop("context-records") + bf_labels_polys = ope_polys["properties"].pop("base-finds") + cr_polys = {"type": "FeatureCollection", "features": []} for cr_label in cr_labels_polys: - geojsons[cr_label]['get_polys']['properties'] = None - cr_polys['features'].append(geojsons[cr_label]['get_polys']) - bf_polys = {'type': 'FeatureCollection', - 'features': [geojsons[bf_label]['get_polys'] for bf_label in bf_labels_polys] - } - - ope_pts = geojsons[label]['get_pts'] - cr_labels_pts = ope_pts['properties'].pop('context-records') - cr_pts = {'type': 'FeatureCollection', 'features': []} + geojsons[cr_label]["get_polys"]["properties"] = None + cr_polys["features"].append(geojsons[cr_label]["get_polys"]) + bf_polys = { + "type": "FeatureCollection", + "features": [ + geojsons[bf_label]["get_polys"] for bf_label in bf_labels_polys + ], + } + + ope_pts = geojsons[label]["get_pts"] + cr_labels_pts = ope_pts["properties"].pop("context-records") + cr_pts = {"type": "FeatureCollection", "features": []} for cr_label in cr_labels_pts: - geojsons[cr_label]['get_pts']['properties'] = None - cr_pts['features'].append(geojsons[cr_label]['get_pts']) - bf_labels_pts = ope_pts['properties'].pop('base-finds') - bf_pts = {'type': 'FeatureCollection', - 'features': [geojsons[bf_label]['get_pts'] for bf_label in bf_labels_pts] - } - - if False: # geojsons[label]['precise'] - ope_base = geojsons[label]['get_pts'] - else: - ope_base = geojsons[label]['get_polys'] + geojsons[cr_label]["get_pts"]["properties"] = None + cr_pts["features"].append(geojsons[cr_label]["get_pts"]) + bf_labels_pts = ope_pts["properties"].pop("base-finds") + bf_pts = { + "type": "FeatureCollection", + "features": [geojsons[bf_label]["get_pts"] for bf_label in bf_labels_pts], + } + + 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"]') + '//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, 2).until( + 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 + '"]')) + '//dl[@class="col-12"]/dt[@id="display-geo-items-for-' + slug_pk + '"]' + ) + ) dd = '//dl[@class="col-12"]/dd' - self.selenium.find_element_by_xpath(dd + '/fieldset/label[@for="' + disp_cr_id + '"]') - disp_cr = self.selenium.find_element_by_xpath(dd + '/fieldset/input[@id="' + disp_cr_id + '"]') - self.selenium.find_element_by_xpath(dd + '/fieldset/label[@for="' + disp_bf_id + '"]') - disp_bf = self.selenium.find_element_by_xpath(dd + '/fieldset/input[@id="' + disp_bf_id + '"]') + self.selenium.find_element_by_xpath( + dd + '/fieldset/label[@for="' + disp_cr_id + '"]' + ) + disp_cr = self.selenium.find_element_by_xpath( + dd + '/fieldset/input[@id="' + disp_cr_id + '"]' + ) + self.selenium.find_element_by_xpath( + dd + '/fieldset/label[@for="' + disp_bf_id + '"]' + ) + disp_bf = self.selenium.find_element_by_xpath( + dd + '/fieldset/input[@id="' + disp_bf_id + '"]' + ) self.assertFalse(disp_cr.is_selected()) self.assertFalse(disp_bf.is_selected()) select_get_poly = dd + '/select[@id="' + get_poly_id + '"]' @@ -4244,14 +4263,11 @@ class SeleniumTestsOperations(SeleniumTests): self.assertMap(ope_base, slug_pk) # click on "Context records" - self.selenium.execute_script('initialize_test_map(arguments[0])', slug_pk) + self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk) self.scroll(disp_cr) disp_cr.click() - cr_geoms = [ - {'type': 'FeatureCollection', 'features': []}, - cr_polys - ] + cr_geoms = [{"type": "FeatureCollection", "features": []}, cr_polys] self.assertTrue(disp_cr.is_selected()) self.assertFalse(disp_bf.is_selected()) self.selenium.find_element_by_xpath(get_poly_label) @@ -4259,18 +4275,17 @@ class SeleniumTestsOperations(SeleniumTests): get_poly = self.selenium.find_element_by_xpath(select_get_poly) get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() - cr_geoms = [ - {'type': 'FeatureCollection', 'features': []}, - cr_pts - ] + self.selenium.find_element_by_xpath( + select_get_poly + '/option[@value="points"]' + ).click() + cr_geoms = [{"type": "FeatureCollection", "features": []}, cr_pts] self.assertTrue(disp_cr.is_selected()) self.assertFalse(disp_bf.is_selected()) self.selenium.find_element_by_xpath(get_poly_label) self.assertMap(ope_base, slug_pk, cr_geoms) # Click on everything - self.selenium.execute_script('initialize_test_map(arguments[0])', slug_pk) + self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk) disp_bf.click() every_geoms = [bf_pts, cr_pts] self.assertTrue(disp_cr.is_selected()) @@ -4278,9 +4293,11 @@ class SeleniumTestsOperations(SeleniumTests): self.selenium.find_element_by_xpath(get_poly_label) self.assertMap(ope_base, slug_pk, every_geoms) - self.selenium.execute_script('initialize_test_map(arguments[0])', slug_pk) + self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk) get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="polygons"]').click() + self.selenium.find_element_by_xpath( + select_get_poly + '/option[@value="polygons"]' + ).click() every_geoms = [bf_polys, cr_polys] self.assertTrue(disp_cr.is_selected()) self.assertTrue(disp_bf.is_selected()) @@ -4288,14 +4305,11 @@ class SeleniumTestsOperations(SeleniumTests): self.assertMap(ope_base, slug_pk, every_geoms) # click on "Base finds" - self.selenium.execute_script('initialize_test_map(arguments[0])', slug_pk) + self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk) self.scroll(disp_cr) disp_cr.click() - bf_geoms = [ - bf_polys, - {'type': 'FeatureCollection', 'features': []} - ] + bf_geoms = [bf_polys, {"type": "FeatureCollection", "features": []}] self.assertFalse(disp_cr.is_selected()) self.assertTrue(disp_bf.is_selected()) self.selenium.find_element_by_xpath(get_poly_label) @@ -4304,18 +4318,17 @@ class SeleniumTestsOperations(SeleniumTests): select_get_poly = dd + '/select[@id="' + get_poly_id + '"]' get_poly = self.selenium.find_element_by_xpath(select_get_poly) get_poly.click() - self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() - bf_geoms = [ - bf_pts, - {'type': 'FeatureCollection', 'features': []} - ] + self.selenium.find_element_by_xpath( + select_get_poly + '/option[@value="points"]' + ).click() + bf_geoms = [bf_pts, {"type": "FeatureCollection", "features": []}] self.assertFalse(disp_cr.is_selected()) self.assertTrue(disp_bf.is_selected()) self.selenium.find_element_by_xpath(get_poly_label) self.assertMap(ope_base, slug_pk, bf_geoms) # Click on "None" - self.selenium.execute_script('initialize_test_map(arguments[0])', slug_pk) + self.selenium.execute_script("initialize_test_map(arguments[0])", slug_pk) disp_bf.click() self.assertFalse(disp_cr.is_selected()) self.assertFalse(disp_bf.is_selected()) @@ -4326,28 +4339,33 @@ class SeleniumTestsOperations(SeleniumTests): def test_geo_items(self): pks, geojsons = self.pks_and_geojson() - 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.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"]' + ) dropdown.click() - self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]').click() - ope = models.Operation.objects.get(pk=pks['Poly']) - slug_pk_poly = str(ope.SLUG) + "-" + str(ope.pk) - self._test_operation(2, slug_pk_poly, copy.deepcopy(geojsons), 'Poly') + self.selenium.find_element_by_xpath( + '//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]' + ).click() + 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") 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() - ope = models.Operation.objects.get(pk=pks['Pt']) - print('\n') - print('OPERATION POINT') - print(ope) - print(ope.multi_polygon.coords) - print(ope.point_2d.coords) - slug_pk_pt = str(ope.SLUG) + "-" + str(ope.pk) - self._test_operation(1, slug_pk_pt, copy.deepcopy(geojsons), 'Pt') + self.selenium.find_element_by_xpath( + '//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]' + ).click() + 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') + self._test_operation(2, slug_pk_poly, geojsons, "Poly") |