Пример #1
0
 def test_process_headline_empty_sequence_short_headline(self):
     f = AAPAnpaFormatter()
     article = {'headline': '1234567890' * 5}
     anpa = []
     f._process_headline(anpa, article, 'a')
     self.assertEqual(
         anpa[0], b'12345678901234567890123456789012345678901234567890')
    def testANPAWithBylineFormatter(self):
        subscriber = self.app.data.find('subscribers', None, None)[0]
        subscriber['name'] = 'not notes'
        byline_article = dict(self.article)
        byline_article['byline'] = 'Joe Blogs'

        f = AAPAnpaFormatter()
        seq, item = f.format(byline_article, subscriber)[0]

        self.assertGreater(int(seq), 0)

        lines = io.StringIO(item.decode())

        line = lines.readline()
        self.assertEqual(line[:3], '')  # Skip the sequence

        line = lines.readline()
        self.assertEqual(line[0:20], 'f a bc-slugline   ')  # skip the date

        line = lines.readline()
        self.assertEqual(line.strip(), 'This is a test headline')

        line = lines.readline()
        self.assertEqual(line.strip(), 'slugline take_key')

        line = lines.readline()
        self.assertEqual(line.strip(), 'Joe Blogs')

        line = lines.readline()
        self.assertEqual(line.strip(), 'The story body')

        line = lines.readline()
        self.assertEqual(line.strip(), 'AAP')
Пример #3
0
    def testANPAFormatter(self):
        subscriber = self.app.data.find('subscribers', None, None)[0]

        f = AAPAnpaFormatter()
        seq, item = f.format(self.article.copy(), subscriber)[0]

        self.assertGreater(int(seq), 0)

        lines = io.StringIO(item.decode())

        line = lines.readline()
        self.assertTrue('axx' in line[1:])

        line = lines.readline()
        self.assertEqual(line[:3], '')  # Skip the sequence

        line = lines.readline()
        self.assertEqual(line[0:20], 'f a bc-slugline   ')  # skip the date

        line = lines.readline()
        self.assertEqual(line.strip(), 'This is a test headline')

        line = lines.readline()
        self.assertEqual(line.strip(), 'slugline take_key')

        line = lines.readline()
        self.assertEqual(
            line.strip(),
            'The story bodycall helpline 999 if you are planning to quit smoking'
        )

        line = lines.readline()
        self.assertEqual(line.strip(), 'AAP')
    def testANPAWithNoSelectorsFormatter(self):
        subscriber = self.app.data.find("subscribers", None, None)[0]
        subscriber["name"] = "not notes"

        f = AAPAnpaFormatter()
        seq, item = f.format(self.article.copy(), subscriber)[0]

        self.assertGreater(int(seq), 0)

        lines = io.StringIO(item.decode())

        line = lines.readline()
        self.assertEqual(line[:3], "")  # Skip the sequence

        line = lines.readline()
        self.assertEqual(line[0:20], "f a bc-slugline   ")  # skip the date

        line = lines.readline()
        self.assertEqual(line.strip(), "This is a test headline")

        line = lines.readline()
        self.assertEqual(line.strip(), "slugline take_key")

        line = lines.readline()
        self.assertEqual(line.strip(), "The story bodycall helpline 999 if you are planning to quit smoking")

        line = lines.readline()
        self.assertEqual(line.strip(), "AAP")
Пример #5
0
    def testANPAWithNoSelectorsFormatter(self):
        subscriber = self.app.data.find('subscribers', None, None)[0]
        subscriber['name'] = 'not notes'

        f = AAPAnpaFormatter()
        seq, item = f.format(self.article, subscriber)[0]

        self.assertGreater(int(seq), 0)

        lines = io.StringIO(item.decode())

        line = lines.readline()
        self.assertEqual(line[:3], '')  # Skip the sequence

        line = lines.readline()
        self.assertEqual(line[0:20], 'f a bc-slugline   ')  # skip the date

        line = lines.readline()
        self.assertEqual(line.strip(), 'This is a test headline')

        line = lines.readline()
        self.assertEqual(line.strip(), 'slugline take_key')

        line = lines.readline()
        self.assertEqual(line.strip(), 'The story body')

        line = lines.readline()
        self.assertEqual(line.strip(), 'AAP')
 def test_process_headline_with_sequence_long_headline(self):
     f = AAPAnpaFormatter()
     article1 = {"headline": "1234567890" * 7 + "=7", "sequence": 7}
     anpa = []
     f._process_headline(anpa, article1, "a")
     self.assertEqual(anpa[0], b"12345678901234567890123456789012345678901234567890123456789012=7")
     article2 = {"headline": "1234567890" * 7 + "=7", "sequence": 17}
     anpa = []
     f._process_headline(anpa, article2, "a")
     self.assertEqual(anpa[0], b"1234567890123456789012345678901234567890123456789012345678901=17")
Пример #7
0
 def test_process_headline_with_sequence_long_headline(self):
     f = AAPAnpaFormatter()
     article1 = {'headline': '1234567890' * 7 + '=7', 'sequence': 7}
     anpa = []
     f._process_headline(anpa, article1, 'a')
     self.assertEqual(anpa[0], b'12345678901234567890123456789012345678901234567890123456789012=7')
     article2 = {'headline': '1234567890' * 7 + '=7', 'sequence': 17}
     anpa = []
     f._process_headline(anpa, article2, 'a')
     self.assertEqual(anpa[0], b'1234567890123456789012345678901234567890123456789012345678901=17')
Пример #8
0
 def test_process_headline_locator_inject(self):
     f = AAPAnpaFormatter()
     article3 = {
         'headline': '1234567890' * 3,
         'place': [{
             'qcode': 'VIC',
             'name': 'VIC'
         }]
     }
     anpa = []
     f._process_headline(anpa, article3, 'a')
     self.assertEqual(anpa[0], b'VIC:123456789012345678901234567890')
 def testMultipleCategoryFormatter(self):
     subscriber = self.app.data.find("subscribers", None, None)[0]
     multi_article = dict(self.article.copy())
     multi_article.pop("anpa_category")
     multi_article["anpa_category"] = [{"qcode": "a"}, {"qcode": "b"}]
     f = AAPAnpaFormatter()
     docs = f.format(multi_article, subscriber)
     self.assertEqual(len(docs), 2)
     cat = "a"
     for seq, doc in docs:
         lines = io.StringIO(doc.decode())
         line = lines.readline()
         line = lines.readline()
         line = lines.readline()
         self.assertEqual(line[2:3], cat)  # skip the date
         cat = "b"
Пример #10
0
 def testMultipleCategoryFormatter(self):
     subscriber = self.app.data.find('subscribers', None, None)[0]
     multi_article = dict(self.article.copy())
     multi_article.pop('anpa_category')
     multi_article['anpa_category'] = [{'qcode': 'a'}, {'qcode': 'b'}]
     f = AAPAnpaFormatter()
     docs = f.format(multi_article, subscriber)
     self.assertEqual(len(docs), 2)
     cat = 'a'
     for seq, doc in docs:
         lines = io.StringIO(doc.decode())
         line = lines.readline()
         line = lines.readline()
         line = lines.readline()
         self.assertEqual(line[2:3], cat)  # skip the date
         cat = 'b'
Пример #11
0
 def testMultipleCategoryFormatter(self):
     subscriber = self.app.data.find('subscribers', None, None)[0]
     multi_article = dict(self.article)
     multi_article.pop('anpa_category')
     multi_article['anpa_category'] = [{'qcode': 'a'}, {'qcode': 'b'}]
     f = AAPAnpaFormatter()
     docs = f.format(multi_article, subscriber)
     self.assertEqual(len(docs), 2)
     cat = 'a'
     for seq, doc in docs:
         lines = io.StringIO(doc.decode())
         line = lines.readline()
         line = lines.readline()
         line = lines.readline()
         self.assertEqual(line[2:3], cat)  # skip the date
         cat = 'b'
Пример #12
0
    def TestANPAFormatter(self):
        with self.app.app_context():
            output_channel = self.app.data.find('output_channels', None, None)[0]
            f = AAPAnpaFormatter()
            seq, item = f.format(self.article, output_channel, self.sel_codes)
            self.assertGreater(int(seq), 0)

            lines = io.StringIO(item.decode())
            line = lines.readline()
            self.assertEqual(line.strip(), 'aaa bbb')
            line = lines.readline()
            self.assertEqual(line[:3], '')  # Skip the sequence
            line = lines.readline()
            self.assertEqual(line[0:20], '1 a bc-slugline   ')  # skip the date
            line = lines.readline()
            self.assertEqual(line.strip(), 'This is a test headline')
            line = lines.readline()
            self.assertEqual(line.strip(), 'slugline take_key')
            line = lines.readline()
            self.assertEqual(line.strip(), 'The story body')
            line = lines.readline()
            self.assertEqual(line.strip(), 'AAP')
Пример #13
0
 def test_process_headline_with_sequence_long_headline(self):
     f = AAPAnpaFormatter()
     article1 = {'headline': '1234567890' * 7 + '=7', 'sequence': 7}
     anpa = []
     f._process_headline(anpa, article1, 'a')
     self.assertEqual(
         anpa[0],
         b'12345678901234567890123456789012345678901234567890123456789012=7'
     )
     article2 = {'headline': '1234567890' * 7 + '=7', 'sequence': 17}
     anpa = []
     f._process_headline(anpa, article2, 'a')
     self.assertEqual(
         anpa[0],
         b'1234567890123456789012345678901234567890123456789012345678901=17'
     )
Пример #14
0
 def test_process_headline_locator_inject(self):
     f = AAPAnpaFormatter()
     article3 = {'headline': '1234567890' * 3, 'place': [{'qcode': 'VIC', 'name': 'VIC'}]}
     anpa = []
     f._process_headline(anpa, article3, 'a')
     self.assertEqual(anpa[0], b'VIC:123456789012345678901234567890')
 def test_dateline_with_empty_text(self):
     f = AAPAnpaFormatter()
     subscriber = self.app.data.find('subscribers', None, None)[0]
     item = self.article.copy()
     item.update({'dateline': {'text': None}})
     seq, out = f.format(item, subscriber)[0]
Пример #16
0
 def test_process_headline_with_sequence_short_headline(self):
     f = AAPAnpaFormatter()
     article = {'headline': '1234567890=7', 'sequence': 7}
     anpa = []
     f._process_headline(anpa, article, 'a')
     self.assertEqual(anpa[0], b'1234567890=7')
Пример #17
0
 def test_process_headline_empty_sequence_long_headline(self):
     f = AAPAnpaFormatter()
     article = {'headline': '1234567890' * 7}
     anpa = []
     f._process_headline(anpa, article, 'a')
     self.assertEqual(anpa[0], b'1234567890123456789012345678901234567890123456789012345678901234')
 def test_process_headline_empty_sequence_long_headline(self):
     f = AAPAnpaFormatter()
     article = {"headline": "1234567890" * 7}
     anpa = []
     f._process_headline(anpa, article, "a")
     self.assertEqual(anpa[0], b"1234567890123456789012345678901234567890123456789012345678901234")
 def test_process_headline_with_sequence_short_headline(self):
     f = AAPAnpaFormatter()
     article = {"headline": "1234567890=7", "sequence": 7}
     anpa = []
     f._process_headline(anpa, article, "a")
     self.assertEqual(anpa[0], b"1234567890=7")
 def test_process_headline_locator_inject(self):
     f = AAPAnpaFormatter()
     article3 = {"headline": "1234567890" * 3, "place": [{"qcode": "VIC", "name": "VIC"}]}
     anpa = []
     f._process_headline(anpa, article3, "a")
     self.assertEqual(anpa[0], b"VIC:123456789012345678901234567890")
 def test_dateline_with_empty_text(self):
     f = AAPAnpaFormatter()
     subscriber = self.app.data.find("subscribers", None, None)[0]
     item = self.article.copy()
     item.update({"dateline": {"text": None}})
     seq, out = f.format(item, subscriber)[0]