summaryrefslogtreecommitdiff
path: root/ishtar_common/tests.py
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-07 01:23:16 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-07-08 09:58:48 +0200
commit313aefcf470df2fe3ad660e568aa8cac308dfcae (patch)
tree2e0ba9944cdc7d9d243cc65c513f772ffe7d937a /ishtar_common/tests.py
parent6a8dc71f4381c5b6b78dc23105ec5cdc3dc64dfb (diff)
downloadIshtar-313aefcf470df2fe3ad660e568aa8cac308dfcae.tar.bz2
Ishtar-313aefcf470df2fe3ad660e568aa8cac308dfcae.zip
PR for peer review
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r--ishtar_common/tests.py112
1 files changed, 112 insertions, 0 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index 7ec38913a..ac78cad02 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
@@ -3207,3 +3208,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)