コード例 #1
0
ファイル: tap.py プロジェクト: MariaAbrahms/otter
def makeService(config):
    """
    Make the FeedPollerService that will polling AtomHopper.
    """
    s = MultiService()

    config = json.loads(open(config['config']).read())

    agent = Agent(reactor, pool=HTTPConnectionPool(reactor, persistent=True))

    for service_name, service_desc in config['services'].iteritems():
        for url in service_desc['urls']:
            fps = FeedPollerService(
                agent,
                str(url),
                [namedAny(h)
                 for h in service_desc.get('event_handlers', [])],
                state_store=FileStateStore(hashlib.md5(url).hexdigest()))
            fps.setServiceParent(s)

    return s
コード例 #2
0
ファイル: test_poller.py プロジェクト: dwcramer/otter
    def setUp(self):
        """
        Create a FeedPollerService with a mock agent, TimerService,
        and cooperator that do not use the real reactor
        """
        self.handler = mock.Mock()
        self.agent = mock.Mock(Agent)
        self.timer = mock.Mock(TimerService)

        self.cooperator = Cooperator(
            scheduler=lambda x: x(),
            started=True
        )

        self.poller = FeedPollerService(
            self.agent, 'http://example.com/feed',
            [self.handler],
            TimerService=self.timer,
            coiterate=self.cooperator.coiterate
        )

        self.poll = self.timer.mock_calls[0][1][1]
コード例 #3
0
ファイル: test_poller.py プロジェクト: dwcramer/otter
class FeedPollerServiceTests(SynchronousTestCase):
    """
    Tests for :class:`otter.indexer.poller.FeedPollerService`
    """

    def setUp(self):
        """
        Create a FeedPollerService with a mock agent, TimerService,
        and cooperator that do not use the real reactor
        """
        self.handler = mock.Mock()
        self.agent = mock.Mock(Agent)
        self.timer = mock.Mock(TimerService)

        self.cooperator = Cooperator(
            scheduler=lambda x: x(),
            started=True
        )

        self.poller = FeedPollerService(
            self.agent, 'http://example.com/feed',
            [self.handler],
            TimerService=self.timer,
            coiterate=self.cooperator.coiterate
        )

        self.poll = self.timer.mock_calls[0][1][1]

    def test_startService(self):
        """
        ``startService`` calls the TimerService's ``startService``
        """
        self.poller.startService()
        self.timer.return_value.startService.assert_called_once_with()

    def test_stopService(self):
        """
        ``stopService`` calls the TimerService's ``stopService``
        """
        self.poller.stopService()
        self.timer.return_value.stopService.assert_called_once_with()

    def test_poll(self):
        """
        During a polling interval, a request is made to the URL specified
        to the constructor of the FeedPollerService, and the response from the
        server is parsed into atom entries, which are then passed to the
        handler.
        """
        self.agent.request.return_value = feed_response('simple.atom')

        self.poll()

        self.agent.request.assert_called_once_with(
            'GET',
            'http://example.com/feed',
            Headers({}),
            None
        )

        self.handler.assert_called_once_with(mock.ANY)
        entry = self.handler.mock_calls[0][1][0]

        self.assertEqual(
            entry.find('./{http://www.w3.org/2005/Atom}id').text,
            'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a'
        )