diff options
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 3452b78fc..9d835aa93 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -97,7 +97,8 @@ from ishtar_common.tests import (      COMMON_FIXTURES,      GenericSerializationTest,      WAREHOUSE_FIXTURES, -    SearchText, SeleniumTests, +    SearchText, +    SeleniumTests,  )  from ishtar_common.serializers import restore_serialized @@ -196,8 +197,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 @@ -302,7 +303,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 = { @@ -1602,12 +1603,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( @@ -1618,14 +1619,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),              ) @@ -1935,14 +1936,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) @@ -2105,8 +2106,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")) @@ -2558,19 +2559,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) @@ -4239,6 +4243,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 @@ -4249,47 +4254,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 + '"]' @@ -4299,14 +4318,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) @@ -4314,18 +4330,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()) @@ -4333,9 +4348,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()) @@ -4343,14 +4360,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) @@ -4359,18 +4373,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()) @@ -4381,28 +4394,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") | 
