Ejemplo n.º 1
0
    def test_trigger_notified_when_sl_block_is_created_in_a_news(self):
        """When a news is published, the first page is the news, then
        the content of the news follows in separate jobs (sl blocks,
        recursive structures).
        When we only trigger when the news itself is published, the content
        will be missing.
        Therefore we must trigger an update on any change within the news.
        """
        self.grant('Manager')
        trigger_url = self.portal.portal_url() + '/mopage-stub'
        endpoint_url = (self.portal.portal_url() + '/news-folder/mopage.news.xml' +
                        '?partnerid=213&importid=456')

        folder = create(Builder('news folder')
                        .titled(u'News Folder')
                        .having(mopage_enabled=True,
                                mopage_trigger_url=trigger_url,
                                mopage_data_endpoint_url=endpoint_url))

        news = create(Builder('news').titled(u'The News').within(folder))
        block = create(Builder('sl textblock').within(news))

        self.assertEquals([], get_stub_log(self.portal))

        notify(AfterCreatedEvent(block))
        transaction.commit()
        runAsyncTest(lambda: None)
        transaction.begin()
        self.assertEquals(
            [{'url': endpoint_url}],
            get_stub_log(self.portal))
Ejemplo n.º 2
0
    def testTaskId(self):
        self.assertEqual(len(self.task_queue), 0)
        a = taskqueue.add("/", queue=self.queue)
        b = taskqueue.add("/Plone", queue=self.queue)
        transaction.commit()
        self.assertEqual(len(self.task_queue), 2)

        handler = InstalledHandler("collective.taskqueue")
        runAsyncTest(self._testConsumeFromQueue)
        messages = [record.getMessage() for record in handler.records]
        self.assertEqual(messages[-2:], [a, b])
Ejemplo n.º 3
0
    def testConsumeFromQueue(self):
        self.assertEqual(len(self.task_queue), 0)
        taskqueue.add("/", queue=self.queue)
        taskqueue.add("/Plone", queue=self.queue)
        transaction.commit()
        self.assertEqual(len(self.task_queue), 2)

        handler = InstalledHandler("collective.taskqueue")
        runAsyncTest(self._testConsumeFromQueue)
        messages = [record.getMessage() for record in handler.records]
        self.assertEqual(messages[-2:],
                         ["http://nohost:/", "http://nohost:/Plone"])
Ejemplo n.º 4
0
    def testConsume100FromQueue(self):
        self.assertEqual(len(self.task_queue), 0)
        expected_result = []
        for i in range(100):
            taskqueue.add("/{0:02d}".format(i), queue=self.queue)
            expected_result.append("http://nohost:/{0:02d}".format(i))
        transaction.commit()
        self.assertEqual(len(self.task_queue), 100)

        handler = InstalledHandler("collective.taskqueue")
        runAsyncTest(self._testConsumeFromQueue)
        messages = [record.getMessage() for record in handler.records]

        self.assertEqual(sorted(messages[-100:]), expected_result)
    def testConsume100FromQueue(self):
        self.assertEqual(len(self.task_queue), 0)
        expected_result = []
        for i in range(100):
            taskqueue.add("/{0:02d}".format(i), queue=self.queue)
            expected_result.append("http://nohost:/{0:02d}".format(i))
        transaction.commit()
        self.assertEqual(len(self.task_queue), 100)

        handler = InstalledHandler("collective.taskqueue")
        runAsyncTest(self._testConsumeFromQueue)
        messages = [record.getMessage() for record in handler.records]

        self.assertEqual(sorted(messages[-100:]), expected_result)
Ejemplo n.º 6
0
    def test_trigger_notified_when_news_created(self):
        self.grant('Manager')
        trigger_url = self.portal.portal_url() + '/mopage-stub'
        endpoint_url = (self.portal.portal_url() + '/news-folder/mopage.news.xml' +
                        '?partnerid=213&importid=456')

        folder = create(Builder('news folder')
                        .titled(u'News Folder')
                        .having(mopage_enabled=True,
                                mopage_trigger_url=trigger_url,
                                mopage_data_endpoint_url=endpoint_url))

        news = create(Builder('news').titled(u'The News').within(folder))
        self.assertEquals([], get_stub_log(self.portal))

        notify(AfterCreatedEvent(news))
        transaction.commit()
        runAsyncTest(lambda: None)
        transaction.begin()
        self.assertEquals(
            [{'url': endpoint_url}],
            get_stub_log(self.portal))
Ejemplo n.º 7
0
    def test_trigger_notified_when_events_updated(self):
        self.grant('Manager')
        trigger_url = self.portal.portal_url() + '/mopage-stub'
        endpoint_url = (self.portal.portal_url() + '/event-folder/mopage.events.xml' +
                        '?partnerid=999&importid=888')

        folder = create(Builder('event folder')
                        .titled(u'Event Folder')
                        .having(mopage_enabled=True,
                                mopage_trigger_url=trigger_url,
                                mopage_data_endpoint_url=endpoint_url))

        events = create(Builder('event page').titled(u'The Events').within(folder))
        self.assertEquals([], get_stub_log(self.portal))

        notify(AfterUpdatedEvent(events))
        transaction.commit()
        runAsyncTest(lambda: None)
        transaction.begin()
        self.assertEquals(
            [{'url': endpoint_url}],
            get_stub_log(self.portal))