-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDESK-4907] Overload the media topics with AAP specific values
- Loading branch information
1 parent
673ed79
commit e5fccf7
Showing
4 changed files
with
97 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8; -*- | ||
# | ||
# This file is part of Superdesk. | ||
# | ||
# Copyright 2013, 2014 Sourcefabric z.u. and contributors. | ||
# | ||
# For the full copyright and license information, please see the | ||
# AUTHORS and LICENSE files distributed with this source code, or | ||
# at https://www.sourcefabric.org/superdesk/license | ||
|
||
import os | ||
from bson import json_util | ||
|
||
|
||
def load_codes(filename): | ||
with open(filename, 'rb') as f: | ||
codes_bytes = f.read() | ||
codes = json_util.loads(codes_bytes.decode('UTF-8')) | ||
return codes | ||
|
||
|
||
dirname = os.path.dirname(os.path.realpath(__file__)) | ||
data_media_topics = os.path.join(dirname, 'data', 'media_topics.json') | ||
aap_media_topics = load_codes(data_media_topics) | ||
|
||
|
||
def init_app(app): | ||
"""Provides a mechanism to overload the media topics | ||
:param app: | ||
:return: | ||
""" | ||
|
||
# Update the topics with any local versions | ||
for topic in aap_media_topics: | ||
app.mediatopics.media_topic_map[topic.get('qcode')] = topic | ||
|
||
# clear the lookup maps | ||
app.mediatopics.clear_maps() | ||
|
||
# re-generate the lookup maps | ||
mediatopics = [t for (_k, t) in app.mediatopics.media_topic_map.items()] | ||
app.mediatopics.generate_mediatopic_to_subject_map(mediatopics) |
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,52 @@ | ||
|
||
from unittests import TestCase | ||
from aap.io.media_topics_extension import init_app | ||
|
||
|
||
class TopicTest(TestCase): | ||
def test_all_subjects_map_to_a_media_topic(self): | ||
init_app(self.app) | ||
for (k, _v) in sorted(self.app.subjects.subjects.items()): | ||
topic = self.app.mediatopics.get_media_topic(k) | ||
# topics codes starting from 99 are AAP specific | ||
if not k.startswith('99'): | ||
self.assertIsNotNone(topic) | ||
# print(k, v, '\t---->\t',topic, | ||
# self.app.mediatopics.get_media_topic_item(topic).get('prefLabel').get('en-GB')) | ||
else: | ||
self.assertINone(topic) | ||
|
||
def test_get_items(self): | ||
init_app(self.app) | ||
items = self.app.mediatopics.get_items() | ||
for i in items: | ||
subject = self.app.mediatopics.get_subject_code(i.get('qcode')) | ||
self.assertIsNotNone(subject) | ||
# print(i.get('qcode'), i.get('name'), '\t---->\t', subject, self.app.subjects.subjects.get(subject)) | ||
|
||
def test_get_media_topics(self): | ||
init_app(self.app) | ||
items = self.app.mediatopics.get_media_topics() | ||
for i in items.keys(): | ||
subject = self.app.mediatopics.get_subject_code(i) | ||
self.assertIsNotNone(subject) | ||
# print(i, v.get('prefLabel').get('en-GB'), '\t---->\t', subject, self.app.subjects.subjects.get(subject)) | ||
|
||
def test_media_topic_to_subject(self): | ||
init_app(self.app) | ||
subject = self.app.mediatopics.get_subject_code('medtop:20000070') | ||
self.assertEqual(subject, '16004000') | ||
|
||
def test_subject_to_media_topic(self): | ||
# The standard mapping maps hip hop to music | ||
topic = self.app.mediatopics.get_media_topic('01011007') | ||
self.assertEqual(topic, 'medtop:20000018') | ||
init_app(self.app) | ||
# AAP overrides to it to point to hip hop to hip hop | ||
topic = self.app.mediatopics.get_media_topic('01011007') | ||
self.assertEqual(topic, 'medtop:20001184') | ||
|
||
def test_get_media_topic_item(self): | ||
init_app(self.app) | ||
topic = self.app.mediatopics.get_media_topic_item('medtop:20000070') | ||
self.assertEqual(topic['type'], ['http://www.w3.org/2004/02/skos/core#Concept']) |
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