Skip to content

Commit ee2d9f8

Browse files
committed
[change:tests] Switch to ChannelsLiveServerTestCase #904
Replaced StaticLiveServerTestCase with ChannelsLiveServerTestCase to resolve JS errors caused by failed websocket connections. Fixes #904
1 parent cb0a85a commit ee2d9f8

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ jobs:
2929
- django~=4.2.0
3030
- django~=5.0.0
3131
- django~=5.1.0
32-
- django~=5.2rc0
32+
- django~=5.2.0
3333
exclude:
3434
# Django 5.0+ requires Python >=3.10
3535
- python-version: "3.9"
3636
django-version: django~=5.0.0
3737
- python-version: "3.9"
3838
django-version: django~=5.1.0
3939
- python-version: "3.9"
40-
django-version: django~=5.2rc0
40+
django-version: django~=5.2.0
4141
# Python 3.13 supported only in Django >=5.1.3
4242
- python-version: "3.13"
4343
django-version: django~=4.2.0
@@ -86,7 +86,7 @@ jobs:
8686
- name: Tests
8787
if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
8888
run: |
89-
coverage run runtests.py --parallel
89+
coverage run runtests.py
9090
coverage combine
9191
coverage xml
9292
env:

tests/openwisp2/asgi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
3+
from django.core.asgi import get_asgi_application
4+
5+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openwisp2.settings')
6+
application = get_asgi_application()

tests/openwisp2/settings.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@
7777
]
7878

7979
DATABASES = {
80-
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'openwisp_utils.db'}
80+
'default': {
81+
'ENGINE': 'django.db.backends.sqlite3',
82+
'NAME': 'openwisp_utils.db',
83+
'TEST': {
84+
'NAME': 'openwisp_utils_test.db',
85+
},
86+
}
8187
}
8288
TEST_RUNNER = 'openwisp_utils.metric_collection.tests.runner.MockRequestPostRunner'
8389
OPENWISP_ADMIN_SITE_CLASS = 'test_project.site.CustomAdminSite'
@@ -125,7 +131,7 @@
125131
CELERY_TASK_ALWAYS_EAGER = True
126132
CELERY_TASK_EAGER_PROPAGATES = True
127133
CELERY_BROKER_URL = 'memory://'
128-
134+
ASGI_APPLICATION = 'openwisp2.asgi.application'
129135
# local settings must be imported before test runner otherwise they'll be ignored
130136
try:
131137
from local_settings import * # noqa

tests/test_project/tests/test_selenium.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
21
from django.urls import reverse
32
from selenium.common.exceptions import JavascriptException, NoSuchElementException
43
from selenium.webdriver import ActionChains
54
from selenium.webdriver.common.by import By
65

76
from ..models import Book, Operator, Shelf
87
from . import CreateMixin
9-
from .utils import SeleniumTestMixin
8+
from .utils import ChannelsLiveServerTestCase, SeleniumTestMixin
109

1110

12-
class TestMenu(SeleniumTestMixin, StaticLiveServerTestCase):
11+
class TestMenu(SeleniumTestMixin, ChannelsLiveServerTestCase):
1312
def tearDown(self):
1413
super().tearDown()
1514
# Clear local storage
@@ -358,7 +357,7 @@ def test_menu_on_narrow_screen(self):
358357
self.web_driver.set_window_size(1366, 768)
359358

360359

361-
class TestBasicFilter(SeleniumTestMixin, StaticLiveServerTestCase, CreateMixin):
360+
class TestBasicFilter(SeleniumTestMixin, ChannelsLiveServerTestCase, CreateMixin):
362361
shelf_model = Shelf
363362
book_model = Book
364363

@@ -503,7 +502,7 @@ def test_book_filter(self):
503502
self.assertEqual(paginator.get_attribute('innerText'), '1 book')
504503

505504

506-
class TestInputFilters(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
505+
class TestInputFilters(SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase):
507506
shelf_model = Shelf
508507

509508
def test_input_filters(self):
@@ -593,7 +592,7 @@ def test_input_filters(self):
593592
self.find_element(By.XPATH, user_xpath)
594593

595594

596-
class TestDashboardCharts(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
595+
class TestDashboardCharts(SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase):
597596
def setUp(self):
598597
super().setUp()
599598
self.web_driver.set_window_size(1600, 768)
@@ -611,7 +610,9 @@ def test_pie_chart_zero_annotation(self):
611610
self.assertEqual(annotation_text.text, '0')
612611

613612

614-
class TestAutocompleteFilter(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
613+
class TestAutocompleteFilter(
614+
SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase
615+
):
615616
shelf_model = Shelf
616617
book_model = Book
617618

@@ -708,7 +709,7 @@ def test_autocomplete_owner_filter(self):
708709
)
709710

710711

711-
class TestFirefoxSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
712+
class TestFirefoxSeleniumHelpers(SeleniumTestMixin, ChannelsLiveServerTestCase):
712713
def setUp(self):
713714
super().setUp()
714715
self.login()
@@ -746,7 +747,7 @@ def test_find_elements(self):
746747
self.assertTrue(len(divs) > 1)
747748

748749

749-
class TestChromeSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
750+
class TestChromeSeleniumHelpers(SeleniumTestMixin, ChannelsLiveServerTestCase):
750751
browser = 'chrome'
751752

752753
def test_get_browser_logs(self):

tests/test_project/tests/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import os
33
import uuid
44

5+
from channels.testing import (
6+
ChannelsLiveServerTestCase as BaseChannelsLiveServerTestCase,
7+
)
58
from django.contrib.auth import get_user_model
69
from django.contrib.auth.models import AnonymousUser
710
from openwisp_utils.tests import SeleniumTestMixin as BaseSeleniumTestMixin
@@ -194,6 +197,10 @@ def wait_for_dropdown(self, filter_class):
194197
self.wait_for_visibility(By.CSS_SELECTOR, f'.{filter_class} .filter-options')
195198

196199

200+
class ChannelsLiveServerTestCase(BaseChannelsLiveServerTestCase):
201+
server_static = True
202+
203+
197204
class MockUser:
198205
def __init__(self, is_superuser=False):
199206
self.is_superuser = is_superuser

0 commit comments

Comments
 (0)