コード例 #1
0
    async def test_on_request_successful_raise_exception_if_redirect_fail(self):
        engine = MagicMock()
        engine.perform = make_mocked_coro(raise_exception=StopRequest())
        self.rule.set_engine(engine)

        with self.assertRaises(StopRequest):
            await self.rule.on_request_successful(self.entry)
コード例 #2
0
    async def test_remove_lock_if_stop_request_raised(self):
        self.engine.mock.perform_high_priority.side_effect = StopRequest(
            "Timeout reached.")

        await self.rule.after_response(
            self.create_entry("http://example.com/test"))

        self.assertEqual(self.rule.performed["http://example.com/"]["/\l"],
                         None)
コード例 #3
0
ファイル: filefetcher.py プロジェクト: ouaibe/tachyon
    async def after_response(self, entry):
        if entry.result.string_match:
            # We found what we were looking for, this entry has to be valid.
            return

        if getattr(entry.result, "error_behavior", False):
            raise StopRequest("Error behavior detected.")
        if getattr(entry.result, "soft404", False):
            raise RejectRequest("Soft 404 detected")
コード例 #4
0
    async def test_add_None_to_knowledge_base_if_request_failed(self):
        self.engine.mock.perform_high_priority.side_effect = StopRequest(
            "Timeout reached.")

        await self.rule.after_response(
            self.create_entry("http://example.com/test",
                              response_content="response"))

        self.assertEqual(self.kb.soft_404_responses["http://example.com/"],
                         {"/\l": None})
コード例 #5
0
    async def test_fetcher_increase_timeout_count_on_stop_request(self, loop):
        self._setup_async_test(loop)
        self.hammertime.request_engine.perform = make_mocked_coro(
            raise_exception=StopRequest())

        requests = self.fetcher.request_files(self.plugin_key,
                                              self.files_to_fetch)

        await asyncio.wait_for(requests, None, loop=loop)

        self.assertEqual(self.fetcher.timeouts, len(self.files_to_fetch.files))
コード例 #6
0
    async def test_awaiting_requests_ignores_timeout_errors(self, loop):
        self._setup_async_test(loop)
        self.hammertime.request_engine.perform = make_mocked_coro(
            raise_exception=StopRequest())

        requests = self.fetcher.request_files(self.plugin_key,
                                              self.files_to_fetch)

        try:
            await asyncio.wait_for(requests, None, loop=loop)
        except StopRequest:
            self.fail("Timeout error raised.")
コード例 #7
0
    async def test_failure_interrupts(self, fake_future):
        r1 = make_mocked_coro(raise_exception=StopRequest())
        r2 = make_mocked_coro()

        rs = RuleSet()
        with patch('asyncio.iscoroutinefunction', MagicMock(return_value=True)):
            rs.add(r1)
            rs.add(r2)

            entry = Entry.create('http://example.com')

            with self.assertRaises(StopRequest):
                await rs.accept(entry)

            r1.assert_called_with(entry)
            r2.assert_not_called()
コード例 #8
0
 async def before_request(self, entry):
     if entry.request.url == self.url and entry.result.attempt < 3:
         raise StopRequest()
コード例 #9
0
ファイル: retryonerrors.py プロジェクト: robputt796/vane2
 async def after_headers(self, entry):
     if entry.response.code in self.errors_set:
         raise StopRequest("Status code %s, retry request" %
                           entry.response.code)