Skip to content

Commit ad6d4e8

Browse files
committed
rewrite tests with dash[testing] #118
1 parent f612bac commit ad6d4e8

7 files changed

+96
-249
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,28 +81,28 @@ jobs:
8181
name: Integration Tests - Usage Apps Rendering
8282
command: |
8383
. venv/bin/activate
84-
python -m unittest tests.test_usage
84+
pytest --headless tests/test_usage.py
8585
when: always
8686

8787
- run:
8888
name: Integration Tests - Interactions
8989
command: |
9090
. venv/bin/activate
91-
python -m unittest tests.test_interactions
91+
pytest --headless tests/test_interactions.py
9292
when: always
9393

9494
- run:
9595
name: Integration Tests - Callbacks
9696
command: |
9797
. venv/bin/activate
98-
python -m unittest tests.test_callbacks
98+
pytest --headless tests/test_callbacks.py
9999
when: always
100100

101101
- run:
102102
name: Capture Percy Snapshots
103103
command: |
104104
. venv/bin/activate
105-
python -m unittest tests.test_percy_snapshot
105+
pytest --headless tests/test_percy_snapshot.py
106106
when: always
107107

108108
"python-3.7":

tests/IntegrationTests.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

tests/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ percy
99
selenium
1010
flake8
1111
pylint
12-
pytest-dash>=2.1.1
1312
colour==0.1.5
1413
biopython>=1.77;python_version>="3.0"
1514
biopython==1.76;python_version=="2.7"

tests/test_callbacks.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
import os
22
import importlib
33

4-
from .IntegrationTests import IntegrationTests
5-
from selenium.webdriver.common.by import By
6-
from selenium.webdriver.support.ui import WebDriverWait
7-
from selenium.webdriver.support import expected_conditions as EC
84
from selenium.webdriver.common.keys import Keys
5+
from selenium.webdriver.common.by import By
96

107

11-
class Tests(IntegrationTests):
12-
def test_callbacks(self):
8+
class Tests:
9+
def test_callbacks(self, dash_duo):
1310
app = importlib.import_module('usage-advanced').app
14-
self.startServer(app)
1511

16-
WebDriverWait(self.driver, 20).until(
17-
EC.presence_of_element_located((By.ID, "cytoscape"))
18-
)
12+
dash_duo.start_server(app)
13+
dash_duo.wait_for_element_by_id("cytoscape", 20)
1914

2015
def create_input_and_save(css_selector,
2116
dir_name,
2217
options,
2318
prefix=None,
2419
name_map=None,
2520
save=True):
26-
elem = self.driver.find_element_by_css_selector(css_selector)
21+
elem = dash_duo.find_element(css_selector)
2722

2823
directory_path = os.path.join(
2924
os.path.dirname(__file__),
@@ -57,9 +52,7 @@ def create_input_and_save(css_selector,
5752
name = name.replace('(', '_').replace(')', '').replace(',', '_')
5853
name = name.replace('#', '_hex_').replace(' ', '')
5954

60-
WebDriverWait(self.driver, 20).until(
61-
EC.presence_of_element_located((By.ID, "cytoscape"))
62-
)
55+
dash_duo.wait_for_element_by_id("cytoscape", 20)
6356

6457
path = os.path.join(
6558
os.path.dirname(__file__),
@@ -68,17 +61,15 @@ def create_input_and_save(css_selector,
6861
name + '.png'
6962
)
7063

71-
self.driver.save_screenshot(path)
64+
dash_duo.driver.save_screenshot(path)
7265

7366
def click_button_and_save(name_to_xpaths, dir_name, save=True):
7467
for name, xpath in name_to_xpaths.items():
75-
button = self.driver.find_element(By.XPATH, xpath)
68+
button = dash_duo.driver.find_element(By.XPATH, xpath)
7669
button.click()
7770

7871
if save:
79-
WebDriverWait(self.driver, 20).until(
80-
EC.presence_of_element_located((By.ID, "cytoscape"))
81-
)
72+
dash_duo.wait_for_element_by_id("cytoscape", 20)
8273

8374
path = os.path.join(
8475
os.path.dirname(__file__),
@@ -87,7 +78,7 @@ def click_button_and_save(name_to_xpaths, dir_name, save=True):
8778
name + '.png'
8879
)
8980

90-
self.driver.save_screenshot(path)
81+
dash_duo.driver.save_screenshot(path)
9182

9283
create_input_and_save(
9384
css_selector='input#dropdown-select-element-list',

tests/test_interactions.py

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,20 @@
2323
import importlib
2424
import time
2525
import json
26-
import platform
2726

28-
from .IntegrationTests import IntegrationTests
29-
from selenium.webdriver.common.by import By
30-
from selenium.webdriver.support.ui import WebDriverWait
31-
from selenium.webdriver.support import expected_conditions as EC
3227
from selenium.webdriver.common.action_chains import ActionChains
3328

3429

35-
class Tests(IntegrationTests):
36-
@classmethod
37-
def setUpClass(cls):
38-
super(Tests, cls).setUpClass()
39-
30+
class Tests:
31+
def create_app(self, dash_duo):
4032
# Initialize the apps
4133
app = importlib.import_module('usage-events').app
42-
cls.startServer(cls, app)
43-
WebDriverWait(cls.driver, 20).until(EC.presence_of_element_located((By.ID, "cytoscape")))
44-
cls.actions = ActionChains(cls.driver)
45-
cls.init_pos = {
34+
35+
dash_duo.start_server(app)
36+
dash_duo.wait_for_element_by_id("cytoscape", 20)
37+
38+
self.actions = ActionChains(dash_duo.driver)
39+
self.init_pos = {
4640
'Node 1': (59, 182),
4741
'Node 2': (222, 345),
4842
'Node 3': (168, 283 - 20),
@@ -51,21 +45,6 @@ def setUpClass(cls):
5145
'Node 6': (168, 283)
5246
}
5347

54-
@classmethod
55-
def tearDownClass(cls):
56-
super(Tests, cls).tearDownClass()
57-
58-
time.sleep(3)
59-
if platform.system() == 'Windows':
60-
cls.driver.get('http://localhost:8050/stop')
61-
else:
62-
cls.server_process.terminate()
63-
time.sleep(3)
64-
cls.driver.quit()
65-
66-
def tearDown(self):
67-
pass
68-
6948
def save_screenshot(self, dir_name, name):
7049
directory_path = os.path.join(
7150
os.path.dirname(__file__),
@@ -77,7 +56,7 @@ def save_screenshot(self, dir_name, name):
7756
if not os.path.exists(directory_path):
7857
os.makedirs(directory_path)
7958

80-
self.driver.save_screenshot(os.path.join(
59+
self.dash_duo.driver.save_screenshot(os.path.join(
8160
os.path.dirname(__file__),
8261
'screenshots',
8362
dir_name,
@@ -96,7 +75,7 @@ def perform_dragging(self, x, y, delta_x, delta_y, elem, actions, dir_name='inte
9675
"""
9776
actions.reset_actions()
9877
actions.move_to_element_with_offset(
99-
self.driver.find_element_by_tag_name('body'), x, y
78+
self.dash_duo.driver.find_element_by_tag_name('body'), x, y
10079
)
10180
actions.drag_and_drop_by_offset(source=None, xoffset=delta_x, yoffset=delta_y)
10281
actions.click()
@@ -127,7 +106,7 @@ def perform_clicking(self, x, y, elem, actions, dir_name='interactions'):
127106
"""
128107
actions.reset_actions()
129108
actions.move_to_element_with_offset(
130-
self.driver.find_element_by_tag_name('body'), x, y
109+
self.dash_duo.driver.find_element_by_tag_name('body'), x, y
131110
)
132111
actions.click()
133112
actions.perform()
@@ -142,7 +121,7 @@ def perform_clicking(self, x, y, elem, actions, dir_name='interactions'):
142121
def perform_mouseover(self, x, y, elem, actions, dir_name='interactions'):
143122
actions.reset_actions()
144123
actions.move_to_element_with_offset(
145-
self.driver.find_element_by_tag_name('body'), x - 50, y
124+
self.dash_duo.driver.find_element_by_tag_name('body'), x - 50, y
146125
)
147126
actions.move_by_offset(50, 0)
148127
actions.perform()
@@ -154,7 +133,10 @@ def perform_mouseover(self, x, y, elem, actions, dir_name='interactions'):
154133

155134
return mouseover_label
156135

157-
def test_dragging(self):
136+
def test_dragging(self, dash_duo):
137+
self.dash_duo = dash_duo
138+
self.create_app(dash_duo)
139+
158140
drag_error = "Unable to drag Cytoscape nodes properly"
159141

160142
# View module docstring for more information about initial positions
@@ -164,7 +146,7 @@ def test_dragging(self):
164146
actions = self.actions
165147

166148
# Select the JSON output element
167-
elem_tap = self.driver.find_element_by_css_selector('pre#tap-node-json-output')
149+
elem_tap = dash_duo.find_element('pre#tap-node-json-output')
168150

169151
# Test dragging the nodes around
170152
offset_x, offset_y = self.perform_dragging(init_x, init_y, 0, 0, elem_tap, actions)
@@ -178,33 +160,38 @@ def test_dragging(self):
178160
assert self.perform_dragging(init_x+150, init_y+150, -150, -150, elem_tap, actions) == \
179161
(-150, -150), drag_error
180162

181-
def test_clicking(self):
163+
def test_clicking(self, dash_duo):
164+
self.dash_duo = dash_duo
165+
self.create_app(dash_duo)
166+
182167
click_error = "Unable to click Cytoscape nodes properly"
183168
actions = self.actions
184169

185170
# Select the JSON output element
186-
elem_tap = self.driver.find_element_by_css_selector('pre#tap-node-json-output')
171+
elem_tap = dash_duo.find_element('pre#tap-node-json-output')
187172

188173
init_pos = self.init_pos
189174
# Test clicking the nodes
190175
for i in range(1, 7):
191176
label = 'Node {}'.format(i)
192177
assert self.perform_clicking(*init_pos[label], elem_tap, actions) == label, click_error
193178

194-
def test_mouseover(self):
179+
def test_mouseover(self, dash_duo):
180+
self.dash_duo = dash_duo
181+
self.create_app(dash_duo)
182+
195183
init_pos = self.init_pos
196184
mouseover_error = "Unable to mouseover Cytoscape nodes properly"
197185
actions = self.actions
198186

199187
# Open the Mouseover JSON tab
200188
actions.move_to_element(
201-
self.driver.find_element_by_css_selector('#tabs > div:nth-child(3)'))
189+
dash_duo.find_element('#tabs > div:nth-child(3)'))
202190
actions.click().perform()
203191
time.sleep(1)
204192

205193
# Select the JSON output element
206-
elem_mouseover = self.driver.find_element_by_css_selector(
207-
'pre#mouseover-node-data-json-output')
194+
elem_mouseover = dash_duo.find_element('pre#mouseover-node-data-json-output')
208195

209196
# Test hovering the nodes
210197
for i in range(1, 7):

0 commit comments

Comments
 (0)