diff options
Diffstat (limited to 'archaeological_operations/tests.py')
| -rw-r--r-- | archaeological_operations/tests.py | 342 | 
1 files changed, 175 insertions, 167 deletions
| diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 88044b4f2..c09e30003 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -33,6 +33,7 @@ from django.contrib.contenttypes.models import ContentType  from django.core.files.uploadedfile import SimpleUploadedFile  from django.core.urlresolvers import reverse  from django.db.models import Q +from django.test import tag  from django.test.client import Client  from django.utils.text import slugify @@ -4239,181 +4240,188 @@ class DocumentQATest(OperationInitTest, TestCase):              models.Document.objects.get(pk=document_1.pk).source_type, source_type          ) - +@tag("ui")  class SeleniumTestsOperations(SeleniumTests):      fixtures = OPERATION_FIXTURES -    def test_geo_items(self): -        def test_operation_i(i): -            #TODO: dic_base should be point or poly, here it's only poly -            dic_base = { -                'type': 'FeatureCollection', -                'features': [ -                    {'geometry': -                         {'coordinates': [ -                             [[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -                             [[[6, 3], [9, 2], [9, 4], [6, 3]]]], -                          'type': 'MultiPolygon'}, -                     'properties': {}, +    def _test_operation(self, i, dic_base, geom_cr, geom_bf): +        self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]').click() +        self.WebDriverWait(self.selenium, 2).until( +            lambda driver: driver.find_element_by_xpath( +                '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]')) +        self.selenium.find_element_by_xpath( +            '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]') +        dd = '//dl[@class="col-12"]/dd' +        self.selenium.find_element_by_xpath(dd + '/label[text()="Display associated features: "]') +        select = dd + '/select[@name="display-geo-items"]' +        disp = self.selenium.find_element_by_xpath(select) +        self.assertEqual(disp.get_attribute("value"), "") +        self.assertMap(dic_base) + +        # operation specific +        poly_cr, centr_cr, pt_cr = geom_cr +        poly_bf, centr_bf, pt_bf = geom_bf + +        # click on "Context records" +        self.selenium.execute_script('return initialize_test_map()') +        self.scroll(disp) +        disp.click() +        self.selenium.find_element_by_xpath(select + '/option[@value="contextrecords"]').click() + +        cr_geoms = [ +            {'type': 'FeatureCollection', +             'features': [ +                 {'geometry': +                     {'coordinates': poly_cr, +                         'type': 'MultiPolygon'}, +                     'properties': None, +                     'type': 'Feature'}, +                 {'geometry': +                      {'coordinates': poly_cr, 'type': 'MultiPolygon'}, +                  'properties': None, 'type': 'Feature'}]} +        ] +        self.assertMap(dic_base, cr_geoms) + +        select_get_poly = dd + '/select[@name="get-polygons"]' +        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': [ +                 {'geometry': +                      {'coordinates': centr_cr, 'type': 'Point'}, +                  'properties': None, +                  'type': 'Feature'}, +                 {'geometry': +                      {'coordinates': pt_cr, 'type': 'Point'}, +                  'properties': None, 'type': 'Feature'}]} +        ] +        self.assertMap(dic_base, cr_geoms) + +        # Click on "Everything" +        disp.click() +        self.selenium.find_element_by_xpath(select + '/option[@value="basefinds"]').click() +        self.selenium.execute_script('return initialize_test_map()') +        get_poly.click() +        self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="polygons"]').click() +        every_geoms = [ +            {'type': 'FeatureCollection', +             'features': [{ +                 'geometry': { +                     'coordinates': poly_bf, +                     'type': 'MultiPolygon'}, +                 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, +                 'type': 'Feature'}, +                 {'geometry': { +                     'coordinates': poly_bf, +                     'type': 'MultiPolygon'}, +                     'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, +                     'type': 'Feature'} +             ]}, +            {'type': 'FeatureCollection', +             'features': [ +                 {'geometry': { +                     'coordinates': poly_bf, +                     'type': 'MultiPolygon'}, +                     'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, +                 {'geometry': { +                     'coordinates': poly_bf, 'type': 'MultiPolygon'}, +                     'properties': {'label': 'Find 2 from CR Pt Poly Pt'},                       'type': 'Feature'} -                ]} -            self.selenium.find_element_by_xpath('//tbody/tr[' + str(i) + ']/td/a[@class="display_details"]').click() -            self.WebDriverWait(self.selenium, 2).until( -                lambda driver: driver.find_element_by_xpath( -                    '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]')) -            self.selenium.find_element_by_xpath( -                '//dl[@class="col-12"]/dt[text()="Display geo items" or text()="Afficher les éléments"]') -            dd = '//dl[@class="col-12"]/dd' -            self.selenium.find_element_by_xpath(dd + '/label[text()="Display associated features: "]') -            select = dd + '/select[@name="display-geo-items"]' -            disp = self.selenium.find_element_by_xpath(select) -            self.assertEqual(disp.get_attribute("value"), "") -            self.assertMap(dic_base) - -            # operation specific - -            # click on "Context records" -            self.selenium.execute_script('return initialize_test_map()') -            self.scroll(disp) -            disp.click() -            self.selenium.find_element_by_xpath(select + '/option[@value="contextrecords"]').click() -            cr_geoms = [ -                {'type': 'FeatureCollection', -                 'features': [ -                    {'geometry': -                         {'coordinates': [ -                             [[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -                             [[[6, 3], [9, 2], [9, 4], [6, 3]]]], -                          'type': 'MultiPolygon'}, +             ]}, +            {'type': 'FeatureCollection', +             'features': [ +                 {'geometry': { +                     'coordinates': poly_cr, +                     'type': 'MultiPolygon'},                       'properties': None,                       'type': 'Feature'}, -                    {'geometry': -                         {'coordinates': [], 'type': 'MultiPolygon'}, -                     'properties': None, 'type': 'Feature'}]} -            ] -            self.assertMap(dic_base, cr_geoms) - -            select_get_poly = dd + '/select[@name="get-polygons"]' -            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': [ -                     {'geometry': -                          {'coordinates': [3.861, 3.028], 'type': 'Point'}, -                      'properties': None, -                      'type': 'Feature'}, -                     {'geometry': -                          {'coordinates': [2, 43], 'type': 'Point'}, -                      'properties': None, 'type': 'Feature'}]} -            ] -            self.assertMap(dic_base, cr_geoms) - -            # Click on "Everything" -            disp.click() -            self.selenium.find_element_by_xpath(select + '/option[@value="basefinds"]').click() -            self.selenium.execute_script('return initialize_test_map()') -            get_poly.click() -            self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="polygons"]').click() -            every_geoms = [ -                {'type': 'FeatureCollection', -                 'features': [{ -                    'geometry': { -                        'coordinates': [[[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], [[[6, 3], [9, 2], [9, 4], [6, 3]]]], -                        'type': 'MultiPolygon'}, -                    'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, -                    'type': 'Feature'}, -                    {'geometry': { -                        'coordinates': [], -                        'type': 'MultiPolygon'}, -                        'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, -                        'type': 'Feature'} -                ]}, -                {'type': 'FeatureCollection', -                 'features': [ -                    {'geometry': { -                        'coordinates': [[[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], [[[6, 3], [9, 2], [9, 4], [6, 3]]]], -                        'type': 'MultiPolygon'}, -                        'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, -                    {'geometry': { -                        'coordinates': [], 'type': 'MultiPolygon'}, -                        'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, -                        'type': 'Feature'} -                ]}, -                {'type': 'FeatureCollection', -                 'features': [ -                    {'geometry': { -                        'coordinates': [ -                            [[[1, 1], [5, 1], [5, 5], [1, 5], [1, 1]], [[2, 2], [2, 3], [3, 3], [3, 2], [2, 2]]], -                            [[[6, 3], [9, 2], [9, 4], [6, 3]]]], -                        'type': 'MultiPolygon'}, -                        'properties': None, -                        'type': 'Feature'}, -                    {'geometry': { -                        'coordinates': [], -                        'type': 'MultiPolygon'}, -                        'properties': None, -                        'type': 'Feature'} -                ]}] -            self.assertMap(dic_base, every_geoms) - -            self.selenium.execute_script('return initialize_test_map()') -            get_poly.click() -            self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() -            every_geoms = [ -                {'type': 'FeatureCollection', -                 'features': [{ -                     'geometry': { -                         'coordinates': [3.861, 3.028], -                         'type': 'Point'}, -                     'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, +                 {'geometry': { +                     'coordinates': poly_cr, +                     'type': 'MultiPolygon'}, +                     'properties': None, +                     'type': 'Feature'} +             ]}] +        self.assertMap(dic_base, every_geoms) + +        self.selenium.execute_script('return initialize_test_map()') +        get_poly.click() +        self.selenium.find_element_by_xpath(select_get_poly + '/option[@value="points"]').click() +        every_geoms = [ +            {'type': 'FeatureCollection', +             'features': [{ +                 'geometry': { +                     'coordinates': centr_bf, +                     'type': 'Point'}, +                 'properties': {'label': 'Find 1 from CR Poly Poly Pt'}, +                 'type': 'Feature'}, +                 {'geometry': { +                     'coordinates': pt_bf, +                     'type': 'Point'}, +                     'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, +                     'type': 'Feature'} +             ]}, +            {'type': 'FeatureCollection', +             'features': [ +                 {'geometry': { +                     'coordinates': centr_bf, +                     'type': 'Point'}, +                     'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, +                 {'geometry': { +                     'coordinates': pt_bf, 'type': 'Point'}, +                     'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, +                     'type': 'Feature'} +             ]}, +            {'type': 'FeatureCollection', +             'features': [ +                 {'geometry': { +                     'coordinates': centr_cr, +                     'type': 'Point'}, +                     'properties': None,                       'type': 'Feature'}, -                     {'geometry': { -                         'coordinates': [2, 43], -                         'type': 'Point'}, -                         'properties': {'label': 'Find 2 from CR Poly Poly Pt'}, -                         'type': 'Feature'} -                 ]}, -                {'type': 'FeatureCollection', -                 'features': [ -                     {'geometry': { -                         'coordinates': [3.861, 3.028], -                         'type': 'Point'}, -                         'properties': {'label': 'Find 1 from CR Pt Poly Pt'}, 'type': 'Feature'}, -                     {'geometry': { -                         'coordinates': [2, 43], 'type': 'Point'}, -                         'properties': {'label': 'Find 2 from CR Pt Poly Pt'}, -                         'type': 'Feature'} -                 ]}, -                {'type': 'FeatureCollection', -                 'features': [ -                     {'geometry': { -                         'coordinates': [3.861, 3.028], -                         'type': 'Point'}, -                         'properties': None, -                         'type': 'Feature'}, -                     {'geometry': { -                         'coordinates': [2, 43], -                         'type': 'Point'}, -                         'properties': None, -                         'type': 'Feature'} -                 ]}] -            self.assertMap(dic_base, every_geoms) - -            # Click on "None" -            self.selenium.execute_script('return initialize_test_map()') -            disp.click() -            self.selenium.find_element_by_xpath(select + '/option[@value=""]').click() -            self.assertMap(dic_base) - -        self.setUpDefaultGeoItems() - -        self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]').click() +                 {'geometry': { +                     'coordinates': pt_cr, +                     'type': 'Point'}, +                     'properties': None, +                     'type': 'Feature'} +             ]}] +        self.assertMap(dic_base, every_geoms) + +        # Click on "None" +        self.selenium.execute_script('return initialize_test_map()') +        disp.click() +        self.selenium.find_element_by_xpath(select + '/option[@value=""]').click() +        self.assertMap(dic_base) + +    def test_geo_items(self): +        geo_elements = self.setUpDefaultGeoItems() +        poly_ope, centr_ope, pt_ope = geo_elements[0] + +        dic_poly = { +            'type': 'FeatureCollection', +            'features': [ +                {'geometry': +                     {'coordinates': poly_ope, +                      'type': 'MultiPolygon'}, +                 'properties': {}, +                 'type': 'Feature'} +            ]} +        dic_pt = { +            'type': 'FeatureCollection', +            'features': [ +                {'geometry': +                     {'coordinates': pt_ope, +                      'type': 'MultiPolygon'}, +                 'properties': {}, +                 'type': 'Feature'} +            ]} + +        self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]').click()          self.selenium.find_element_by_xpath('//div[@class="dropdown-menu show"]/a[@href="/operation_search/"]').click() -        test_operation_i(1) # point based operation -        dropdown = self.selenium.find_element_by_xpath('//a[@class="nav-link dropdown-toggle"]') +        self._test_operation(1, dic_poly, geo_elements[1], geo_elements[2]) # polygon based operation +        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() -        test_operation_i(2) # polygon based operation +        self._test_operation(2, dic_pt, geo_elements[1], geo_elements[2]) # point based operation | 
