Skip to content

Commit

Permalink
Merge pull request #21 from superdesk/fix-unpublish
Browse files Browse the repository at this point in the history
fix missing `extra.profile_id` after unpublish
  • Loading branch information
petrjasek authored Mar 15, 2024
2 parents de224cc + 3d4bdd3 commit edd106c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions server/tests/test_signal_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from unittest.mock import patch

from tga.signal_hooks import generate_doi


@patch("tga.signal_hooks._generate_short_unique_id")
def test_generate_doi_existing_doi(mock_generate_short_unique_id):
item = {"extra": {"doi": "existing_doi"}}
updates = {}
generate_doi(None, item, updates)
assert item["extra"]["doi"] == "existing_doi"
assert "extra" not in updates

item = {"extra": {}}
updates = {}
generate_doi(None, item, updates)
assert item["extra"]["doi"] is not None
assert item["extra"]["doi"] == updates["extra"]["doi"]


@patch("tga.signal_hooks._generate_short_unique_id")
def test_generate_doi_new_doi(mock_generate_short_unique_id):
item = {"extra": {}}
updates = {}
generate_doi(None, item, updates)
assert item["extra"]["doi"] is not None
assert item["extra"]["doi"] == updates["extra"]["doi"]
4 changes: 3 additions & 1 deletion server/tga/signal_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

def generate_doi(_sender, item, updates):
"""Assign a DOI to this item if one does not already exist"""

item.setdefault("extra", {})
if item["extra"].get("doi"):
return

updates.setdefault("extra", {})
updates["extra"]["doi"] = updates["extra"].get("doi") or item["extra"].get("doi") or _generate_short_unique_id()
item["extra"]["doi"] = updates["extra"]["doi"]
Expand Down

0 comments on commit edd106c

Please sign in to comment.