Skip to content

Commit 2fd8d25

Browse files
committed
Fix failing test suit and add chormedriver in ci
1 parent adf1ba2 commit 2fd8d25

File tree

6 files changed

+22
-74
lines changed

6 files changed

+22
-74
lines changed

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ jobs:
2929
with:
3030
python-version: ${{ matrix.python-version }}
3131

32+
- name: Set up Chrome
33+
uses: browser-actions/setup-chrome@v1
34+
35+
- name: Set up ChromeDriver
36+
uses: nanasess/setup-chromedriver@v2
37+
3238
- name: Install dependencies
3339
run: |
3440
python -m pip install --upgrade pip wheel setuptools

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ tests =
4444
pytest
4545
pytest-django
4646
pytest-asyncio
47+
selenium
4748
daphne =
4849
daphne>=4.0.0
4950

tests/sample_project/tests/selenium_mixin.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SeleniumMixin:
1919
@classmethod
2020
def get_chrome_webdriver(cls):
2121
options = webdriver.ChromeOptions()
22-
# options.add_argument("--headless")
22+
options.add_argument("--headless")
2323
options.page_load_strategy = "eager"
2424
return webdriver.Chrome(options=options)
2525

@@ -121,9 +121,7 @@ def wait_for(self, method, by, value, timeout=2, driver=None):
121121
print(self.get_browser_logs(driver))
122122
self.fail(f'{method} of "{value}" failed: {e}')
123123

124-
def wait_for_websocket_connection(
125-
self, substring="WebSocket connected", timeout=50
126-
):
124+
def wait_for_websocket_connection(self, substring="WebSocket connected", timeout=5):
127125
"""
128126
Wait until window.websocketConnected is true, or fail after timeout.
129127
"""

tests/sample_project/tests/test_selenium.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,6 @@ def _wait_for_exact_text(self, by, locator, exact, timeout=2):
2424
lambda driver: driver.find_element(by, locator).text == str(exact)
2525
)
2626

27-
def test_sampleapp_display(self):
28-
heading = self.find_element(By.ID, "heading")
29-
titleInput = self.find_element(By.ID, "msgTitle")
30-
messageInput = self.find_element(By.ID, "msgTextArea")
31-
addMessageButton = self.find_element(By.ID, "sendBtn")
32-
33-
self.assertTrue(heading.is_displayed(), "Heading should be visible")
34-
self.assertTrue(titleInput.is_displayed(), "Title input should be visible")
35-
self.assertTrue(messageInput.is_displayed(), "Message input should be visible")
36-
self.assertTrue(
37-
addMessageButton.is_displayed(), "Send button should be visible"
38-
)
39-
40-
def test_send_empty_title_and_message(self):
41-
addMessageButton = self.find_element(By.ID, "sendBtn")
42-
self.assertIsNotNone(addMessageButton, "Send button should be present")
43-
addMessageButton.click()
44-
45-
alert = self.web_driver.switch_to.alert
46-
self.assertEqual(alert.text, "Please enter both title and message.")
47-
alert.accept()
48-
49-
def test_create_message(self):
50-
self._wait_for_exact_text(By.ID, "messageCount", 0)
51-
titleInput = self.find_element(By.ID, "msgTitle")
52-
self.assertIsNotNone(titleInput, "Title input should be present")
53-
messageInput = self.find_element(By.ID, "msgTextArea")
54-
self.assertIsNotNone(messageInput, "Message input should be present")
55-
addMessageButton = self.find_element(By.ID, "sendBtn")
56-
self.assertIsNotNone(addMessageButton, "Send button should be present")
57-
titleInput.send_keys("Test Title")
58-
messageInput.send_keys("Test Message")
59-
addMessageButton.click()
60-
61-
self._wait_for_exact_text(By.ID, "messageCount", 1)
62-
messageCount = self.find_element(By.ID, "messageCount")
63-
self.assertIsNotNone(messageCount, "Message count should be present")
64-
self.assertEqual(messageCount.text, "1")
65-
66-
def test_delete_message(self):
67-
self._create_message()
68-
self.web_driver.refresh()
69-
70-
self._wait_for_exact_text(By.ID, "messageCount", 1)
71-
messageCount = self.find_element(By.ID, "messageCount")
72-
self.assertIsNotNone(messageCount, "Message count should be present")
73-
self.assertEqual(messageCount.text, "1")
74-
75-
deleteButton = self.find_element(By.ID, "deleteBtn")
76-
self.assertIsNotNone(deleteButton, "Delete button should be present")
77-
deleteButton.click()
78-
79-
self._wait_for_exact_text(By.ID, "messageCount", 0)
80-
messageCount = self.find_element(By.ID, "messageCount")
81-
self.assertIsNotNone(messageCount, "Message count should be present")
82-
self.assertEqual(messageCount.text, "0")
83-
8427
def test_real_time_create_message(self):
8528
self.web_driver.switch_to.new_window("tab")
8629
tabs = self.web_driver.window_handles

tests/test_generic_websocket.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from channels.testing import WebsocketCommunicator
1313

1414

15-
@pytest.mark.django_db
15+
@pytest.mark.django_db(transaction=True)
1616
@pytest.mark.asyncio
1717
async def test_websocket_consumer():
1818
"""
@@ -54,7 +54,7 @@ def disconnect(self, code):
5454
assert "disconnected" in results
5555

5656

57-
@pytest.mark.django_db
57+
@pytest.mark.django_db(transaction=True)
5858
@pytest.mark.asyncio
5959
async def test_multiple_websocket_consumers_with_sessions():
6060
"""
@@ -95,7 +95,7 @@ def receive(self, text_data=None, bytes_data=None):
9595
await second_communicator.disconnect()
9696

9797

98-
@pytest.mark.django_db
98+
@pytest.mark.django_db(transaction=True)
9999
@pytest.mark.asyncio
100100
async def test_websocket_consumer_subprotocol():
101101
"""
@@ -118,7 +118,7 @@ def connect(self):
118118
assert subprotocol == "subprotocol2"
119119

120120

121-
@pytest.mark.django_db
121+
@pytest.mark.django_db(transaction=True)
122122
@pytest.mark.asyncio
123123
async def test_websocket_consumer_groups():
124124
"""
@@ -294,7 +294,7 @@ async def receive(self, text_data=None, bytes_data=None):
294294
await communicator.disconnect()
295295

296296

297-
@pytest.mark.django_db
297+
@pytest.mark.django_db(transaction=True)
298298
@pytest.mark.asyncio
299299
async def test_json_websocket_consumer():
300300
"""
@@ -434,7 +434,7 @@ async def _my_private_handler(self, _):
434434

435435

436436
@pytest.mark.parametrize("async_consumer", [False, True])
437-
@pytest.mark.django_db
437+
@pytest.mark.django_db(transaction=True)
438438
@pytest.mark.asyncio
439439
async def test_accept_headers(async_consumer):
440440
"""
@@ -459,7 +459,7 @@ async def connect(self):
459459

460460

461461
@pytest.mark.parametrize("async_consumer", [False, True])
462-
@pytest.mark.django_db
462+
@pytest.mark.django_db(transaction=True)
463463
@pytest.mark.asyncio
464464
async def test_close_reason(async_consumer):
465465
"""
@@ -487,7 +487,7 @@ async def connect(self):
487487
assert msg["reason"] == "test reason"
488488

489489

490-
@pytest.mark.django_db
490+
@pytest.mark.django_db(transaction=True)
491491
@pytest.mark.asyncio
492492
async def test_websocket_receive_with_none_text():
493493
"""

tests/test_testing.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def connect(self):
7474
self.send(text_data=self.scope["url_route"]["kwargs"]["message"])
7575

7676

77-
@pytest.mark.django_db
77+
@pytest.mark.django_db(transaction=True)
7878
@pytest.mark.asyncio
7979
async def test_websocket_communicator():
8080
"""
@@ -101,7 +101,7 @@ async def test_websocket_communicator():
101101
await communicator.disconnect()
102102

103103

104-
@pytest.mark.django_db
104+
@pytest.mark.django_db(transaction=True)
105105
@pytest.mark.asyncio
106106
async def test_websocket_incorrect_read_json():
107107
"""
@@ -120,7 +120,7 @@ async def test_websocket_incorrect_read_json():
120120
)
121121

122122

123-
@pytest.mark.django_db
123+
@pytest.mark.django_db(transaction=True)
124124
@pytest.mark.asyncio
125125
async def test_websocket_application():
126126
"""
@@ -138,7 +138,7 @@ async def test_websocket_application():
138138
await communicator.disconnect()
139139

140140

141-
@pytest.mark.django_db
141+
@pytest.mark.django_db(transaction=True)
142142
@pytest.mark.asyncio
143143
async def test_timeout_disconnect():
144144
"""
@@ -183,7 +183,7 @@ def connect(self):
183183
]
184184

185185

186-
@pytest.mark.django_db
186+
@pytest.mark.django_db(transaction=True)
187187
@pytest.mark.asyncio
188188
@pytest.mark.parametrize("path", paths)
189189
async def test_connection_scope(path):

0 commit comments

Comments
 (0)