Skip to content

Commit 705c03d

Browse files
committed
[tests] Fixed tests for for deleting device
1 parent 8818436 commit 705c03d

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

openwisp_controller/config/tests/test_selenium.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
24
from django.test import tag
35
from django.urls.base import reverse
@@ -246,8 +248,13 @@ def test_force_delete_device_with_deactivating_config(self):
246248
By.CSS_SELECTOR, '#deactivating-warning .messagelist .warning p'
247249
)
248250
self.find_element(by=By.CSS_SELECTOR, value='#warning-ack').click()
251+
# After accepting the warning, wee need to wait for the animation
252+
# to complete before trying to interact with the button,
253+
# otherwise the test may fail due to the button not being fully
254+
# visible or clickable yet.
255+
time.sleep(0.5)
249256
delete_confirm = self.find_element(
250-
By.CSS_SELECTOR, 'form[method="post"] input[type="submit"]'
257+
By.CSS_SELECTOR, 'form[method="post"] input[type="submit"]', timeout=10
251258
)
252259
delete_confirm.click()
253260
self.assertEqual(Device.objects.count(), 0)

runtests.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,30 @@
66
import sys
77

88

9-
def run_tests(args, settings_module):
9+
def run_tests(extra_args, settings_module, test_app):
1010
"""
1111
Run Django tests with the specified settings module in a separate subprocess.
1212
Executes the command inside the 'tests/' directory.
1313
"""
14-
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
15-
result = subprocess.run(['python', 'manage.py'] + args, cwd='tests')
14+
args = []
15+
if os.environ.get('COVERAGE_RUN', False):
16+
args.extend(['coverage', 'run'])
17+
args.extend(
18+
[
19+
'./tests/manage.py',
20+
'test',
21+
test_app,
22+
'--settings',
23+
settings_module,
24+
'--pythonpath',
25+
'tests',
26+
]
27+
)
28+
args.extend(extra_args)
29+
result = subprocess.run(args)
1630
if result.returncode != 0:
17-
sys.exit(result.returncode) # Exit immediately if tests fail
31+
# Exit immediately if tests fail
32+
sys.exit(result.returncode)
1833

1934

2035
if __name__ == '__main__':
@@ -29,19 +44,17 @@ def run_tests(args, settings_module):
2944
test_app = 'openwisp2'
3045
app_dir = 'tests/openwisp2/'
3146
# Run all tests except Selenium tests using SQLite
32-
sqlite_args = ['test', test_app, '--exclude-tag', 'selenium_tests'] + base_args
33-
run_tests(sqlite_args, 'openwisp2.settings')
47+
sqlite_args = ['--exclude-tag', 'selenium_tests'] + base_args
48+
run_tests(sqlite_args, 'openwisp2.settings', test_app)
3449

3550
# Run Selenium tests using PostgreSQL
3651
psql_args = [
37-
'test',
38-
test_app,
3952
'--tag',
4053
'db_tests',
4154
'--tag',
4255
'selenium_tests',
4356
] + base_args
44-
run_tests(psql_args, 'openwisp2.postgresql_settings')
57+
run_tests(psql_args, 'openwisp2.postgresql_settings', test_app)
4558

4659
# Run pytest tests
4760
result = subprocess.run(

0 commit comments

Comments
 (0)