From affb7e9192862598860fe16399cd80c12d6d3797 Mon Sep 17 00:00:00 2001 From: akintolga Date: Sun, 17 Jul 2016 13:37:06 +1000 Subject: [PATCH] [SD-5013] - Publishing with empty byline fails in odbc --- .../formatters/aap_ipnews_formatter_test.py | 91 +++++++++++++++++++ .../publish/formatters/aap_odbc_formatter.py | 4 +- .../aap/publish/formatters/anpa_formatter.py | 2 +- 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/server/aap/publish/formatters/aap_ipnews_formatter_test.py b/server/aap/publish/formatters/aap_ipnews_formatter_test.py index 32097e3ad..4bb31b3e2 100644 --- a/server/aap/publish/formatters/aap_ipnews_formatter_test.py +++ b/server/aap/publish/formatters/aap_ipnews_formatter_test.py @@ -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": "

One Ruralco export licence lost to BJD

", + "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() diff --git a/server/aap/publish/formatters/aap_odbc_formatter.py b/server/aap/publish/formatters/aap_odbc_formatter.py index ffdf87c1b..2fdda7a3e 100644 --- a/server/aap/publish/formatters/aap_odbc_formatter.py +++ b/server/aap/publish/formatters/aap_odbc_formatter.py @@ -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: diff --git a/server/aap/publish/formatters/anpa_formatter.py b/server/aap/publish/formatters/anpa_formatter.py index a359e4635..7d3e47d12 100644 --- a/server/aap/publish/formatters/anpa_formatter.py +++ b/server/aap/publish/formatters/anpa_formatter.py @@ -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')