Skip to content

Commit 449f82a

Browse files
author
karosc
committed
adjust _add_assts_resource to use get_asset_url
1 parent 68042fd commit 449f82a

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

dash/dash.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,10 +1100,7 @@ def _setup_server(self):
11001100
def _add_assets_resource(self, url_path, file_path):
11011101
res = {"asset_path": url_path, "filepath": file_path}
11021102
if self.config.assets_external_path:
1103-
res["external_url"] = "/".join([
1104-
self.config.assets_external_path.rstrip('/'), self.config.assets_url_path.strip('/'), url_path.lstrip('/')
1105-
]
1106-
)
1103+
res["external_url"] = self.get_asset_url(url_path.lstrip("/"))
11071104
self._assets_files.append(file_path)
11081105
return res
11091106

@@ -1193,11 +1190,7 @@ def get_asset_url(self, path):
11931190
else:
11941191
prefix = self.config.requests_pathname_prefix
11951192

1196-
asset = get_asset_path(
1197-
prefix,
1198-
path,
1199-
self.config.assets_url_path.lstrip("/")
1200-
)
1193+
asset = get_asset_path(prefix, path, self.config.assets_url_path.lstrip("/"))
12011194

12021195
return asset
12031196

tests/unit/test_configs.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,34 @@ def test_pathname_prefix_assets(empty_environ, req, expected):
108108
@pytest.mark.parametrize(
109109
"requests_pathname_prefix, assets_external_path, assets_url_path, expected",
110110
[
111-
(None , None , "assets" , "/assets/reset.css"),
112-
("/app/" , None , "assets" , '/app/assets/reset.css'),
113-
(None , None , "css" , "/css/reset.css"),
114-
("/app/" , None , "css" , "/app/css/reset.css"),
115-
(None , "http://external.com/", "assets" , "http://external.com/assets/reset.css"),
116-
("/app/" , "http://external.com/", "css" , "http://external.com/css/reset.css"),
117-
118-
],)
119-
def test_asset_url(empty_environ, requests_pathname_prefix, assets_external_path, assets_url_path, expected):
120-
app = Dash('Dash',
121-
requests_pathname_prefix=requests_pathname_prefix,
122-
assets_external_path=assets_external_path,
123-
assets_url_path=assets_url_path
124-
)
125-
126-
path = app.get_asset_url('reset.css')
111+
(None, None, "assets", "/assets/reset.css"),
112+
("/app/", None, "assets", "/app/assets/reset.css"),
113+
(None, None, "css", "/css/reset.css"),
114+
("/app/", None, "css", "/app/css/reset.css"),
115+
(
116+
None,
117+
"http://external.com/",
118+
"assets",
119+
"http://external.com/assets/reset.css",
120+
),
121+
("/app/", "http://external.com/", "css", "http://external.com/css/reset.css"),
122+
],
123+
)
124+
def test_asset_url(
125+
empty_environ,
126+
requests_pathname_prefix,
127+
assets_external_path,
128+
assets_url_path,
129+
expected,
130+
):
131+
app = Dash(
132+
"Dash",
133+
requests_pathname_prefix=requests_pathname_prefix,
134+
assets_external_path=assets_external_path,
135+
assets_url_path=assets_url_path,
136+
)
137+
138+
path = app.get_asset_url("reset.css")
127139
assert path == expected
128140

129141

0 commit comments

Comments
 (0)