Skip to content

Commit a2f7d55

Browse files
authored
Merge pull request #9 from kevin-bates/fix-fetch
Fix fetch fixtures to use jp_base_url
2 parents 1e464af + 9ae8f5f commit a2f7d55

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pytest_jupyter/jupyter_server.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,14 @@ def _configurable_serverapp(
160160
c = Config(config)
161161
c.NotebookNotary.db_file = ":memory:"
162162
token = hexlify(os.urandom(4)).decode("ascii")
163-
url_prefix = "/"
164163
app = ServerApp.instance(
165164
# Set the log level to debug for testing purposes
166165
log_level='DEBUG',
167166
port=http_port,
168167
port_retries=0,
169168
open_browser=False,
170169
root_dir=str(root_dir),
171-
base_url=url_prefix,
170+
base_url=base_url,
172171
config=c,
173172
allow_root=True,
174173
token=token,
@@ -262,9 +261,10 @@ async def my_test(jp_fetch):
262261
"""
263262
def client_fetch(*parts, headers={}, params={}, **kwargs):
264263
# Handle URL strings
265-
path_url = url_escape(url_path_join(jp_base_url, *parts), plus=False)
264+
path_url = url_escape(url_path_join(*parts), plus=False)
265+
base_path_url = url_path_join(jp_base_url, path_url)
266266
params_url = urllib.parse.urlencode(params)
267-
url = path_url + "?" + params_url
267+
url = base_path_url + "?" + params_url
268268
# Add auth keys to header
269269
headers.update(jp_auth_header)
270270
# Make request.
@@ -275,7 +275,7 @@ def client_fetch(*parts, headers={}, params={}, **kwargs):
275275

276276

277277
@pytest.fixture
278-
def jp_ws_fetch(jp_serverapp, jp_auth_header, jp_http_port):
278+
def jp_ws_fetch(jp_serverapp, jp_auth_header, jp_http_port, jp_base_url):
279279
"""Sends a websocket request to a test server.
280280
281281
The fixture is a factory; it can be called like
@@ -303,10 +303,11 @@ async def my_test(jp_fetch, jp_ws_fetch):
303303
"""
304304
def client_fetch(*parts, headers={}, params={}, **kwargs):
305305
# Handle URL strings
306-
path = url_escape(url_path_join(*parts), plus=False)
306+
path_url = url_escape(url_path_join(*parts), plus=False)
307+
base_path_url = url_path_join(jp_base_url, path_url)
307308
urlparts = urllib.parse.urlparse('ws://localhost:{}'.format(jp_http_port))
308309
urlparts = urlparts._replace(
309-
path=path,
310+
path=base_path_url,
310311
query=urllib.parse.urlencode(params)
311312
)
312313
url = urlparts.geturl()

0 commit comments

Comments
 (0)