Skip to content

Commit 1e659e2

Browse files
authored
Merge pull request #75 from lumapps/add-helper
Add helper
2 parents 3b0f419 + e9aeda3 commit 1e659e2

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lumapps/api/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.1.18"
1+
__version__ = "0.1.19"
22
__pypi_packagename__ = "lumapps-sdk"

lumapps/api/helpers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
copy_with_new_lumapps_uuids,
1111
iter_with_key,
1212
iter_with_key_value,
13+
replace_matching_key_val,
1314
)

lumapps/api/helpers/widgets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,11 @@ def copy_with_new_lumapps_uuids(content):
116116
new_content = deepcopy(content)
117117
set_new_lumapps_uuids(new_content)
118118
return new_content
119+
120+
121+
def replace_matching_key_val(content, key, old_val, new_val):
122+
for d in iter_with_key(content, key):
123+
if d[key] == old_val:
124+
d[key] = new_val
125+
elif isinstance(d[key], list) and old_val in d[key]:
126+
d[key] = [i if i != old_val else new_val for i in d[key]]

tests/test_helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
iter_with_key_value,
1414
set_new_lumapps_uuids,
1515
copy_with_new_lumapps_uuids,
16+
replace_matching_key_val,
1617
)
1718

1819

@@ -168,3 +169,14 @@ def test_copy_with_new_lumapps_uuids():
168169
assert with_uuid[1]["uuid"] != "2ad93c14-0a9d-4d0e-a91b-eb38e1025991"
169170
assert with_uuid[2]["uuid"] != "f0951e06-ffb6-4406-a9c5-97e0be977f94"
170171
assert with_uuid[3]["uuid"] != "ae9aac74-1ee5-45c2-9a57-8e447ad663f3"
172+
173+
174+
def test_replace_matching_key_val():
175+
with open("tests/test_data/community_1.json") as fh:
176+
c = json.load(fh)
177+
replace_matching_key_val(c, "instance", "2222222222", "foo_bar_123")
178+
assert c["instance"] == "foo_bar_123"
179+
tmpl = c["template"]
180+
props = tmpl["components"][0]["cells"][0]["components"][0]["properties"]
181+
assert props["instance"] == ["foo_bar_123"]
182+
assert props["media"][0]["instance"] == "foo_bar_123"

0 commit comments

Comments
 (0)