forked from superdesk/superdesk-planning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid overriding user changes via event ingest
check event history what keys were updated by users and ignore those when updating from ingest. SDCP-861
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from superdesk import get_resource_service | ||
from datetime import datetime, timedelta | ||
from planning.tests import TestCase | ||
from unittest.mock import patch | ||
from flask import g | ||
|
||
|
||
class EventIngestTestCase(TestCase): | ||
def test_ingest_updated_event(self): | ||
events_service = get_resource_service("events") | ||
events_history_service = get_resource_service("events_history") | ||
dates = {"start": datetime.now(), "end": datetime.now() + timedelta(days=1)} | ||
old_event = {"guid": "1", "name": "bar", "ednote": "ednote1", "dates": dates} | ||
|
||
# event is created | ||
events_service.post_in_mongo([old_event]) | ||
|
||
# user updates the event | ||
updates = {"definition_short": "manual", "ednote": "manual"} | ||
with self.app.test_request_context(): | ||
g.user = {"_id": "test"} | ||
events_service.patch(old_event["_id"], updates) | ||
events_history_service.on_item_updated(updates, old_event) | ||
|
||
new_event = {"guid": "1", "name": "updated", "ednote": "updated", "dates": dates, "definition_short": "updated"} | ||
old_event = events_service.find_one(req=None, guid="1") | ||
|
||
# event is updated via ingest | ||
events_service.patch_in_mongo(new_event["guid"], new_event, old_event) | ||
|
||
updated_event = events_service.find_one(req=None, _id="1") | ||
assert updated_event is not None | ||
assert updated_event["name"] == "updated" | ||
assert updated_event["ednote"] == "manual" | ||
assert updated_event["definition_short"] == "manual" |