Skip to content

Commit 6602c16

Browse files
committed
fix(rsconnect): ensure meta name is always full pin name
1 parent 777e7d6 commit 6602c16

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

pins/boards.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,29 @@ def pin_write(
245245
A date to store in the Meta.created field. This field may be used as
246246
part of the pin version name.
247247
"""
248+
249+
pin_name = self.path_to_pin(name)
250+
248251
# TODO(docs): describe options for type argument
249252
# TODO(docs): elaborate on default behavior for versioned parameter
250253
# TODO(compat): python pins added a created parameter above
251254
with tempfile.TemporaryDirectory() as tmp_dir:
252255
# create all pin data (e.g. data.txt, save object)
253256
meta = self.prepare_pin_version(
254-
tmp_dir, x, name, type, title, description, metadata, versioned, created
257+
tmp_dir,
258+
x,
259+
pin_name,
260+
type,
261+
title,
262+
description,
263+
metadata,
264+
versioned,
265+
created,
255266
)
256267

257268
# move pin to destination ----
258269
# create pin version folder
259-
dst_pin_path = self.construct_path([self.path_to_pin(name)])
270+
dst_pin_path = self.construct_path([pin_name])
260271
dst_version_path = self.path_to_deploy_version(name, meta.version.version)
261272

262273
try:
@@ -773,6 +784,7 @@ def prepare_pin_version(self, pin_dir_path, x, name: "str | None", *args, **kwar
773784
# TODO(compat): py pins always uses the short name, R pins uses w/e the
774785
# user passed, but guessing people want the long name?
775786
meta = super().prepare_pin_version(pin_dir_path, x, short_name, *args, **kwargs)
787+
meta.name = name
776788

777789
# copy in files needed by index.html ----------------------------------
778790
crnt_files = set([meta.file] if isinstance(meta.file, str) else meta.file)

pins/tests/test_boards.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,20 @@ def test_board_pin_search_name(board, df, search, matches):
301301

302302

303303
@pytest.mark.fs_rsc
304-
def test_board_pin_write_rsc_full_name(df, fs_short): # noqa
305-
board_susan = BoardRsConnect("", fs_short)
306-
board_susan.pin_write(df, "susan/some_df", type="csv")
304+
@pytest.fixture
305+
def board_short(fs_short): # noqa
306+
board_short = BoardRsConnect("", fs_short)
307+
return board_short
308+
309+
310+
@pytest.mark.fs_rsc
311+
def test_board_pin_write_rsc_full_name(df, board_short): # noqa
312+
board_short.pin_write(df, "susan/some_df", type="csv")
307313

308314

309315
@pytest.mark.fs_rsc
310-
def test_board_pin_search_admin_user(df, fs_short, fs_admin): # noqa
311-
board_susan = BoardRsConnect("", fs_short)
312-
board_susan.pin_write(df, "some_df", type="csv")
316+
def test_board_pin_search_admin_user(df, board_short, fs_admin): # noqa
317+
board_short.pin_write(df, "some_df", type="csv")
313318

314319
board_admin = BoardRsConnect("", fs_admin)
315320
search_res = board_admin.pin_search("susan", as_df=False)
@@ -324,6 +329,23 @@ def test_board_pin_search_admin_user(df, fs_short, fs_admin): # noqa
324329
assert isinstance(search_res2.loc[0, "meta"], MetaRaw)
325330

326331

332+
@pytest.mark.fs_rsc
333+
def test_board_pin_meta_is_full_name(df, board_short):
334+
meta = board_short.pin_write(df, "susan/some_df", type="csv")
335+
336+
assert meta.name == "susan/some_df"
337+
338+
meta2 = board_short.pin_write(df, "some_df", type="csv")
339+
assert meta2.name == "susan/some_df"
340+
341+
meta3 = board_short.pin_meta("some_df")
342+
assert meta3.name == "susan/some_df"
343+
344+
345+
def test_board_rsc_path_to_pin_safe(board_short):
346+
assert board_short.path_to_pin("me/some_pin") == "me/some_pin"
347+
348+
327349
# Manual Board Specific =======================================================
328350

329351
from pins.boards import BoardManual # noqa

0 commit comments

Comments
 (0)