Skip to content

Commit 1fe99dc

Browse files
committed
added tests
1 parent fa35884 commit 1fe99dc

File tree

4 files changed

+71
-21
lines changed

4 files changed

+71
-21
lines changed

dash/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from .version import __version__ # noqa: F401,E402
2222
from ._callback_context import callback_context # noqa: F401,E402
2323
from ._callback import callback, clientside_callback # noqa: F401,E402
24-
from ._get_paths import (
24+
from ._get_paths import ( # noqa: F401,E402
2525
get_asset_url,
2626
get_relative_path,
2727
strip_relative_path,
28-
) # noqa: F401,E402
28+
)

dash/_get_paths.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66

77
def get_asset_url(path):
8-
return real_get_asset_url(CONFIG, path)
8+
return app_get_asset_url(CONFIG, path)
99

1010

11-
def real_get_asset_url(config, path):
11+
def app_get_asset_url(config, path):
1212
if config.assets_external_path:
1313
prefix = config.assets_external_path
1414
else:
@@ -60,10 +60,10 @@ def display_content(path):
6060
return chapters.page_2
6161
```
6262
"""
63-
return real_get_relative_path(CONFIG.requests_pathname_prefix, path)
63+
return app_get_relative_path(CONFIG.requests_pathname_prefix, path)
6464

6565

66-
def real_get_relative_path(requests_pathname, path):
66+
def app_get_relative_path(requests_pathname, path):
6767
if requests_pathname == "/" and path == "":
6868
return "/"
6969
if requests_pathname != "/" and path == "":
@@ -127,10 +127,10 @@ def display_content(path):
127127
`page-1/sub-page-1`
128128
```
129129
"""
130-
return real_strip_relative_path(CONFIG.requests_pathname_prefix, path)
130+
return app_strip_relative_path(CONFIG.requests_pathname_prefix, path)
131131

132132

133-
def real_strip_relative_path(requests_pathname, path):
133+
def app_strip_relative_path(requests_pathname, path):
134134
if path is None:
135135
return None
136136
if (

dash/dash.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ def csp_hashes(self, hash_algorithm="sha256"):
14731473
]
14741474

14751475
def get_asset_url(self, path):
1476-
return _get_paths.real_get_asset_url(self.config, path)
1476+
return _get_paths.app_get_asset_url(self.config, path)
14771477

14781478
def get_relative_path(self, path):
14791479
"""
@@ -1512,7 +1512,9 @@ def display_content(path):
15121512
return chapters.page_2
15131513
```
15141514
"""
1515-
return _get_paths.real_get_relative_path(self.config, path)
1515+
return _get_paths.app_get_relative_path(
1516+
self.config.requests_pathname_prefix, path
1517+
)
15161518

15171519
def strip_relative_path(self, path):
15181520
"""
@@ -1561,7 +1563,9 @@ def display_content(path):
15611563
`page-1/sub-page-1`
15621564
```
15631565
"""
1564-
return _get_paths.real_strip_relative_path(self.config, path)
1566+
return _get_paths.app_strip_relative_path(
1567+
self.config.requests_pathname_prefix, path
1568+
)
15651569

15661570
def _setup_dev_tools(self, **kwargs):
15671571
debug = kwargs.get("debug", False)

tests/unit/test_configs.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
from dash._utils import AttributeDict
1818
from dash._get_paths import (
19-
real_get_asset_url,
20-
real_get_relative_path,
21-
real_strip_relative_path,
19+
app_get_asset_url,
20+
app_get_relative_path,
21+
app_strip_relative_path,
22+
get_asset_url,
23+
get_relative_path,
24+
strip_relative_path,
2225
)
2326

2427

@@ -108,7 +111,7 @@ def test_pathname_prefix_environ_requests(empty_environ):
108111
)
109112
def test_pathname_prefix_assets(empty_environ, req, expected):
110113
config = AttributeDict(assets_external_path=req, assets_url_path="assets")
111-
path = real_get_asset_url(config, "reset.css")
114+
path = app_get_asset_url(config, "reset.css")
112115
assert path == expected
113116

114117

@@ -142,8 +145,51 @@ def test_asset_url(
142145
assets_url_path=assets_url_path,
143146
)
144147

145-
path = app.get_asset_url("reset.css")
146-
assert path == expected
148+
app_path = app.get_asset_url("reset.css")
149+
dash_path = get_asset_url("reset.css")
150+
assert app_path == dash_path == expected
151+
152+
153+
@pytest.mark.parametrize(
154+
"requests_pathname_prefix, expected",
155+
[
156+
(None, "/page2"),
157+
("/app/", "/app/page2"),
158+
],
159+
)
160+
def test_get_relative_path(
161+
empty_environ,
162+
requests_pathname_prefix,
163+
expected,
164+
):
165+
app = Dash(
166+
"Dash",
167+
requests_pathname_prefix=requests_pathname_prefix,
168+
)
169+
app_path = app.get_relative_path("/page2")
170+
dash_path = get_relative_path("/page2")
171+
assert app_path == dash_path == expected
172+
173+
174+
@pytest.mark.parametrize(
175+
"requests_pathname_prefix, expected",
176+
[
177+
(None, "/app/page2"),
178+
("/app/", "/page2"),
179+
],
180+
)
181+
def test_strip_relative_path(
182+
empty_environ,
183+
requests_pathname_prefix,
184+
expected,
185+
):
186+
app = Dash(
187+
"Dash",
188+
requests_pathname_prefix=requests_pathname_prefix,
189+
)
190+
app_path = app.strip_relative_path("/app/page2")
191+
dash_path = strip_relative_path("/app/page2")
192+
assert app_path == dash_path == expected
147193

148194

149195
def test_get_combined_config_dev_tools_ui(empty_environ):
@@ -216,7 +262,7 @@ def test_app_name_server(empty_environ, name, server, expected):
216262
],
217263
)
218264
def test_pathname_prefix_relative_url(prefix, partial_path, expected):
219-
path = real_get_relative_path(prefix, partial_path)
265+
path = app_get_relative_path(prefix, partial_path)
220266
assert path == expected
221267

222268

@@ -226,7 +272,7 @@ def test_pathname_prefix_relative_url(prefix, partial_path, expected):
226272
)
227273
def test_invalid_get_relative_path(prefix, partial_path):
228274
with pytest.raises(_exc.UnsupportedRelativePath):
229-
real_get_relative_path(prefix, partial_path)
275+
app_get_relative_path(prefix, partial_path)
230276

231277

232278
@pytest.mark.parametrize(
@@ -254,7 +300,7 @@ def test_invalid_get_relative_path(prefix, partial_path):
254300
],
255301
)
256302
def test_strip_relative_path(prefix, partial_path, expected):
257-
path = real_strip_relative_path(prefix, partial_path)
303+
path = app_strip_relative_path(prefix, partial_path)
258304
assert path == expected
259305

260306

@@ -268,7 +314,7 @@ def test_strip_relative_path(prefix, partial_path, expected):
268314
)
269315
def test_invalid_strip_relative_path(prefix, partial_path):
270316
with pytest.raises(_exc.UnsupportedRelativePath):
271-
real_strip_relative_path(prefix, partial_path)
317+
app_strip_relative_path(prefix, partial_path)
272318

273319

274320
def test_port_env_fail_str(empty_environ):

0 commit comments

Comments
 (0)