Пример #1
0
 def test_raising_custom_error(self):
     with aioresponses() as aiomock:
         aiomock.get(self.url, exception=HttpProcessingError(message='foo'))
         with self.assertRaises(HttpProcessingError):
             self.loop.run_until_complete(
                 self.session.get(self.url)
             )
Пример #2
0
    async def test_raising_exception(self):
        with aioresponses() as aiomock:
            url = 'http://example.com/Exception'
            aiomock.get(url, exception=Exception)
            with self.assertRaises(Exception):
                await self.session.get(url)

            url = 'http://example.com/Exception_object'
            aiomock.get(url, exception=Exception())
            with self.assertRaises(Exception):
                await self.session.get(url)

            url = 'http://example.com/BaseException'
            aiomock.get(url, exception=BaseException)
            with self.assertRaises(BaseException):
                await self.session.get(url)

            url = 'http://example.com/BaseException_object'
            aiomock.get(url, exception=BaseException())
            with self.assertRaises(BaseException):
                await self.session.get(url)

            url = 'http://example.com/CancelError'
            aiomock.get(url, exception=CancelledError)
            with self.assertRaises(CancelledError):
                await self.session.get(url)

            url = 'http://example.com/TimeoutError'
            aiomock.get(url, exception=TimeoutError)
            with self.assertRaises(TimeoutError):
                await self.session.get(url)

            url = 'http://example.com/HttpProcessingError'
            aiomock.get(url, exception=HttpProcessingError(message='foo'))
            with self.assertRaises(HttpProcessingError):
                await self.session.get(url)

            callback_called = asyncio.Event()
            url = 'http://example.com/HttpProcessingError'
            aiomock.get(url,
                        exception=HttpProcessingError(message='foo'),
                        callback=lambda *_, **__: callback_called.set())
            with self.assertRaises(HttpProcessingError):
                await self.session.get(url)

            await callback_called.wait()
Пример #3
0
def test_aget_job_404(mocker, SETTINGS):
    mocker.patch('jenkins_epo.jenkins.LazyJenkins.load')
    mocker.patch('jenkins_epo.jenkins.Job.factory')

    from aiohttp.errors import HttpProcessingError
    from jenkins_epo.jenkins import LazyJenkins, UnknownJob

    my = LazyJenkins()
    my._instance = Mock()
    my.rest = Mock()
    my.rest.job().api.python.aget = CoroutineMock(
        side_effect=HttpProcessingError(code=404))
    my.rest.job()().aget = CoroutineMock()

    with pytest.raises(UnknownJob):
        yield from my.aget_job('name')
Пример #4
0
    def test_raising_exception(self):
        with aioresponses() as aiomock:
            url = 'http://example.com/Exception'
            aiomock.get(url, exception=Exception)
            with self.assertRaises(Exception):
                yield from self.session.get(url)

            url = 'http://example.com/Exception_object'
            aiomock.get(url, exception=Exception())
            with self.assertRaises(Exception):
                yield from self.session.get(url)

            url = 'http://example.com/BaseException'
            aiomock.get(url, exception=BaseException)
            with self.assertRaises(BaseException):
                yield from self.session.get(url)

            url = 'http://example.com/BaseException_object'
            aiomock.get(url, exception=BaseException())
            with self.assertRaises(BaseException):
                yield from self.session.get(url)

            url = 'http://example.com/CancelError'
            aiomock.get(url, exception=CancelledError)
            with self.assertRaises(CancelledError):
                yield from self.session.get(url)

            url = 'http://example.com/TimeoutError'
            aiomock.get(url, exception=TimeoutError)
            with self.assertRaises(TimeoutError):
                yield from self.session.get(url)

            url = 'http://example.com/HttpProcessingError'
            aiomock.get(url, exception=HttpProcessingError(message='foo'))
            with self.assertRaises(HttpProcessingError):
                yield from self.session.get(url)
Пример #5
0
 def test_raising_custom_error(self):
     with aioresponses() as aiomock:
         aiomock.get(self.url, exception=HttpProcessingError(message='foo'))
         with self.assertRaises(HttpProcessingError):
             yield from self.session.get(self.url)
Пример #6
0
async def error(request):
    raise HttpProcessingError(code=403, message="unauthorized")