def test_publish_scheduled(self): item = { '_id': 'foo', 'guid': 'foo', 'type': 'text', 'state': CONTENT_STATE.SCHEDULED, 'task': {}, 'profile': self.profiles[1], 'versioncreated': self.now - timedelta(minutes=5), 'headline': 'foo bar', 'body_html': 'foo', SCHEDULE_SETTINGS: { 'time_zone': 'Europe/Brussels', 'utc_publish_schedule': self.now + timedelta(minutes=20), } } with self.assertRaises(StopDuplication): macro.callback(item) published = self.app.data.find_one('published', req=None, original_id=item['_id']) schedule = published[SCHEDULE_SETTINGS]['utc_publish_schedule'] self.assertLessEqual(self.now + timedelta(minutes=45), schedule)
def test_callback(self): item = { '_id': 'foo', 'guid': 'foo', 'type': 'text', 'state': CONTENT_STATE.PUBLISHED, 'task': {}, 'profile': self.profiles[1], 'versioncreated': self.now - timedelta(minutes=5), 'headline': 'foo BELGANIGHT bar (test)', 'body_html': ''.join([ '<p>foo</p>', '<p>Disclaimer:</p>', '<p>bar</p>', ]), } with self.assertRaises(StopDuplication): macro.callback(item) # test metadata self.assertEqual(self.profiles[0], item['profile']) self.assertEqual(2, item['urgency']) self.assertIn( { 'name': 'BELGA/AG', 'qcode': 'BELGA/AG', 'scheme': 'credits', }, item['subject']) # test published published = self.app.data.find_one('published', req=None, original_id=item['_id']) self.assertIsNotNone(published) self.assertEqual(CONTENT_STATE.SCHEDULED, published['state']) # test schedule schedule = published[SCHEDULE_SETTINGS]['utc_publish_schedule'] self.assertGreaterEqual(self.now + timedelta(minutes=31), schedule) self.assertLessEqual(self.now + timedelta(minutes=29), schedule) self.assertEqual('Europe/Brussels', published[SCHEDULE_SETTINGS]['time_zone']) self.assertEqual( utc_to_local('Europe/Brussels', self.now + timedelta(minutes=30)).replace(tzinfo=utc), published['publish_schedule']) # test content self.assertEqual('foo bar', published['headline']) self.assertEqual('<p>foo</p>', published['body_html'])
def test_filtering(self): item = {} with self.assertRaises(StopDuplication): macro.callback(item) self.assertEqual({}, item) item['profile'] = self.profiles[0] with self.assertRaises(StopDuplication): macro.callback(item) self.assertEqual(1, len(item.keys())) item['profile'] = self.profiles[1] item['body_html'] = '<p>foo</p>' * 500 with self.assertRaises(StopDuplication): macro.callback(item) self.assertEqual(2, len(item.keys()))