Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-5906] ingest of json event format #1566

Merged
2 changes: 2 additions & 0 deletions server/planning/feed_parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

from superdesk.io.registry import register_feed_parser
from .ics_2_0 import IcsTwoFeedParser
from .superdesk_event_json import EventJsonFeedParser

register_feed_parser(IcsTwoFeedParser.NAME, IcsTwoFeedParser())
register_feed_parser(EventJsonFeedParser.NAME, EventJsonFeedParser())
178 changes: 178 additions & 0 deletions server/planning/feed_parsers/event_format_sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
{
"_current_version": 6374718192158218,
"_time_to_be_confirmed": false,
"event_contact_info": [
{
"is_active": true,
"_updated": "2019-08-29T13:01:54+0000",
"mobile": [],
"first_name": "Jan",
"last_name": "Christian Kolst\u00f8",
"_created": "2019-08-29T13:01:54+0000",
"public": true,
"_id": "5d67ccc2fdf5baac5c93745c",
"contact_phone": [
{
"is_active": true,
"usage": "",
"number": "92056081",
"public": true
}
],
"contact_email": [
"jck@kud.dep.no"
]
}
],
"state_reason": null,
"place": [
{
"qcode": "random123",
"name": "random123"
}
],
"item_id": "835d5175-a2bc-41ad-a906-baf3f2281a5c",
"schedule_settings": {
"time_zone": null,
"utc_publish_schedule": null
},
"internal_note": "TEST Internal note",
"plans": [],
"pubstatus": "usable",
"name": "TEST Event name",
"_created": "2021-01-25T14:31:52+0000",
"calendars": [
{
"is_active": true,
"qcode": "sport",
"name": "Sport"
},
{
"is_active": true,
"qcode": "finance",
"name": "Finance"
},
{
"qcode": "random123",
"name": "random123"
}
],
"firstcreated": "2021-01-25T14:31:52+0000",
"files": [
"600ed567b481422b366e9063",
"600ed573209d2bdea5bdc35a"
],
"definition_short": "TEST Description",
"subject": [
{
"service": {
"s": 1,
"t": 1,
"e": 1,
"m": 1,
"n": 1,
"i": 1
},
"scheme": "category",
"qcode": "Sport",
"name": "Sport"
},
{
"parent": "05000000",
"scheme": "subject_custom",
"qcode": "05005000",
"name": "Skoler"
},
{
"parent": null,
"scheme": "subject_custom",
"qcode": "05000000",
"name": "Utdanning"
},
{
"parent": "15000000",
"scheme": "subject_custom",
"qcode": "15054000",
"name": "Fotball"
},
{
"service": {
"s": 1,
"j": 1,
"t": 1,
"e": 1,
"m": 1,
"n": 1,
"i": 1
},
"scheme": "category",
"qcode": "Innenriks",
"name": "Innenriks"
},
{
"qcode": "random123",
"name": "random123"
}
],
"links": [
"https://www.ntb.no",
"https://www.sourcefabric.org"
],
"definition_long": "TEST Long description",
"_updated": "2021-01-25T14:32:01+0000",
"state": "scheduled",
"_id": "835d5175-a2bc-41ad-a906-baf3f2281a5c",
"actioned_date": null,
"location": [
{
"qcode": "835d5175-a2bc-41ad-a906-baf3f2281a5c",
"address": {
"area": "Oslo",
"line": [
"Operagata"
],
"locality": "Oslo",
"postal_code": "0194",
"type": "unclassified",
"boundingbox": [
"59.9072822",
"59.9075653",
"10.755855",
"10.7570023"
],
"country": "Norway"
},
"name": "Operagata",
"location": {
"lon": 10.756074,
"lat": 59.9075113
}
}
],
"anpa_category": [
{
"qcode": "n",
"language": "nb-NO",
"name": "Nyhetstjenesten",
"selection_type": "multi selection"
},
{
"qcode": "random123",
"name": "random123"
}
],
"guid": "835d5175-a2bc-41ad-a906-baf3f2281a5c",
"dates": {
"tz": "Europe/Prague",
"start": "2021-03-01T14:00:41+0000",
"end": "2021-03-01T15:00:41+0000"
},
"type": "event",
"versioncreated": "2021-01-25T14:32:01+0000",
"occur_status": {
"qcode": "random123",
"name": "random123"
},
"slugline": "TEST slugline",
"ednote": "TEST editorial note"
}
62 changes: 62 additions & 0 deletions server/planning/feed_parsers/event_json_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from planning.feed_parsers.superdesk_event_json import EventJsonFeedParser
import os
from planning.tests import TestCase
from superdesk import get_resource_service


class EventJsonFeedParserTestCase(TestCase):

sample_json = {}

def setUp(self):
super().setUp()
dir_path = os.path.dirname(os.path.realpath(__file__))
self.sample_json = os.path.join(dir_path, 'event_format_sample.json')

def test_event_json_feed_parser_can_parse(self):
self.assertEqual(True, EventJsonFeedParser().can_parse(self.sample_json))

def test_event_json_feed_parser_parse(self):
with self.app.app_context():

random_event = {'is_active': True, 'name': 'random123', 'qcode': 'random123'}
assign_from_local_cv = {
'anpa_category': 'categories',
'calendars': 'event_calendars',
'place': 'locators',
'occur_status': 'eventoccurstatus'
}

# add the random event items for above fields.
for field in assign_from_local_cv:

self.app.data.insert('vocabularies', [{
"_id": assign_from_local_cv[field],
"type": "manageable",
"unique_field": "qcode",
"selection_type": "do not show",
"items": [
{'is_active': True, 'name': 'random123', 'qcode': 'random123'}
]
}])

events = EventJsonFeedParser().parse(self.sample_json)
for field in assign_from_local_cv.keys():

# check if the same random is returned after parsing as inserted above.
if events[0].get(field):
if field == 'occur_status':
self.assertTrue(True, (events[0][field]['qcode'] == random_event['qcode']))
else:
self.assertTrue(True, (random_event['qcode'] in [event['qcode'] for event in events[0][field]]))

# check if locations and contacts are created.
location = get_resource_service('locations').find_one(req=None, _id='835d5175-a2bc-41ad-a906-baf3f2281a5c')
contact = get_resource_service('contacts').find_one(req=None, _id='5d67ccc2fdf5baac5c93745c')

self.assertTrue(True, location)
self.assertTrue(True, contact)

# remove the locations and contacts added.
get_resource_service('locations').delete(location)
get_resource_service('contacts').delete(contact)
Loading