Skip to content

Commit 1e4e8dc

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

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
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: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,36 @@
55
import subprocess
66
import sys
77

8+
import pytest
89

9-
def run_tests(args, settings_module):
10+
11+
def exec_command(args):
12+
"""
13+
Execute a command in a subprocess.
14+
"""
15+
if os.environ.get('COVERAGE_RUN', False):
16+
args = ['coverage', 'run'] + args
17+
result = subprocess.run(args)
18+
if result.returncode != 0:
19+
sys.exit(result.returncode)
20+
21+
22+
def run_tests(extra_args, settings_module, test_app):
1023
"""
1124
Run Django tests with the specified settings module in a separate subprocess.
1225
Executes the command inside the 'tests/' directory.
1326
"""
14-
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
15-
result = subprocess.run(['python', 'manage.py'] + args, cwd='tests')
16-
if result.returncode != 0:
17-
sys.exit(result.returncode) # Exit immediately if tests fail
27+
args = [
28+
'./tests/manage.py',
29+
'test',
30+
test_app,
31+
'--settings',
32+
settings_module,
33+
'--pythonpath',
34+
'tests',
35+
]
36+
args.extend(extra_args)
37+
exec_command(args)
1838

1939

2040
if __name__ == '__main__':
@@ -29,23 +49,17 @@ def run_tests(args, settings_module):
2949
test_app = 'openwisp2'
3050
app_dir = 'tests/openwisp2/'
3151
# 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')
52+
sqlite_args = ['--exclude-tag', 'selenium_tests'] + base_args
53+
run_tests(sqlite_args, 'openwisp2.settings', test_app)
3454

3555
# Run Selenium tests using PostgreSQL
3656
psql_args = [
37-
'test',
38-
test_app,
3957
'--tag',
4058
'db_tests',
4159
'--tag',
4260
'selenium_tests',
4361
] + base_args
44-
run_tests(psql_args, 'openwisp2.postgresql_settings')
62+
run_tests(psql_args, 'openwisp2.postgresql_settings', test_app)
4563

4664
# Run pytest tests
47-
result = subprocess.run(
48-
['pytest', app_dir],
49-
)
50-
if result.returncode != 0:
51-
sys.exit(result.returncode) # Exit immediately if tests fail
65+
sys.exit(pytest.main([app_dir]))

0 commit comments

Comments
 (0)