Skip to content

Commit

Permalink
Merge pull request #116 from mdhaman/locator
Browse files Browse the repository at this point in the history
fix(publish):Ignore category c for bulletin builder.
  • Loading branch information
Mayur Dhamanwala authored Sep 7, 2016
2 parents bd8d474 + 4bb5895 commit 5486c86
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class LocatorMapper(FieldMapper):
'13000000': 'SCI',
'13010000': 'TECH',
'10006000': 'TRAV',
'01016000': 'TV'
'01016000': 'TV',
'01028000': 'HIST',
'13003002': 'HIST'
}

iptc_sports_locators = {
Expand Down

0 comments on commit 5486c86

Please sign in to comment.