
from unittest.mock import patch
from superdesk.tests import TestCase
from apps.publish.enqueue.enqueue_service import EnqueueService


class EnqueueTestCase(TestCase):

    def setUp(self):
        super().setUp()

        self.product_ids = self.app.data.insert('products', [
            {'name': 'all'},
        ])

        self.subscriber_ids = self.app.data.insert('subscribers', [
            {'name': 'digi', 'subscriber_type': 'digital', 'is_targetable': True, 'products': self.product_ids},
        ])

        self.desk_ids = self.app.data.insert('desks', [
            {'name': 'sports'},
        ])

        self.service = EnqueueService()

    def test_resend_no_takes(self):
        self.app.config['NO_TAKES'] = True

        doc = {}
        subscribers = [s for s in self.app.data.find_all('subscribers')]
        subscriber_codes = self.service._get_subscriber_codes(subscribers)
        with patch.object(self.service, '_resend_to_subscribers') as resend:
            self.service.resend(doc, subscribers)
            resend.assert_called_with(doc, subscribers, subscriber_codes)

@@ -135,16 +135,23 @@
 %0A%0Aclass 
+NoTakes
 EnqueueT
@@ -693,52 +693,8 @@
 f):%0A
-        self.app.config%5B'NO_TAKES'%5D = True%0A%0A
     
@@ -931,16 +931,120 @@
 resend:%0A
+            with patch.dict('apps.publish.enqueue.enqueue_service.app.config', %7B'NO_TAKES': True%7D):%0A    
         

reset config after no takes tests