diff options
author | QuentinAndre <quentin.andre@imt-atlantique.net> | 2021-08-07 01:23:16 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-10-25 12:06:02 +0200 |
commit | 5124549dd86b3a4522cc953768a93e4dcce1a89c (patch) | |
tree | ba8aedfa4f07511f11ce49fb60f1b656104c7ccb /ishtar_common/tests.py | |
parent | 8eeb37c0648690e4ffca7234b710e44be4359b20 (diff) | |
download | Ishtar-5124549dd86b3a4522cc953768a93e4dcce1a89c.tar.bz2 Ishtar-5124549dd86b3a4522cc953768a93e4dcce1a89c.zip |
PR for peer review
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index e535eda4b..73e3dda88 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -16,6 +16,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # See the file COPYING for details. +import re from bs4 import BeautifulSoup as Soup import csv @@ -3127,3 +3128,114 @@ class TemplateGenerationTest(TestCase): filtr = doc.get_filter(template, filter_re) for key in expected_keys: self.assertIn(key, filtr) + +from django.contrib.staticfiles.testing import StaticLiveServerTestCase +from selenium.webdriver.firefox.webdriver import WebDriver + +class SeleniumTests(StaticLiveServerTestCase): + from selenium.webdriver.support.wait import WebDriverWait + from selenium.webdriver.common.by import By + from selenium.webdriver.support import expected_conditions as EC + from archaeological_operations.models import Operation + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.selenium = WebDriver() + cls.selenium.implicitly_wait(20) + + @classmethod + def tearDownClass(cls): + cls.selenium.quit() + super().tearDownClass() + + def setUp(self): + # profile + profile = models.get_current_profile() + profile.mapping = True + profile.files = True + profile.context_record = True + profile.find = True + profile.warehouse = True + profile.save() + + # login + self.username, self.password, self.user = create_superuser() + self.selenium.get('%s%s' % (self.live_server_url, '/accounts/login/')) + self.WebDriverWait(self.selenium, 2).until( + lambda driver: driver.find_element_by_name("username")) + username_input = self.selenium.find_element_by_name("username") + username_input.send_keys(self.username) + password_input = self.selenium.find_element_by_name("password") + password_input.send_keys(self.password) + self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click() + + def setUpDefaultGeoItems(self): + from django.contrib.gis.geos import GEOSGeometry + from ishtar_common.models_common import SpatialReferenceSystem + from archaeological_finds.tests import GeomaticTest + from archaeological_operations.tests import create_operation + + ope1 = create_operation(self.user) + ope2 = create_operation(self.user) + + wgs84 = SpatialReferenceSystem.objects.get(srid=4326) + limit = ( + "MULTIPOLYGON(((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)))" + ) + geom = GEOSGeometry("POINT({} {} {})".format(2, 43, 1), srid=4326) + geom_2d = GEOSGeometry("POINT({} {})".format(2, 43), srid=4326) + xy = 2, 43 + geom_params = [limit, geom, geom_2d, xy, wgs84] + + ope1 = self.Operation.objects.get(pk=ope1.pk) + ope1.multi_polygon = limit + ope1.save() + ope1 = self.Operation.objects.get(pk=ope1.pk) + ope1.point = geom + ope1.x, ope2.y = xy + ope1.point_source = "P" + ope1.spatial_reference_system = wgs84 + ope1.point_source_item = "Operation" + ope1.save() + ope1 = self.Operation.objects.get(pk=ope1.pk) + ope2.multi_polygon = limit + ope2.save() + + cr_pt1, (bf_poly_pt1, bf_pt_pt1) = GeomaticTest.create_cr_with_bfs(ope1, "Point", ["Polygon", "Point"], + "CR Pt Poly Pt", geom_params) + cr_poly1, (bf_poly_poly1, bf_pt_poly1) = GeomaticTest.create_cr_with_bfs(ope1, "Polygon", ["Polygon", "Point"], + "CR Poly Poly Pt", geom_params) + cr_pt2, (bf_poly_pt2, bf_pt_pt2) = GeomaticTest.create_cr_with_bfs(ope2, "Point", ["Polygon", "Point"], + "CR Pt Poly Pt", geom_params) + cr_poly2, (bf_poly_poly2, bf_pt_poly2) = GeomaticTest.create_cr_with_bfs(ope2, "Polygon", ["Polygon", "Point"], + "CR Poly Poly Pt", geom_params) + def scroll(self, element): + self.selenium.execute_script( + "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);" + + "var elementTop = arguments[0].getBoundingClientRect().top;" + + "window.scrollBy(0, elementTop-(viewPortHeight/2));", + element) + + def assertMap(self, dic_base, features_collecs=None): + mapdiv = self.selenium.find_element_by_class_name("window-map") + mapid = mapdiv.get_attribute("id") + id = int(re.search(r'\d+$', mapid).group()) + # TODO: use the map and not the map_features in the js function + if features_collecs: + self.WebDriverWait(self.selenium, 2).until( + self.EC.visibility_of_element_located((self.By.ID, "http-geo-items-ready")) + ) + print(id) + print(self.selenium.execute_script('return print(arguments[0])', mapid)) + base_features, geo_items_feats = self.selenium.execute_script('return get_map_by_id(arguments[0])', mapid) + base_features['features'][0]['properties'].pop('name') + dic_base['features'][0]['properties']['id'] = id + print('feat : ', base_features) + print('dic : ', dic_base) + self.assertEqual(base_features, dic_base) + if features_collecs: + print('feat : ', geo_items_feats) + print('dic : ', features_collecs) + self.assertEqual(geo_items_feats, features_collecs) |