From 4bb5895d45df7e11d43bd0b37f5003359ab50d46 Mon Sep 17 00:00:00 2001 From: Mayur Dhamanwala Date: Tue, 6 Sep 2016 14:05:43 +1000 Subject: [PATCH] Ignore category c for bulletin builder. --- .../aap_bulletinbuilder_formatter.py | 7 +++- .../aap_bulletinbuilder_formatter_tests.py | 34 +++++++++++++++++++ .../field_mappers/locator_mapper.py | 4 ++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/server/aap/publish/formatters/aap_bulletinbuilder_formatter.py b/server/aap/publish/formatters/aap_bulletinbuilder_formatter.py index ef32c468f..5aaf8325a 100644 --- a/server/aap/publish/formatters/aap_bulletinbuilder_formatter.py +++ b/server/aap/publish/formatters/aap_bulletinbuilder_formatter.py @@ -63,8 +63,13 @@ def format(self, article, subscriber, codes=None): formatted_article['byline'] = self.get_text_content( to_ascii(formatted_article.get('byline', '') or '')).strip() + # remove category c from the list + formatted_article['anpa_category'] = [cat for cat in (formatted_article.get('anpa_category') or []) + if cat.get('qcode') != 'c'] + # get the first category and derive the locator - category = next((iter(formatted_article.get('anpa_category', []))), None) + category = next((iter((formatted_article.get('anpa_category') or []))), None) + if category: locator = LocatorMapper().map(formatted_article, category.get('qcode').upper()) if locator: diff --git a/server/aap/publish/formatters/aap_bulletinbuilder_formatter_tests.py b/server/aap/publish/formatters/aap_bulletinbuilder_formatter_tests.py index 0c8407c42..3283b2954 100644 --- a/server/aap/publish/formatters/aap_bulletinbuilder_formatter_tests.py +++ b/server/aap/publish/formatters/aap_bulletinbuilder_formatter_tests.py @@ -407,3 +407,37 @@ def test_NZN_content_from_Sports_Desk(self): self.assertGreater(int(seq), 0) test_article = json.loads(item.get('data')) self.assertEqual(test_article['source'], 'NZN') + + def test_multiple_categories(self): + article = { + 'source': 'AAP', + 'anpa_category': [{'qcode': 'c'}, {'qcode': 's'}, {'qcode': 'a'}], + 'headline': 'This is a test headline', + 'byline': 'joe', + 'slugline': 'slugline', + 'subject': [{'qcode': '15017000'}], + 'anpa_take_key': 'take_key', + 'unique_id': '1', + 'type': 'text', + 'format': 'HTML', + 'body_html': 'The story body', + 'word_count': '1', + 'priority': '1', + 'firstcreated': utcnow(), + 'versioncreated': utcnow(), + 'lock_user': ObjectId(), + 'task': { + 'desk': self.desks[0][config.ID_FIELD] + } + } + + subscriber = self.app.data.find('subscribers', None, None)[0] + seq, item = self._formatter.format(article, subscriber)[0] + item = json.loads(item) + self.assertGreater(int(seq), 0) + test_article = json.loads(item.get('data')) + self.assertEqual(test_article['source'], 'AAP') + self.assertEqual(test_article['first_category']['qcode'], 's') + self.assertEqual(len(test_article['anpa_category']), 2) + self.assertEqual(test_article['anpa_category'][0]['qcode'], 's') + self.assertEqual(test_article['anpa_category'][1]['qcode'], 'a') diff --git a/server/aap/publish/formatters/field_mappers/locator_mapper.py b/server/aap/publish/formatters/field_mappers/locator_mapper.py index 98a7bdb64..50a492a59 100644 --- a/server/aap/publish/formatters/field_mappers/locator_mapper.py +++ b/server/aap/publish/formatters/field_mappers/locator_mapper.py @@ -27,7 +27,9 @@ class LocatorMapper(FieldMapper): '13000000': 'SCI', '13010000': 'TECH', '10006000': 'TRAV', - '01016000': 'TV' + '01016000': 'TV', + '01028000': 'HIST', + '13003002': 'HIST' } iptc_sports_locators = {