Skip to content

Commit

Permalink
[SD-4066] AP categories, map the category to 'i' only if it is not in…
Browse files Browse the repository at this point in the history
… the active vocabulary
  • Loading branch information
marwoodandrew authored and petrjasek committed Sep 29, 2016
1 parent 6fe05bd commit fc72f61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion superdesk/io/feed_parsers/ap_anpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from apps.archive.common import format_dateline_to_locmmmddsrc
from superdesk.utc import get_date
from bs4 import BeautifulSoup
from superdesk import get_resource_service
import logging

logger = logging.getLogger("AP_ANPAFeedParser")
Expand Down Expand Up @@ -79,7 +80,14 @@ def map_category_codes(self, item):
elif category.get('qcode').lower() == 'z':
category['qcode'] = 's'
else:
category['qcode'] = 'i'
# check if the category is defined in the system
category_map = get_resource_service('vocabularies').find_one(req=None, _id='categories')
if category_map:
if not next((code for code in category_map['items'] if
code['qcode'].lower() == category['qcode'].lower() and code['is_active']), None):
category['qcode'] = 'i'
else:
category['qcode'] = 'i'

def map_sluglines_to_subjects(self, item):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/io/feed_parsers/ap_anpa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ANPATestCase(TestCase):

parser = AP_ANPAFeedParser()

def setUp(self):
with self.app.app_context():
vocab = [{'_id': 'categories', 'items': [{'is_active': True, 'name': 'Domestic Sport', 'qcode': 's'}]}]
self.app.data.insert('vocabularies', vocab)

def open(self, filename):
provider = {'name': 'Test'}
return self.parser.parse(fixture(filename), provider)
Expand Down

0 comments on commit fc72f61

Please sign in to comment.