Skip to content

Commit

Permalink
Add behave tests for multilingual embedded planning
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLark86 committed Dec 28, 2023
1 parent eaa4568 commit 8182230
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 16 deletions.
216 changes: 213 additions & 3 deletions server/features/event_embedded_planning.feature
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Feature: Event Embedded Planning
@auth
Scenario: Create and update associated Planning with an Event
Scenario: Can create and update associated Planning with an Event
# Test creating and Event with a Planning item/Coveage
When we post to "/events"
"""
[{
"guid": "event1",
"name": "Event1",
"dates": {
"start": "2029-11-21T12:00:00.000Z",
"end": "2029-11-21T14:00:00.000Z",
"start": "2029-11-21T12:00:00+0000",
"end": "2029-11-21T14:00:00+0000",
"tz": "Australia/Sydney"
},
"embedded_planning": [{
Expand Down Expand Up @@ -153,3 +153,213 @@ Feature: Event Embedded Planning
}
}]}
"""

@auth
Scenario: Can create multilingual Planning with multilingual Event
Given "vocabularies"
"""
[{
"_id": "languages", "display_name": "Languages", "type": "manageable",
"unique_field": "qcode", "service": {"all": 1},
"items": [
{"qcode": "en", "name": "English", "is_active": true},
{"qcode": "nl", "name": "Dutch", "is_active": true}
]
}]
"""
And "planning_types"
"""
[{
"_id": "event",
"name": "event",
"editor": {
"language": {"enabled": true},
"name": {"enabled": true},
"slugline": {"enabled": true},
"definition_short": {"enabled": true},
"internal_note": {"enabled": true},
"ednote": {"enabled": true},
"priority": {"enabled": true},
"place": {"enabled": true},
"subject": {"enabled": true},
"anpa_category": {"enabled": true}
},
"schema": {
"language": {
"languages": ["en", "nl"],
"default_language": "en",
"multilingual": true,
"required": true
},
"name": {"multilingual": true},
"slugline": {"multilingual": true},
"definition_short": {"multilingual": true},
"ednote": {"multilingual": true},
"internal_note": {"multilingual": true}
}
}, {
"_id": "planing",
"name": "planning",
"editor": {
"language": {"enabled": true},
"name": {"enabled": true},
"slugline": {"enabled": true},
"description_text": {"enabled": true},
"internal_note": {"enabled": true},
"ednote": {"enabled": true},
"priority": {"enabled": true},
"place": {"enabled": true},
"subject": {"enabled": true},
"anpa_category": {"enabled": true}
},
"schema": {
"language": {
"languages": ["en", "nl"],
"default_language": "en",
"multilingual": true,
"required": true
},
"name": {"multilingual": true},
"slugline": {"multilingual": true},
"description_text": {"multilingual": true},
"ednote": {"multilingual": true},
"internal_note": {"multilingual": true}
}
}, {
"_id": "coverage",
"name": "coverage",
"editor": {
"g2_content_type": {"enabled": true},
"slugline": {"enabled": true},
"ednote": {"enabled": true},
"internal_note": {"enabled": true},
"language": {"enabled": true},
"priority": {"enabled": true},
"genre": {"enabled": true}
}
}]
"""
When we post to "/events"
"""
[{
"guid": "event1",
"name": "name1",
"dates": {
"start": "2029-11-21T12:00:00+0000",
"end": "2029-11-21T14:00:00+0000",
"tz": "Australia/Sydney"
},
"slugline": "slugline1",
"definition_short": "The description",
"internal_note": "event internal note",
"ednote": "event editorial note",
"language": "en",
"languages": ["en", "nl"],
"priority": 2,
"place": [{
"name": "NSW",
"qcode": "NSW",
"state": "New South Wales",
"country": "Australia",
"world_region": "Oceania",
"group": "Australia"
}],
"subject":[{"qcode": "17004000", "name": "Statistics"}],
"anpa_category": [{"name": "Overseas Sport", "qcode": "s"}],
"translations": [
{"field": "name", "language": "en", "value": "name-en"},
{"field": "name", "language": "nl", "value": "name-nl"},
{"field": "slugline", "language": "en", "value": "slugline-en"},
{"field": "slugline", "language": "nl", "value": "slugline-nl"},
{"field": "definition_short", "language": "en", "value": "description en"},
{"field": "definition_short", "language": "nl", "value": "description nl"},
{"field": "ednote", "language": "en", "value": "ednote en"},
{"field": "ednote", "language": "nl", "value": "ednote nl"},
{"field": "internal_note", "language": "en", "value": "internal note en"},
{"field": "internal_note", "language": "nl", "value": "internal note nl"}
],
"embedded_planning": [{
"coverages": [{
"g2_content_type": "text",
"language": "en",
"news_coverage_status": "ncostat:int",
"scheduled": "2029-11-21T15:00:00+0000",
"genre": "Article"
}, {
"g2_content_type": "text",
"language": "nl",
"news_coverage_status": "ncostat:onreq",
"scheduled": "2029-11-21T16:00:00+0000",
"genre": "Sidebar"
}]
}]
}]
"""
Then we get OK response
When we get "/events_planning_search?repo=planning&only_future=false&event_item=event1"
Then we get list with 1 items
"""
{"_items": [{
"_id": "__any_value__",
"slugline": "slugline1",
"internal_note": "event internal note",
"name": "name1",
"description_text": "The description",
"place": [{
"name": "NSW",
"qcode": "NSW",
"state": "New South Wales",
"country": "Australia",
"world_region": "Oceania",
"group": "Australia"
}],
"subject":[{"qcode": "17004000", "name": "Statistics"}],
"ednote": "event editorial note",
"language": "en",
"languages": ["en", "nl"],
"priority": 2,
"translations": [
{"field": "name", "language": "en", "value": "name-en"},
{"field": "name", "language": "nl", "value": "name-nl"},
{"field": "slugline", "language": "en", "value": "slugline-en"},
{"field": "slugline", "language": "nl", "value": "slugline-nl"},
{"field": "description_text", "language": "en", "value": "description en"},
{"field": "description_text", "language": "nl", "value": "description nl"},
{"field": "ednote", "language": "en", "value": "ednote en"},
{"field": "ednote", "language": "nl", "value": "ednote nl"},
{"field": "internal_note", "language": "en", "value": "internal note en"},
{"field": "internal_note", "language": "nl", "value": "internal note nl"}
],
"coverages": [{
"coverage_id": "__any_value__",
"workflow_status": "draft",
"news_coverage_status": {"qcode": "ncostat:int"},
"planning": {
"g2_content_type": "text",
"language": "en",
"scheduled": "2029-11-21T15:00:00+0000",
"description_text": "description en",
"ednote": "ednote en",
"internal_note": "internal note en",
"slugline": "slugline-en",
"priority": 2,
"genre": [{"qcode": "Article"}]
}
}, {
"coverage_id": "__any_value__",
"workflow_status": "draft",
"news_coverage_status": {"qcode": "ncostat:onreq"},
"planning": {
"g2_content_type": "text",
"language": "nl",
"scheduled": "2029-11-21T16:00:00+0000",
"description_text": "description nl",
"ednote": "ednote nl",
"internal_note": "internal note nl",
"slugline": "slugline-nl",
"priority": 2,
"genre": [{"qcode": "Sidebar"}]
}
}]
}]}
"""
3 changes: 3 additions & 0 deletions server/features/event_sync_to_planning.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Feature: Sync Event metadata To Planning
@auth
Scenario: Sync Event metadata to Planning
2 changes: 1 addition & 1 deletion server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
def get_events_embedded_planning(event: Event) -> List[EmbeddedPlanning]:
def get_coverage_id(coverage: EmbeddedCoverageItem) -> str:
if not coverage.get("coverage_id"):
coverage["coverage_id"] = TEMP_ID_PREFIX + "-coverage"
coverage["coverage_id"] = TEMP_ID_PREFIX + "-" + generate_guid(type=GUID_NEWSML)
return coverage["coverage_id"]

return [
Expand Down
36 changes: 24 additions & 12 deletions server/planning/events/events_sync/embedded_planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from superdesk import get_resource_service

from planning.types import Event, EmbeddedPlanning, EmbeddedCoverageItem, Planning, Coverage
from planning.types import Event, EmbeddedPlanning, EmbeddedCoverageItem, Planning, Coverage, StringFieldTranslation
from planning.content_profiles.utils import AllContentProfileData

from .common import VocabsSyncData
Expand Down Expand Up @@ -45,18 +45,28 @@ def create_new_plannings_from_embedded_planning(
if field in profiles.planning.enabled_fields
)
multilingual_enabled = profiles.events.is_multilingual and profiles.planning.is_multilingual
translations = []
if multilingual_enabled and "language" in planning_fields:
translations: List[StringFieldTranslation] = []
event_translations: List[StringFieldTranslation] = event.get("translations") or []
if multilingual_enabled and "language" in planning_fields and len(event_translations):
planning_fields.add("languages")

def map_event_to_planning_translation(translation: StringFieldTranslation):
if translation["field"] == "definition_short":
translation["field"] = "description_text"
return translation

translations = [
translation
for translation in event.get("translations", [])
map_event_to_planning_translation(translation)
for translation in event_translations
if (
(
translation.get("field") == "definition_short"
and "description_text" in profiles.planning.enabled_fields
translation.get("field") is not None
and (
(
translation["field"] == "definition_short"
and "description_text" in profiles.planning.enabled_fields
)
or translation["field"] in profiles.planning.enabled_fields
)
or translation.get("field") in profiles.planning.enabled_fields
)
]

Expand Down Expand Up @@ -144,8 +154,8 @@ def create_new_coverage_from_event_and_planning(
for field in coverage_planning_fields:
new_coverage["planning"][field] = coverage.get(field) or planning.get(field) or event.get(field) # type: ignore

if "genre" in coverage_planning_fields:
new_coverage["planning"]["genre"] = vocabs.genres[coverage["genre"]] if coverage.get("genre") else None
if "genre" in profiles.coverages.enabled_fields and coverage.get("genre") is not None:
new_coverage["planning"]["genre"] = [vocabs.genres.get(coverage["genre"]) or {"qcode": coverage["genre"]}]

if "language" in profiles.coverages.enabled_fields:
# If ``language`` is enabled for Coverages but not defined in ``embedded_planning``
Expand Down Expand Up @@ -248,7 +258,9 @@ def get_existing_plannings_from_embedded_planning(
"genre" in profiles.coverages.enabled_fields
and coverage_planning.get("genre") != embedded_coverage["genre"]
):
coverage_planning["genre"] = vocabs.genres[embedded_coverage["genre"]]
coverage_planning["genre"] = [
vocabs.genres.get(embedded_coverage["genre"]) or {"qcode": embedded_coverage["genre"]}
]
update_required = True
except KeyError:
pass
Expand Down

0 comments on commit 8182230

Please sign in to comment.