Skip to content

Commit bf8ac7b

Browse files
authored
[tests:fix] Switched to ChannelsLiveServerTestCase #466
Replaced StaticLiveServerTestCase with ChannelsLiveServerTestCase to resolve JS errors caused by failed websocket connections. Fixes #466
1 parent dd1b06f commit bf8ac7b

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ jobs:
8686
- name: Tests
8787
if: ${{ !cancelled() && steps.deps.conclusion == 'success' }}
8888
run: |
89-
coverage run runtests.py --parallel
89+
coverage run runtests.py --parallel --noinput --exclude-tag=selenium_tests
90+
coverage run runtests.py --noinput --tag=selenium_tests
9091
coverage combine
9192
coverage xml
9293
env:
@@ -103,7 +104,7 @@ jobs:
103104
with:
104105
parallel: true
105106
format: cobertura
106-
flag-name: python-${{ matrix.env.env }}
107+
flag-name: python-${{ matrix.python-version }}-${{ matrix.django-version }}
107108
github-token: ${{ secrets.GITHUB_TOKEN }}
108109

109110
coveralls:

tests/openwisp2/asgi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.core.asgi import get_asgi_application
2+
3+
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: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import expectedFailure
22

3-
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
3+
from channels.testing import ChannelsLiveServerTestCase
4+
from django.test import tag
45
from django.urls import reverse
56
from selenium.common.exceptions import JavascriptException, NoSuchElementException
67
from selenium.webdriver import ActionChains
@@ -11,7 +12,8 @@
1112
from .utils import SeleniumTestMixin
1213

1314

14-
class TestMenu(SeleniumTestMixin, StaticLiveServerTestCase):
15+
@tag("selenium_tests")
16+
class TestMenu(SeleniumTestMixin, ChannelsLiveServerTestCase):
1517
def tearDown(self):
1618
super().tearDown()
1719
# Clear local storage
@@ -360,7 +362,8 @@ def test_menu_on_narrow_screen(self):
360362
self.web_driver.set_window_size(1366, 768)
361363

362364

363-
class TestBasicFilter(SeleniumTestMixin, StaticLiveServerTestCase, CreateMixin):
365+
@tag("selenium_tests")
366+
class TestBasicFilter(SeleniumTestMixin, ChannelsLiveServerTestCase, CreateMixin):
364367
shelf_model = Shelf
365368
book_model = Book
366369

@@ -505,7 +508,8 @@ def test_book_filter(self):
505508
self.assertEqual(paginator.get_attribute("innerText"), "1 book")
506509

507510

508-
class TestInputFilters(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
511+
@tag("selenium_tests")
512+
class TestInputFilters(SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase):
509513
shelf_model = Shelf
510514

511515
def test_input_filters(self):
@@ -595,7 +599,8 @@ def test_input_filters(self):
595599
self.find_element(By.XPATH, user_xpath)
596600

597601

598-
class TestDashboardCharts(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
602+
@tag("selenium_tests")
603+
class TestDashboardCharts(SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase):
599604
def setUp(self):
600605
super().setUp()
601606
self.web_driver.set_window_size(1600, 768)
@@ -613,7 +618,10 @@ def test_pie_chart_zero_annotation(self):
613618
self.assertEqual(annotation_text.text, "0")
614619

615620

616-
class TestAutocompleteFilter(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
621+
@tag("selenium_tests")
622+
class TestAutocompleteFilter(
623+
SeleniumTestMixin, CreateMixin, ChannelsLiveServerTestCase
624+
):
617625
shelf_model = Shelf
618626
book_model = Book
619627

@@ -710,7 +718,8 @@ def test_autocomplete_owner_filter(self):
710718
)
711719

712720

713-
class TestFirefoxSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
721+
@tag("selenium_tests")
722+
class TestFirefoxSeleniumHelpers(SeleniumTestMixin, ChannelsLiveServerTestCase):
714723
def setUp(self):
715724
super().setUp()
716725
self.login()
@@ -748,7 +757,8 @@ def test_find_elements(self):
748757
self.assertTrue(len(divs) > 1)
749758

750759

751-
class TestChromeSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
760+
@tag("selenium_tests")
761+
class TestChromeSeleniumHelpers(SeleniumTestMixin, ChannelsLiveServerTestCase):
752762
browser = "chrome"
753763

754764
def test_get_browser_logs(self):
@@ -757,7 +767,8 @@ def test_get_browser_logs(self):
757767
self.assertEqual(len(self.get_browser_logs()), 1)
758768

759769

760-
class TestSeleniumMixinRetryMechanism(SeleniumTestMixin, StaticLiveServerTestCase):
770+
@tag("selenium_tests")
771+
class TestSeleniumMixinRetryMechanism(SeleniumTestMixin, ChannelsLiveServerTestCase):
761772
retry_delay = 0
762773

763774
@classmethod

0 commit comments

Comments
 (0)