Example #1
0
    def TestBulletinBuilderFormatter(self):
        article = {
            'source': 'AAP',
            'anpa_category': [{
                'qcode': 'a'
            }],
            'headline': 'This is a test headline',
            'byline': 'joe',
            'slugline': 'slugline',
            'subject': [{
                'qcode': '02011001'
            }],
            'anpa_take_key': 'take_key',
            'unique_id': '1',
            'type': 'preformatted',
            'body_html': 'The story body',
            'word_count': '1',
            'priority': '1',
            'firstcreated': utcnow(),
            'versioncreated': utcnow(),
            'lock_user': ObjectId()
        }

        subscriber = self.app.data.find('subscribers', None, None)[0]
        f = AAPBulletinBuilderFormatter()
        seq, item = f.format(article, subscriber)[0]
        self.assertGreater(int(seq), 0)
        self.assertEqual(
            json.dumps(article, default=json_serialize_datetime_objectId),
            item)
Example #2
0
    def TestLocator(self):
        article = {
            'source': 'AAP',
            'anpa_category': [{
                'qcode': 's'
            }],
            'headline': 'This is a test headline',
            'byline': 'joe',
            'slugline': 'slugline',
            'subject': [{
                'qcode': '15017000'
            }],
            'anpa_take_key': 'take_key',
            'unique_id': '1',
            'type': 'preformatted',
            'body_html': 'The story body',
            'word_count': '1',
            'priority': '1',
            'firstcreated': utcnow(),
            'versioncreated': utcnow(),
            'lock_user': ObjectId(),
            'place': [{
                'qcode': 'VIC',
                'name': 'VIC'
            }]
        }

        subscriber = self.app.data.find('subscribers', None, None)[0]
        f = AAPBulletinBuilderFormatter()
        seq, item = f.format(article, subscriber)[0]
        self.assertGreater(int(seq), 0)
        test_article = json.loads(item)
        self.assertEqual(test_article['headline'], 'This is a test headline')
        self.assertEqual(test_article['place'][0]['qcode'], 'CRIK')
        article['anpa_category'] = [{'qcode': 'a'}]
        article['place'] = [{'qcode': 'VIC', 'name': 'VIC'}]
        seq, item = f.format(article, subscriber)[0]
        self.assertGreater(int(seq), 0)
        test_article = json.loads(item)
        self.assertEqual(test_article['headline'], 'This is a test headline')
        self.assertEqual(test_article['place'][0]['qcode'], 'VIC')
Example #3
0
    def TestStripHtml(self):
        article = {
            'source':
            'AAP',
            'headline':
            'This is a test headline',
            'body_html':
            ('<p>The story body line 1<br>Line 2</p>'
             '<p>abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi'
             '<span> abcdefghi</span> abcdefghi abcdefghi more</p>'
             '<table><tr><td>test</td></tr></table>')
        }

        body_text = ('The story body line 1 Line 2\r\n\r\n'
                     'abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi'
                     ' abcdefghi abcdefghi abcdefghi more\r\n\r\n'
                     'test')

        subscriber = self.app.data.find('subscribers', None, None)[0]
        f = AAPBulletinBuilderFormatter()
        seq, item = f.format(article, subscriber)[0]
        self.assertGreater(int(seq), 0)
        test_article = json.loads(item)
        self.assertEqual(test_article['body_text'], body_text)
Example #4
0
 def setUp(self):
     super().setUp()
     self.app.data.insert('subscribers', self.subscribers)
     init_app(self.app)
     self._formatter = AAPBulletinBuilderFormatter()