Skip to content

Commit

Permalink
Merge pull request #131 from mdhaman/1.2
Browse files Browse the repository at this point in the history
fix(formatters):Fixing the bulletin builder content for features content.
  • Loading branch information
Mayur Dhamanwala authored Sep 15, 2016
2 parents 6de87ce + b8a325e commit f120e5c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ 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']
if len(formatted_article.get('anpa_category') or []) > 1:
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') or []))), None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def test_NZN_content_from_Sports_Desk(self):
test_article = json.loads(item.get('data'))
self.assertEqual(test_article['source'], 'NZN')

def test_multiple_categories(self):
def test_multiple_categories_ignore_features(self):
article = {
'source': 'AAP',
'anpa_category': [{'qcode': 'c'}, {'qcode': 's'}, {'qcode': 'a'}],
Expand Down Expand Up @@ -441,3 +441,36 @@ def test_multiple_categories(self):
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')

def test_single_category_allow_features(self):
article = {
'source': 'AAP',
'anpa_category': [{'qcode': 'c'}],
'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'], 'c')
self.assertEqual(len(test_article['anpa_category']), 1)
self.assertEqual(test_article['anpa_category'][0]['qcode'], 'c')

0 comments on commit f120e5c

Please sign in to comment.