Skip to content

Commit 0666a9b

Browse files
authored
[tests] Fixed selenium test imports
1 parent 84abe37 commit 0666a9b

File tree

3 files changed

+39
-42
lines changed

3 files changed

+39
-42
lines changed

openwisp_controller/config/tests/test_selenium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from openwisp_users.tests.utils import TestOrganizationMixin
1717

18-
from ...tests.utils import SeleniumTestMixin
18+
from ...tests.test_selenium import SeleniumTestMixin
1919
from .utils import CreateConfigTemplateMixin
2020

2121

openwisp_controller/tests/test_selenium.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,50 @@
1515
from openwisp_controller.connection.tests.utils import CreateConnectionsMixin
1616
from openwisp_controller.geo.tests.utils import TestGeoMixin
1717

18-
from .utils import SeleniumTestMixin
19-
2018
Device = load_model('config', 'Device')
2119
DeviceConnection = load_model('connection', 'DeviceConnection')
2220
Location = load_model('geo', 'Location')
2321
DeviceLocation = load_model('geo', 'DeviceLocation')
2422

2523

24+
class SeleniumTestMixin:
25+
"""
26+
A base test case for Selenium, providing helped methods for generating
27+
clients and logging in profiles.
28+
"""
29+
30+
def open(self, url, driver=None):
31+
"""
32+
Opens a URL
33+
Argument:
34+
url: URL to open
35+
driver: selenium driver (default: cls.base_driver)
36+
"""
37+
if not driver:
38+
driver = self.web_driver
39+
driver.get(f'{self.live_server_url}{url}')
40+
41+
def login(self, username=None, password=None, driver=None):
42+
"""
43+
Log in to the admin dashboard
44+
Argument:
45+
driver: selenium driver (default: cls.web_driver)
46+
username: username to be used for login (default: cls.admin.username)
47+
password: password to be used for login (default: cls.admin.password)
48+
"""
49+
if not driver:
50+
driver = self.web_driver
51+
if not username:
52+
username = self.admin_username
53+
if not password:
54+
password = self.admin_password
55+
driver.get(f'{self.live_server_url}/admin/login/')
56+
if 'admin/login' in driver.current_url:
57+
driver.find_element(by=By.NAME, value='username').send_keys(username)
58+
driver.find_element(by=By.NAME, value='password').send_keys(password)
59+
driver.find_element(by=By.XPATH, value='//input[@type="submit"]').click()
60+
61+
2662
class TestDeviceConnectionInlineAdmin(
2763
CreateConnectionsMixin, TestGeoMixin, SeleniumTestMixin, StaticLiveServerTestCase
2864
):

openwisp_controller/tests/utils.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from django.contrib.auth import get_user_model
22
from django.urls import reverse
3-
from selenium.webdriver.common.by import By
43

54
from openwisp_users.tests.utils import TestMultitenantAdminMixin
65

@@ -17,41 +16,3 @@ def _test_changelist_recover_deleted(self, app_label, model_label):
1716

1817
def _login(self, username='admin', password='tester'):
1918
self.client.force_login(user_model.objects.get(username=username))
20-
21-
22-
class SeleniumTestMixin:
23-
"""
24-
A base test case for Selenium, providing helped methods for generating
25-
clients and logging in profiles.
26-
"""
27-
28-
def open(self, url, driver=None):
29-
"""
30-
Opens a URL
31-
Argument:
32-
url: URL to open
33-
driver: selenium driver (default: cls.base_driver)
34-
"""
35-
if not driver:
36-
driver = self.web_driver
37-
driver.get(f'{self.live_server_url}{url}')
38-
39-
def login(self, username=None, password=None, driver=None):
40-
"""
41-
Log in to the admin dashboard
42-
Argument:
43-
driver: selenium driver (default: cls.web_driver)
44-
username: username to be used for login (default: cls.admin.username)
45-
password: password to be used for login (default: cls.admin.password)
46-
"""
47-
if not driver:
48-
driver = self.web_driver
49-
if not username:
50-
username = self.admin_username
51-
if not password:
52-
password = self.admin_password
53-
driver.get(f'{self.live_server_url}/admin/login/')
54-
if 'admin/login' in driver.current_url:
55-
driver.find_element(by=By.NAME, value='username').send_keys(username)
56-
driver.find_element(by=By.NAME, value='password').send_keys(password)
57-
driver.find_element(by=By.XPATH, value='//input[@type="submit"]').click()

0 commit comments

Comments
 (0)