Пример #1
0
    def test_publish(self):
        test_utils.register_fake_publisher()
        utility = component.queryUtility(ISocialPublisherUtility,
                                         name=test_utils.FakePublisher.id)
        # let's create an event
        event = self.create_event()
        # and get its manager
        manager = IPublishStorageManager(event)
        # we must have empty values here
        self.assertEqual(manager.get_accounts(), {})
        self.assertEqual(manager.get_text(), '')

        # we can now publish it using `social-publish` view
        view = event.restrictedTraverse('@@social-publish')
        publishers = [test_utils.FakePublisher.id]
        accounts = {test_utils.FakePublisher.id: 'simahawk'}
        result = view.publish(publishers=publishers, accounts=accounts)
        # we expect the content of the publication to be equal `get_text` result
        # and the publisher/account mapping matching the one we pass to the publisher
        expected = {
            'content': 'Great event http://nohost/plone/event',
            'fakepub': 'simahawk'
        }
        self.assertEqual(result, expected)
        # publisher/account mapping is saved by default by the publishing view
        self.assertEqual(manager.get_accounts(), {'fakepub': 'simahawk'})
    def test_publish(self):
        test_utils.register_fake_publisher()
        utility = component.queryUtility(ISocialPublisherUtility,
                                         name=test_utils.FakePublisher.id)
        # let's create an event
        event = self.create_event()
        # and get its manager
        manager = IPublishStorageManager(event)
        # we must have empty values here
        self.assertEqual(manager.get_accounts(),{})
        self.assertEqual(manager.get_text(),'')

        # we can now publish it using `social-publish` view
        view = event.restrictedTraverse('@@social-publish')
        publishers = [test_utils.FakePublisher.id]
        accounts = {test_utils.FakePublisher.id:'simahawk'}
        result = view.publish(publishers=publishers,accounts=accounts)
        # we expect the content of the publication to be equal `get_text` result
        # and the publisher/account mapping matching the one we pass to the publisher
        expected = {'content': 'Great event http://nohost/plone/event', 'fakepub': 'simahawk'}
        self.assertEqual(result,expected)
        # publisher/account mapping is saved by default by the publishing view
        self.assertEqual(manager.get_accounts(),{'fakepub': 'simahawk'})
Пример #3
0
    def publish(self):
        settings = utils.get_global_settings()
        if not settings.autopublish_enabled:
            self.logger.info(self.msg_autopublish_disabled)
            return self.msg_autopublish_disabled

        for brain in self.get_items():
            obj = brain.getObject()
            manager = IPublishStorageManager(obj)
            # XXX: we should delegate default text get to manager (?)
            content = manager.get_text() or utils.get_text(obj)
            for publisher, account_id in manager.get_accounts().items():
                self._publish(content, publisher, account_id=account_id)

        self.logger.info(self.msg_autopublish_done)
        return self.msg_autopublish_done
    def publish(self):
        settings = utils.get_global_settings()
        if not settings.autopublish_enabled:
            self.logger.info(self.msg_autopublish_disabled)
            return self.msg_autopublish_disabled

        for brain in self.get_items():
            obj = brain.getObject()
            manager = IPublishStorageManager(obj)
            # XXX: we should delegate default text get to manager (?)
            content = manager.get_text() or utils.get_text(obj)
            for publisher, account_id in manager.get_accounts().items():
                self._publish(content, publisher, account_id=account_id)

        self.logger.info(self.msg_autopublish_done)
        return self.msg_autopublish_done