|
5 | 5 | from django.urls.base import reverse |
6 | 6 | from selenium.common.exceptions import TimeoutException |
7 | 7 | from selenium.webdriver.common.action_chains import ActionChains |
8 | | -from selenium.webdriver.common.alert import Alert |
9 | 8 | from selenium.webdriver.common.by import By |
10 | 9 | from selenium.webdriver.common.keys import Keys |
11 | 10 | from selenium.webdriver.support import expected_conditions as EC |
@@ -267,42 +266,7 @@ def test_change_config_backend(self): |
267 | 266 | config_backend_select.select_by_visible_text("OpenWISP Firmware 1.x") |
268 | 267 | self.wait_for_invisibility(By.XPATH, f'//*[@value="{template.id}"]') |
269 | 268 |
|
270 | | - def test_template_context_variables(self): |
271 | | - self._create_template( |
272 | | - name="Template1", default_values={"vni": "1"}, required=True |
273 | | - ) |
274 | | - self._create_template( |
275 | | - name="Template2", default_values={"vni": "2"}, required=True |
276 | | - ) |
277 | | - device = self._create_config(organization=self._get_org()).device |
278 | | - self.login() |
279 | | - self.open( |
280 | | - reverse("admin:config_device_change", args=[device.id]) + "#config-group" |
281 | | - ) |
282 | | - self.hide_loading_overlay() |
283 | | - try: |
284 | | - WebDriverWait(self.web_driver, 2).until( |
285 | | - EC.text_to_be_present_in_element_value( |
286 | | - ( |
287 | | - By.XPATH, |
288 | | - '//*[@id="flat-json-config-0-context"]/div[2]/div/div/input[1]', |
289 | | - ), |
290 | | - "vni", |
291 | | - ) |
292 | | - ) |
293 | | - except TimeoutException: |
294 | | - self.fail("Timed out wating for configuration variabled to get loaded") |
295 | | - self.find_element( |
296 | | - by=By.XPATH, value='//*[@id="main-content"]/div[2]/a[3]' |
297 | | - ).click() |
298 | | - try: |
299 | | - WebDriverWait(self.web_driver, 2).until(EC.alert_is_present()) |
300 | | - except TimeoutException: |
301 | | - pass |
302 | | - else: |
303 | | - alert = Alert(self.web_driver) |
304 | | - alert.accept() |
305 | | - self.fail("Unsaved changes alert displayed without any change") |
| 269 | + retry_max = 1 |
306 | 270 |
|
307 | 271 | def test_force_delete_device_with_deactivating_config(self): |
308 | 272 | self._create_template(default=True) |
@@ -579,6 +543,52 @@ def test_unsaved_changes(self): |
579 | 543 | if not self._is_unsaved_changes_alert_present(): |
580 | 544 | self.fail("Unsaved changes code was not executed.") |
581 | 545 |
|
| 546 | + def test_template_context_variables(self): |
| 547 | + self._create_template( |
| 548 | + name="Template1", default_values={"vni": "1"}, required=True |
| 549 | + ) |
| 550 | + self._create_template( |
| 551 | + name="Template2", default_values={"vni": "2"}, required=True |
| 552 | + ) |
| 553 | + device = self._create_config(organization=self._get_org()).device |
| 554 | + self.login() |
| 555 | + self.open( |
| 556 | + reverse("admin:config_device_change", args=[device.id]) + "#config-group" |
| 557 | + ) |
| 558 | + self.hide_loading_overlay() |
| 559 | + try: |
| 560 | + WebDriverWait(self.web_driver, 2).until( |
| 561 | + EC.text_to_be_present_in_element_value( |
| 562 | + ( |
| 563 | + By.XPATH, |
| 564 | + '//*[@id="flat-json-config-0-context"]/div[2]/div/div/input[1]', |
| 565 | + ), |
| 566 | + "vni", |
| 567 | + ) |
| 568 | + ) |
| 569 | + except TimeoutException: |
| 570 | + self.fail("Timed out waiting for configuration variables to get loaded") |
| 571 | + |
| 572 | + with self.subTest("Navigating away from the page should not show alert"): |
| 573 | + self._override_unsaved_changes_alert() |
| 574 | + # Simulate navigating away from the page |
| 575 | + self.find_element( |
| 576 | + by=By.XPATH, value='//*[@id="main-content"]/div[2]/a[3]' |
| 577 | + ).click() |
| 578 | + if self._is_unsaved_changes_alert_present(): |
| 579 | + self.fail("Unsaved changes alert displayed without any change") |
| 580 | + |
| 581 | + with self.subTest("Saving the objects should not save context variables"): |
| 582 | + self.open(reverse("admin:config_device_change", args=[device.id])) |
| 583 | + self.web_driver.execute_script( |
| 584 | + "window.scrollTo(0, document.body.scrollHeight);" |
| 585 | + ) |
| 586 | + self.find_element( |
| 587 | + by=By.CSS_SELECTOR, value='input[name="_continue"]' |
| 588 | + ).click() |
| 589 | + device.refresh_from_db() |
| 590 | + self.assertEqual(device.config.context, {}) |
| 591 | + |
582 | 592 |
|
583 | 593 | @tag("selenium_tests") |
584 | 594 | class TestVpnAdmin( |
|
0 commit comments