Skip to content

Commit

Permalink
reingest event on subject name change
Browse files Browse the repository at this point in the history
SDCP-794 SDCP-795
  • Loading branch information
petrjasek committed Jul 8, 2024
1 parent 9fdacc2 commit a2e810d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,23 @@ def get_coverage_id(coverage: EmbeddedCoverageItem) -> str:
]


def get_subject_str(subject: Dict[str, str]) -> str:
return ":".join(
[
subject.get("name", ""),
subject.get("qcode", ""),
subject.get("scheme", ""),
subject.get("translations", ""),
]
)


def is_event_updated(new_item: Event, old_item: Event) -> bool:
if new_item.get("name") != old_item.get("name"):
return True
new_subject = set([subject.get("qcode") for subject in new_item.get("subject", [])])
old_subject = set([subject.get("qcode") for subject in old_item.get("subject", [])])
if new_subject != old_subject:
return True
return False
new_subject = set([get_subject_str(subject) for subject in new_item.get("subject", [])])
old_subject = set([get_subject_str(subject) for subject in old_item.get("subject", [])])
return new_subject != old_subject


class EventsService(superdesk.Service):
Expand Down
10 changes: 10 additions & 0 deletions server/planning/tests/events_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ def test_is_new_version():

assert service.is_new_version(new_event, old_event)

new_event["subject"] = [{"qcode": "foo", "name": "Foo"}]
old_event["subject"] = [{"qcode": "foo", "name": "foo"}]

assert service.is_new_version(new_event, old_event)

new_event["subject"] = [{}]
old_event["subject"] = [{"qcode": "foo", "name": "foo"}]

assert service.is_new_version(new_event, old_event)


def test_should_update():
service = EventsService()
Expand Down

0 comments on commit a2e810d

Please sign in to comment.