Skip to content

Commit

Permalink
Merge pull request #52 from akintolga/master
Browse files Browse the repository at this point in the history
[SD-5013] - Publishing with empty/None byline fails in odbc
  • Loading branch information
akintolga authored Jul 17, 2016
2 parents 5fed69c + affb7e9 commit cf7b8b3
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
91 changes: 91 additions & 0 deletions server/aap/publish/formatters/aap_ipnews_formatter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,97 @@ def testIpNewsFormatterNoSubject(self):
self.assertEqual(doc['subject_reference'], '00000000')
self.assertEqual(doc['headline'], 'This is a test headline')

def testIpNewsFormatterNoByline(self):
article = {
"_id": "urn:newsml:localhost:2016-07-15T12:48:23.630571:fcdf4e61-541c-4cc7-86c7-8e15314b5e71",
"headline": "Finance Highlights",
"source": "AAP",
"unique_id": 1,
"type": "text",
"slugline": "Highlights Finance",
"place": [
{
"qcode": "FED",
"country": "Australia",
"world_region": "Oceania",
"group": "Australia",
"state": "",
"name": "FED"
}
],
"format": "HTML",
"priority": 6,
"sign_off": "SC/TDW/DC/SC",
"pubstatus": "usable",
"byline": None,
"more_coming": False,
"body_html": "<h2>One Ruralco export licence lost to BJD</h2>",
"original_creator": "576b60baa5398f65d12ad0c8",
"urgency": 3,
"schedule_settings": {
"utc_embargo": None,
"time_zone": None,
"utc_publish_schedule": None
},
"genre": [
{
"qcode": "Article",
"name": "Article (news)"
}
],
"dateline": {
"date": "2016-07-15T02:48:23.000+0000",
"source": "AAP",
"located": {
"state_code": "NSW",
"country_code": "AU",
"city": "Sydney",
"alt_name": "",
"country": "Australia",
"tz": "Australia/Sydney",
"city_code": "Sydney",
"dateline": "city",
"state": "New South Wales"
},
"text": "SYDNEY, July 15 AAP -"
},
"unique_name": "#9555064",
"version": 2,
"anpa_category": [
{
"qcode": "f",
"subject": "04000000",
"name": "Finance",
"scheme": None
}
],
"linked_in_packages": [
{
"package": "urn:newsml:localhost:2016-07-15T13:04:34.991699:fd7aad03-87a8-4cd5-9fdb-2624f3e02666"
},
{
"package_type": "takes",
"package": "urn:newsml:localhost:2016-07-15T13:59:19.157701:7c7bd386-25ea-42d7-9543-4eff5bceef40"
}
],
"publish_schedule": None,
"subject": [
{
"qcode": "04000000",
"scheme": None,
"name": "economy, business and finance",
"parent": None
}
],
"rewritten_by": None
}
subscriber = self.app.data.find('subscribers', None, None)[0]

f = AAPIpNewsFormatter()
seq, doc = f.format(article, subscriber)[0]
doc = json.loads(doc)
self.assertEqual(doc['headline'], 'FED:Finance Highlights')

def test_aap_ipnews_formatter_with_body_footer(self):
subscriber = self.app.data.find('subscribers', None, None)[0]
doc = self.article.copy()
Expand Down
4 changes: 2 additions & 2 deletions server/aap/publish/formatters/aap_odbc_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def get_odbc_item(self, article, subscriber, category, codes):
odbc_item = dict(originator=article.get('source', None), sequence=pub_seq_num,
category=category.get('qcode'),
headline=to_ascii(article.get('headline', '')).replace('\'', '\'\'').replace('\xA0', ' '),
author=article.get('byline', '').replace('\'', '\'\''),
author=(article.get('byline', '') or '').replace('\'', '\'\''),
keyword=self.append_legal(article=article, truncate=True).replace('\'', '\'\''),
subject_reference=set_subject(category, article),
take_key=article.get('anpa_take_key', '').replace('\'', '\'\''))
take_key=(article.get('anpa_take_key', '') or '').replace('\'', '\'\''))
if 'genre' in article and len(article['genre']) >= 1:
odbc_item['genre'] = article['genre'][0].get('name', None)
else:
Expand Down
2 changes: 1 addition & 1 deletion server/aap/publish/formatters/anpa_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def format(self, article, subscriber, codes=None):

keyword = self.append_legal(article=formatted_article, truncate=True).encode('ascii', 'ignore')
anpa.append(keyword)
take_key = formatted_article.get('anpa_take_key', '').encode('ascii', 'ignore')
take_key = (formatted_article.get('anpa_take_key', '') or '').encode('ascii', 'ignore')
anpa.append((b'\x20' + take_key) if len(take_key) > 0 else b'')
anpa.append(b'\x0D\x0A')

Expand Down

0 comments on commit cf7b8b3

Please sign in to comment.