Skip to content

Commit 99c3d2f

Browse files
authored
[SYNPY-1547] parentWikiId="" Bug (#1165)
* get error response correctly * handle setting parent wiki to none * updates tests * updates integration test * updates unit test * combines logical
1 parent 645f7f5 commit 99c3d2f

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

synapseclient/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4996,7 +4996,7 @@ def _storeWiki(self, wiki: Wiki, createOrUpdate: bool) -> Wiki:
49964996
if createOrUpdate and (
49974997
(
49984998
err.response.status_code == 400
4999-
and "DuplicateKeyException" in err.message
4999+
and "DuplicateKeyException" in err.response.text
50005000
)
50015001
or err.response.status_code == 409
50025002
):

synapseclient/wiki.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ def __init__(self, **kwargs):
122122
kwargs["attachmentFileHandleIds"].append(handle)
123123
del kwargs["fileHandles"]
124124

125+
# if parentWikiId is a falsey value (empty string, None, etc),
126+
# standardize it to None
127+
if "parentWikiId" in kwargs and not kwargs["parentWikiId"]:
128+
kwargs["parentWikiId"] = None
129+
125130
super(Wiki, self).__init__(kwargs)
126131
self.ownerId = id_of(self.owner)
127132
del self["owner"]

tests/integration/synapseclient/test_wikis.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111

1212
@pytest.mark.flaky(reruns=3)
13-
async def test_wikiAttachment(syn: Synapse, project: Project, schedule_for_cleanup):
13+
async def test_wikiAttachment(
14+
syn: Synapse, project: Project, schedule_for_cleanup
15+
) -> None:
1416
# Upload a file to be attached to a Wiki
1517
filename = utils.make_bogus_data_file()
1618
attachname = utils.make_bogus_data_file()
@@ -80,7 +82,7 @@ async def test_wikiAttachment(syn: Synapse, project: Project, schedule_for_clean
8082
pytest.raises(SynapseHTTPError, syn.getWiki, project)
8183

8284

83-
async def test_create_or_update_wiki(syn, project):
85+
async def test_create_or_update_wiki(syn: Synapse, project: Project) -> None:
8486
# create wiki once
8587
syn.store(
8688
Wiki(
@@ -103,7 +105,7 @@ async def test_create_or_update_wiki(syn, project):
103105
assert new_title == syn.getWiki(wiki.ownerId)["title"]
104106

105107

106-
async def test_wiki_version(syn, project):
108+
async def test_wiki_version(syn: Synapse, project: Project) -> None:
107109
# create a new project to avoid artifacts from previous tests
108110
project = syn.store(Project(name=str(uuid.uuid4())))
109111
wiki = syn.store(
@@ -126,3 +128,23 @@ async def test_wiki_version(syn, project):
126128
w2 = syn.getWiki(owner=wiki.ownerId, subpageId=wiki.id, version=1)
127129
assert "version 2" in w2.title
128130
assert "version 2" in w2.markdown
131+
132+
133+
async def test_wiki_with_empty_string_parent_wiki_id(
134+
syn: Synapse, project: Project
135+
) -> None:
136+
# GIVEN a wiki is created with an empty string parentWikiId
137+
# WHEN it is stored
138+
wiki_stored = syn.store(
139+
Wiki(
140+
title="This is the title",
141+
owner=project,
142+
markdown="#Wikis are OK\n\nBlabber jabber blah blah blither blather bonk!",
143+
parentWikiId="",
144+
)
145+
)
146+
# THEN it exists in Synapse
147+
wiki_retrieved = syn.getWiki(owner=wiki_stored.ownerId, subpageId=wiki_stored.id)
148+
# AND when we retrieve it, all attributes are set as expected
149+
for property_name in wiki_stored:
150+
assert wiki_stored[property_name] == wiki_retrieved[property_name]

tests/unit/synapseclient/unit_test_Wiki.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def test_Wiki__with_markdown_file():
2626
adkflajsl;kfjasd;lfkjsal;kfajslkfjasdlkfj
2727
"""
2828
markdown_path = "/somewhere/over/the/rainbow.txt"
29-
with patch(
30-
"synapseclient.wiki.open", mock_open(read_data=markdown_data), create=True
31-
) as mocked_open, patch("os.path.isfile", return_value=True):
29+
with (
30+
patch(
31+
"synapseclient.wiki.open", mock_open(read_data=markdown_data), create=True
32+
) as mocked_open,
33+
patch("os.path.isfile", return_value=True),
34+
):
3235
# method under test
3336
wiki = Wiki(owner="doesn't matter", markdownFile=markdown_path)
3437

@@ -44,9 +47,10 @@ def test_Wiki__markdown_and_markdownFile_both_defined():
4447

4548
def test_Wiki__markdown_is_None_markdownFile_defined():
4649
markdown_path = "/somewhere/over/the/rainbow.txt"
47-
with patch(
48-
"synapseclient.wiki.open", mock_open(), create=True
49-
) as mocked_open, patch("os.path.isfile", return_value=True):
50+
with (
51+
patch("synapseclient.wiki.open", mock_open(), create=True) as mocked_open,
52+
patch("os.path.isfile", return_value=True),
53+
):
5054
# method under test
5155
Wiki(owner="doesn't matter", markdownFile=markdown_path)
5256

@@ -76,3 +80,18 @@ def test_wiki_with_none_attachments(syn: Synapse):
7680
with patch.object(syn, "restPOST"):
7781
w = Wiki(owner="syn1", markdown="markdown", attachments=None)
7882
syn.store(w)
83+
84+
85+
def test_wiki_with_empty_string_parent_wiki_id(syn: Synapse):
86+
with patch.object(syn, "restPOST") as mock_restPOST:
87+
# WHEN a wiki is created with an empty string parentWikiId
88+
w = Wiki(owner="syn1", markdown="markdown", parentWikiId="")
89+
# THEN the parentWikiId is set to None
90+
assert w.parentWikiId is None
91+
# WHEN the wiki is stored
92+
syn.store(w)
93+
# THEN the parentWikiId is set to None in the request
94+
mock_restPOST.assert_called_once_with(
95+
"/entity/syn1/wiki",
96+
'{"markdown": "markdown", "parentWikiId": null, "attachmentFileHandleIds": []}',
97+
)

0 commit comments

Comments
 (0)