Skip to content

Commit 0dc09fb

Browse files
committed
add basic test of IDOM
1 parent edeadbe commit 0dc09fb

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

noxfile.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ def test(session: Session) -> None:
4646
@nox.session
4747
def test_suite(session: Session) -> None:
4848
"""Run the Python-based test suite"""
49-
session.env["IDOM_DEBUG_MODE"] = "1"
5049
install_requirements_file(session, "test-env")
5150
session.install(".[all]")
52-
session.chdir("tests")
53-
session.run("figure-it-out")
51+
52+
# build javascript bundle
53+
session.chdir(HERE / "tests" / "js")
54+
session.run("npm", "install", external=True)
55+
session.run("npm", "run", "build", external=True)
56+
57+
# run the test suite
58+
session.chdir(HERE / "tests")
59+
session.env["IDOM_DEBUG_MODE"] = "1"
60+
session.run("python", "manage.py", "test")
5461

5562

5663
@nox.session

requirements/test-env.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
django
2+
selenium
3+
4+
# required due issue with channels:
5+
# https://github.com/django/channels/issues/1639#issuecomment-817994671
6+
twisted<21

src/django_idom/websocket_consumer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from idom.core.layout import Layout
88
from idom.core.dispatcher import dispatch_single_view
9-
from idom.core.component import ComponentConstructor
9+
from idom.core.proto import ComponentConstructor
1010

1111

1212
class IdomAsyncWebSocketConsumer(AsyncJsonWebsocketConsumer):

tests/test_app/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@
7878
DATABASES = {
7979
"default": {
8080
"ENGINE": "django.db.backends.sqlite3",
81-
"NAME": BASE_DIR / "db.sqlite3",
82-
}
81+
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
82+
"TEST": {
83+
"NAME": os.path.join(BASE_DIR, "db_test.sqlite3"),
84+
},
85+
},
8386
}
8487

8588

tests/test_app/tests.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
from django.test import TestCase
1+
from channels.testing import ChannelsLiveServerTestCase
22

3-
# Create your tests here.
3+
from selenium import webdriver
4+
5+
6+
class TestIdomCapabilities(ChannelsLiveServerTestCase):
7+
def test_hello_world(self):
8+
driver = make_driver(5, 5)
9+
driver.get(self.live_server_url)
10+
driver.find_element_by_id("hello-world")
11+
12+
13+
def make_driver(page_load_timeout, implicit_wait_timeout):
14+
driver = webdriver.Chrome()
15+
driver.set_page_load_timeout(page_load_timeout)
16+
driver.implicitly_wait(implicit_wait_timeout)
17+
return driver

0 commit comments

Comments
 (0)