def test_queue_transmission_wrong_article_type_fails(self): self._is_publish_queue_empty() doc = copy(self.articles[0]) doc['item_id'] = doc['_id'] doc[ITEM_TYPE] = CONTENT_TYPE.PICTURE subscribers, subscribers_yet_to_receive, subscriber_codes = \ EnqueuePublishedService().get_subscribers(doc, SUBSCRIBER_TYPES.DIGITAL) no_formatters, queued = EnqueueService().queue_transmission(doc, subscribers, subscriber_codes) queue_items = self.app.data.find(PUBLISH_QUEUE, None, None) self.assertEqual(1, queue_items.count()) self.assertEqual(0, len(no_formatters)) self.assertTrue(queued) subscribers, subscribers_yet_to_receive, subscriber_codes = \ EnqueuePublishedService().get_subscribers(doc, SUBSCRIBER_TYPES.WIRE) no_formatters, queued = EnqueueService().queue_transmission(doc, subscribers) queue_items = self.app.data.find(PUBLISH_QUEUE, None, None) self.assertEqual(2, queue_items.count()) self.assertEqual(0, len(no_formatters)) self.assertTrue(queued)
def test_queue_transmission_for_digital_channels(self): self._is_publish_queue_empty() doc = copy(self.articles[1]) doc['item_id'] = doc['_id'] subscribers, subscribers_yet_to_receive, subscriber_codes = \ EnqueuePublishedService().get_subscribers(doc, SUBSCRIBER_TYPES.DIGITAL) EnqueueService().queue_transmission(doc, subscribers, subscriber_codes) queue_items = self.app.data.find(PUBLISH_QUEUE, None, None) self.assertEqual(1, queue_items.count()) expected_subscribers = ['5'] for item in queue_items: self.assertIn(item["subscriber_id"], expected_subscribers, 'item {}'.format(item))
def test_get_subscribers_without_product(self): doc = copy(self.articles[1]) doc['item_id'] = doc['_id'] subscriber_service = get_resource_service('subscribers') for sub in self.subscribers: sub.pop('products', None) subscriber_service.delete({'_id': sub['_id']}) subscriber_service.post(self.subscribers) subscribers, subscribers_yet_to_receive, subscriber_codes = \ EnqueuePublishedService().get_subscribers(doc, SUBSCRIBER_TYPES.WIRE) self.assertEqual(0, len(subscribers)) self.assertDictEqual({}, subscriber_codes)
def test_queue_transmission_for_wire_channels_with_codes(self): self._is_publish_queue_empty() doc = copy(self.articles[1]) doc['item_id'] = doc['_id'] subscribers, subscribers_yet_to_receive, subscriber_codes = \ EnqueuePublishedService().get_subscribers(doc, SUBSCRIBER_TYPES.WIRE) EnqueueService().queue_transmission(doc, subscribers, subscriber_codes) queue_items = self.app.data.find(PUBLISH_QUEUE, None, None) self.assertEqual(5, queue_items.count()) expected_subscribers = ['1', '2', '4', '5'] for item in queue_items: self.assertIn(item['subscriber_id'], expected_subscribers, 'item {}'.format(item)) if item['subscriber_id'] == '5': self.assertIn('def', item['codes']) self.assertIn('abc', item['codes'])
logger = logging.getLogger(__name__) profile = cProfile.Profile() UPDATE_SCHEDULE_DEFAULT = {'seconds': 10} ITEM_PUBLISH = 'publish' ITEM_CORRECT = 'correct' ITEM_KILL = 'kill' ITEM_TAKEDOWN = 'takedown' ITEM_UNPUBLISH = 'unpublish' enqueue_services = { ITEM_PUBLISH: EnqueuePublishedService(), ITEM_CORRECT: EnqueueCorrectedService(), ITEM_KILL: EnqueueKilledService(), ITEM_TAKEDOWN: EnqueueKilledService(published_state=CONTENT_STATE.RECALLED), ITEM_UNPUBLISH: EnqueueKilledService(published_state=CONTENT_STATE.UNPUBLISHED), } def get_enqueue_service(operation): try: enqueue_services[operation].get_filters() except KeyError:
logger = logging.getLogger(__name__) profile = cProfile.Profile() UPDATE_SCHEDULE_DEFAULT = {'seconds': 10} ITEM_PUBLISH = 'publish' ITEM_CORRECT = 'correct' ITEM_KILL = 'kill' ITEM_TAKEDOWN = 'takedown' ITEM_UNPUBLISH = 'unpublish' enqueue_services = { ITEM_PUBLISH: EnqueuePublishedService(), ITEM_CORRECT: EnqueueCorrectedService(), ITEM_KILL: EnqueueKilledService(), ITEM_TAKEDOWN: EnqueueKilledService(published_state=CONTENT_STATE.RECALLED), ITEM_UNPUBLISH: EnqueueKilledService(published_state=CONTENT_STATE.UNPUBLISHED), } def get_enqueue_service(operation): try: enqueue_services[operation].get_filters() except KeyError: # Hot fix for https://dev.sourcefabric.org/browse/SDESK-3555 # FIXME: this issue needs investigation and a proper fix. logger.error("unexpected operation: {operation}".format(operation=operation)) operation = "correct"