Skip to content

Commit

Permalink
fix empty associations in NTB NINJS
Browse files Browse the repository at this point in the history
it was sending `{}` instead of a list, won't be there now when empty.
  • Loading branch information
petrjasek committed Jun 7, 2023
1 parent fa6e935 commit 93e8746
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/ntb/publish/ntb_ninjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def convert_dicts_to_lists(ninjs):
for key, value
in ninjs[field].items()
]
elif field in ninjs:
ninjs.pop(field)


class NTBNINJSFormatter(NINJSFormatter):
Expand Down
11 changes: 9 additions & 2 deletions server/ntb/tests/publish/ntb_ninjs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ def setUp(self):
if cv.get("_id") == "place_custom":
self.app.data.insert("vocabularies", [cv])

def format(self):
_, doc = self.formatter.format(self.article, {"name": "Test Subscriber"})[0]
def format(self, updates=None):
article = self.article.copy()
if updates:
article.update(updates)
_, doc = self.formatter.format(article, {"name": "Test Subscriber"})[0]
return json.loads(doc)

def test_format_type(self):
Expand Down Expand Up @@ -386,3 +389,7 @@ def test_planning_ids(self):
{"role": "EVENT-ID", "value": "event-id"},
ninjs["altids"],
)

def test_empty_assocations_renditions(self):
ninjs = self.format({"associations": {"foo": None}})
assert "associations" not in ninjs, ninjs.get("associations")

0 comments on commit 93e8746

Please sign in to comment.