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')
    def test_strip_html_case2(self):
        article = {
            config.ID_FIELD:
            '123',
            config.VERSION:
            2,
            'source':
            'AAP',
            'headline':
            'This is a test headline',
            'type':
            'text',
            'body_html':
            ('<p>This is third<br> take.</p><br><p>Correction in the third take.</p><br>'
             '<p>This is test.</p><br><p><br></p>')
        }

        body_text = ('This is third take.\r\n\r\n'
                     'Correction in the third take.\r\n\r\n'
                     'This is test.\r\n\r\n')

        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['body_text'], body_text)
    def test_strip_html(self):
        article = {
            config.ID_FIELD:
            '123',
            config.VERSION:
            2,
            'source':
            'AAP',
            'headline':
            'This is a test headline',
            'type':
            'text',
            '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]
        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['body_text'], body_text)
    def test_body_footer(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(),
            'body_footer':
            'call helpline 999 if you are planning to quit smoking'
        }

        subscriber = self.app.data.find('subscribers', None, None)[0]
        seq, item = self._formatter.format(article, subscriber)[0]
        item = json.loads(item)

        formatted_article = json.loads(item.get('data'))
        self.assertEqual(
            formatted_article['body_text'],
            'The story body\r\ncall helpline 999 if you are planning to quit smoking'
        )
    def test_body_footer(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(),
            'body_footer': 'call helpline 999 if you are planning to quit smoking'
        }

        subscriber = self.app.data.find('subscribers', None, None)[0]
        seq, item = self._formatter.format(article, subscriber)[0]
        item = json.loads(item)

        formatted_article = json.loads(item.get('data'))
        self.assertEqual(formatted_article['body_text'],
                         'The story body\r\ncall helpline 999 if you are planning to quit smoking')
    def test_bulletin_builder_formatter(self):
        article = {
            config.ID_FIELD: '123',
            config.VERSION: 2,
            '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]
        seq, item = self._formatter.format(article, subscriber)[0]
        item = json.loads(item)
        self.assertGreater(int(seq), 0)
        self.assertEqual(article[config.ID_FIELD], item.get('id'))
        self.assertEqual(article[config.VERSION], item.get('version'))
        self.assertEqual(article[ITEM_TYPE], item.get(ITEM_TYPE))
        self.assertEqual(article.get(PACKAGE_TYPE, ''), item.get(PACKAGE_TYPE))
        self.assertEqual(article['headline'], item.get('headline'))
        self.assertEqual(article['slugline'], item.get('slugline'))
        self.assertEqual(json.dumps(article, default=json_serialize_datetime_objectId),
                         item.get('data'))
    def test_locator(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]
        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['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 = 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['headline'], 'This is a test headline')
        self.assertEqual(test_article['place'][0]['qcode'], 'VIC')
    def test_strip_html_case2(self):
        article = {
            config.ID_FIELD: '123',
            config.VERSION: 2,
            'source': 'AAP',
            'headline': 'This is a test headline',
            'type': 'text',
            'body_html': ('<p>This is third<br> take.</p><br><p>Correction in the third take.</p><br>'
                          '<p>This is test.</p><br><p><br></p>')
        }

        body_text = ('This is third take.\r\n\r\n'
                     'Correction in the third take.\r\n\r\n'
                     'This is test.\r\n\r\n')

        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['body_text'], body_text)
    def test_strip_html_case1(self):
        article = {
            config.ID_FIELD: '123',
            config.VERSION: 2,
            'source': 'AAP',
            'headline': 'This is a test headline',
            'type': 'text',
            '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]
        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['body_text'], body_text)
    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)
    def test_bulletin_builder_formatter(self):
        article = {
            config.ID_FIELD: '123',
            config.VERSION: 2,
            '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]
        seq, item = self._formatter.format(article, subscriber)[0]
        item = json.loads(item)
        self.assertGreater(int(seq), 0)
        self.assertEqual(article[config.ID_FIELD], item.get('id'))
        self.assertEqual(article[config.VERSION], item.get('version'))
        self.assertEqual(article[ITEM_TYPE], item.get(ITEM_TYPE))
        self.assertEqual(article.get(PACKAGE_TYPE, ''), item.get(PACKAGE_TYPE))
        self.assertEqual(article['headline'], item.get('headline'))
        self.assertEqual(article['slugline'], item.get('slugline'))
        self.assertEqual(
            json.dumps(article, default=json_serialize_datetime_objectId),
            item.get('data'))
    def get(self, req, lookup):
        """
        Overriding to pass user as search parameter
        """
        session_user = str(get_user_id(required=True))

        if not req:
            req = ParsedRequest()

        where = json.loads(req.where) if req.where else {}

        if lookup:
            where.update(lookup)

        if '$or' not in where:
            where['$or'] = []

        # Restrict the saved reports to either global or owned by current user
        where['$or'].extend([{'is_global': True}, {'user': session_user}])

        req.where = json.dumps(where)

        return super().get(req, lookup=None)
示例#13
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)