Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Apr 15, 2024
1 parent 77c1c6e commit f3647b8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion superdesk/io/commands/update_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def ingest_item(item, provider, feeding_service, rule_set=None, routing_scheme=N
f"updating items is disabled on provider '{provider['name']}'."
)
return False, []
elif old_item and old_item.get("version_creator"):
elif old_item and not ingest_service.should_update(old_item):
logger.warning(f"Resource '{ingest_collection}' " f"item '{item[GUID_FIELD]}' is already edited in SD .")
return False, []

Expand Down
3 changes: 3 additions & 0 deletions superdesk/io/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,6 @@ def on_deleted(self, docs):
user = get_user(required=True)
if docs:
push_notification("item:deleted", item=str(docs[0].get(config.ID_FIELD)), user=str(user))

def should_update(self, old_item):
return True
76 changes: 74 additions & 2 deletions tests/io/update_ingest_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ def test_edited_planning_item_is_not_update(self):
"content_expiry": 525700,
}
event_service = get_resource_service("events")
events_post_service = get_resource_service("events_post")

# ingest first version
ingested, ids = ingest_item(item, provider=provider, feeding_service={})
self.assertTrue(ingested)
self.assertIn(item["guid"], ids)
Expand All @@ -699,11 +702,80 @@ def test_edited_planning_item_is_not_update(self):
self.assertEqual(dest["state"], "ingested")
self.assertEqual(dest.get("version_creator"), None)

# edit event
event_service.patch(dest["_id"], {"name": "Edit event Name", "update_method": "single"})
dest = list(event_service.get_from_mongo(req=None, lookup={"guid": item["guid"]}))[0]
self.assertEqual(dest.get("version_creator"), "current_user_id")

# version_creator, if it is there then cancel the update and return []
# update event
ingested, ids = ingest_item(item, provider=provider, feeding_service={})
self.assertFalse(ingested)
self.assertEqual([], ids)

def test_unpublished_event_is_not_update(self):
item = {
"guid": "urn:onclusive:411202222",
"type": "event",
"state": "ingested",
"occur_status": {
"qcode": "eocstat:eos5",
"name": "Planned, occurs certainly",
"label": "Planned, occurs certainly",
},
"pubstatus": "usable",
"versioncreated": datetime(2022, 5, 10, 11, 14, 34),
"firstcreated": datetime(2022, 5, 10, 11, 14, 34),
"name": "Annual Forum on Anti-Money Laundering and Financial Crime",
"definition_short": "",
"dates": {
"start": datetime(2022, 5, 10, 11, 14, 34),
"end": datetime(2022, 5, 10, 11, 14, 34),
"all_day": True,
},
}
flask.g.user = {"_id": "current_user_id"}

provider = {
"_id": "asdnjsandkajsdnjkasnd",
"source": "sf",
"name": "Onclusive",
"content_expiry": 525700,
}
event_service = get_resource_service("events")
events_post_service = get_resource_service("events_post")

# ingest first version
ingested, ids = ingest_item(item, provider=provider, feeding_service={})
self.assertTrue(ingested)
self.assertIn(item["guid"], ids)

# post an event
events_post_service.post(
[
{
"event": item["_id"],
"pubstatus": "usable",
"update_method": "single",
}
]
)
dest = list(event_service.get_from_mongo(req=None, lookup={"guid": item["guid"]}))[0]
self.assertEqual(dest.get("state"), "scheduled")

# Un-post an event
events_post_service.post(
[
{
"event": item["_id"],
"pubstatus": "cancelled",
"update_method": "single",
}
]
)
dest = list(event_service.get_from_mongo(req=None, lookup={"guid": item["guid"]}))[0]
self.assertEqual(dest.get("state"), "killed")

# update an event
ingested, ids = ingest_item(item, provider=provider, feeding_service={})
self.assertFalse(ingested)
self.assertNotIn(item["guid"], ids)
self.assertEqual([], ids)

0 comments on commit f3647b8

Please sign in to comment.