diff options
Diffstat (limited to 'ishtar_common/tests.py')
-rw-r--r-- | ishtar_common/tests.py | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index 25d4d8e85..a7cc8361c 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -90,12 +90,6 @@ from ishtar_common import utils_secretary from django.contrib.staticfiles.testing import StaticLiveServerTestCase -if settings.SELENIUM_TEST: - from selenium.webdriver.firefox.webdriver import WebDriver - from selenium.webdriver.support.wait import WebDriverWait - from selenium.webdriver.common.by import By - from selenium.webdriver.support import expected_conditions as EC - COMMON_FIXTURES = [ settings.ROOT_PATH + "../fixtures/initial_data-auth-fr.json", @@ -3369,178 +3363,3 @@ class TemplateGenerationTest(TestCase): filtr = doc.get_filter(template, filter_re) for key in expected_keys: self.assertIn(key, filtr) - - -@tag("ui") -class SeleniumTests(StaticLiveServerTestCase): - @classmethod - def setUpClass(cls): - if not settings.SELENIUM_TEST: - sys.stdout.write("UI test not activated. Set SELENIUM_TEST to True.") - return - super().setUpClass() - cls.waiting_time = 20 - cls.selenium = WebDriver() - cls.selenium.implicitly_wait(cls.waiting_time) - - @classmethod - def tearDownClass(cls): - if not settings.SELENIUM_TEST: - return - cls.selenium.quit() - super().tearDownClass() - - def setUp(self): - if not settings.SELENIUM_TEST: - return - - # profile - profile = models.get_current_profile() - profile.mapping = True - profile.files = True - profile.context_record = True - profile.find = True - profile.warehouse = True - profile.experimental_feature = True - profile.save() - - # login - self.username, self.password, self.user = create_superuser() - self.selenium.get("%s%s" % (self.live_server_url, "/accounts/login/")) - WebDriverWait(self.selenium, self.waiting_time).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): - if not settings.SELENIUM_TEST: - return - return GeomaticTest.setUpDefaultGeoItems(self.user) - - def default_geojson(self): - geoms, pks = self.setUpDefaultGeoItems() - return GeomaticTest.geojson_geo_items(geoms, pks) - - 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 wait_and_click(self, xpath): - WebDriverWait(self.selenium, self.waiting_time).until( - EC.visibility_of_element_located((By.XPATH, xpath)) - ) - el = self.selenium.find_element_by_xpath(xpath) - self.scroll(el) - el.click() - - def access_from_dropdown(self, slug): - if slug == "contextrecord": - slug = "record" - if slug == "basefind": - slug = "find" - self.wait_and_click( - '//a[@class="nav-link dropdown-toggle"][@id="dropdown-menu-main"]' - ) - self.selenium.find_element_by_xpath( - '//div[@class="dropdown-menu show"]/a[@href="/' + slug + '_search/"]' - ).click() - - def pks_and_details_from_table(self, slug, source=None): - res = [] - xpath = "//table" - keywords = ["find", "record", "operation"] - for key in keywords: - if key in slug or (source and key in source): - xpath += '[contains(@id, "' + key + '")]' - else: - xpath += '[not(contains(@id, "' + key + '"))]' - xpath += ( - '/tbody/tr/td/a[@class="display_details"][@href="#"][contains(@onclick, "' - + slug - + '")]' - ) - for el in self.selenium.find_elements_by_xpath(xpath): - pk = int(re.findall(r"\d+", el.get_attribute("onclick"))[-1]) - res.append([pk, xpath + '[contains(@onclick, "' + str(pk) + '")]']) - return res - - def label_from_internal_id(self, slug_pk): - xpath = '//div[contains(@id, "' - if slug_pk[:3] == "ope": - xpath += slug_pk + '")]' + "/div" * 5 - elif slug_pk[:7] == "context": - xpath += slug_pk + '")]' + "/div" * 3 - else: - xpath += slug_pk[4:] + '")]' - xpath += '/p/small[@title="ID interne" or @title="Internal ID"]' - WebDriverWait(self.selenium, self.waiting_time).until( - EC.visibility_of_element_located((By.XPATH, xpath)) - ) - label = self.selenium.find_element_by_xpath(xpath).text - if slug_pk[:3] == "ope": - if label == "2": - label = "Poly" - else: - label = "Pt" - elif slug_pk[:7] == "context": - label = label[1:] - else: - label = label.split("-") - label = label[2] - return label - - def assertNotInDOM(self, xpath): - self.selenium.implicitly_wait(self.waiting_time / 10) - try: - WebDriverWait(self.selenium, self.waiting_time / 10).until( - EC.visibility_of_element_located((By.XPATH, xpath)) - ) - found = True - except: - found = False - self.selenium.implicitly_wait(self.waiting_time) - self.assertFalse(found) - - def assertMap(self, dic_base, slug_pk, features_collecs=None): - dic_base = {"type": "FeatureCollection", "features": [dic_base]} - mapid = None - t = time() - while not mapid and time() - t < self.waiting_time: - mapdivs = self.selenium.find_elements_by_class_name("window-map") - for mapdiv in mapdivs: - if slug_pk in mapdiv.get_attribute("id"): - mapid = mapdiv.get_attribute("id") - break - self.assertIsNotNone(mapid, "Timeout, no mapid found") - id = int(re.search(r"\d+$", mapid).group()) - # TODO: use the map and not the map_features in the js function - if features_collecs: - WebDriverWait(self.selenium, self.waiting_time).until( - EC.visibility_of_element_located( - (By.ID, "http-geo-items-ready-" + slug_pk) - ) - ) - base_features, geo_items_feats = self.selenium.execute_script( - "return get_features_by_id(arguments[0])", mapid - ) - base_features["features"][0]["properties"].pop("name") - base_features_type = self.selenium.execute_script( - "return base_features_type(arguments[0])", mapid - ) - dic_base["features"][0]["properties"] = {"id": id} - self.assertEqual( - base_features_type, dic_base["features"][0]["geometry"]["type"] - ) - self.assertEqual(base_features, dic_base) - if features_collecs: - self.assertEqual(geo_items_feats, features_collecs) |