From b87ea7176fd9edd8371bc2e0eeea4a6c7cc32684 Mon Sep 17 00:00:00 2001 From: Louis-Philippe Huberdeau Date: Fri, 20 Apr 2018 10:20:04 -0400 Subject: [PATCH] Upgrade to latest aiohttp --- requirements.txt | 4 ++-- tests/fixtures.py | 18 +++++++++++++++++- tests/wordpress_test/enumerate_plugins_test.py | 7 +++---- tests/wordpress_test/enumerate_themes_test.py | 7 +++---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index b1fd84e..8f97a7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -aiohttp==2.1.0 +aiohttp>3.1,<3.2 easyinject==0.3 marshmallow==2.9.1 packaging==16.7 -lxml==3.6.4 +lxml>=3.6.4,<4 diff --git a/tests/fixtures.py b/tests/fixtures.py index 5f0ee26..c9bd0d0 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -16,11 +16,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import unittest -from unittest.mock import MagicMock +from unittest.mock import MagicMock, Mock import asyncio from functools import wraps from os.path import join, dirname from aiohttp.test_utils import loop_context +from aiohttp import ClientResponse as BaseClientResponse +from aiohttp.helpers import TimerNoop from easyinject import Injector @@ -34,6 +36,20 @@ def setup(f): return setup +def ClientResponse(method, url, *, + writer=None, continue100=None, timer=None, request_info=None, auto_decompress=True, + traces=None, loop=None, session=None): + return BaseClientResponse(method, url, + writer=writer or Mock(), + continue100=continue100, + timer=timer or TimerNoop(), + request_info=request_info or Mock(), + auto_decompress=auto_decompress, + traces=traces or [], + loop=loop or asyncio.get_event_loop(), + session=session or None) + + def file_path(relative, file): return join(dirname(relative), file) diff --git a/tests/wordpress_test/enumerate_plugins_test.py b/tests/wordpress_test/enumerate_plugins_test.py index 7fc05f5..76934df 100644 --- a/tests/wordpress_test/enumerate_plugins_test.py +++ b/tests/wordpress_test/enumerate_plugins_test.py @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from yarl import URL -from aiohttp import ClientResponse from asyncio import TimeoutError from unittest import TestCase from unittest.mock import MagicMock, call -from fixtures import read_file, async_test, fake_future, ClientSessionMock +from fixtures import read_file, async_test, fake_future, ClientSessionMock, ClientResponse from openwebvulndb.wordpress.repository import WordPressRepository, RepositoryUnreachable from openwebvulndb.wordpress.errors import PluginNotFound from openwebvulndb.common import Meta, Repository @@ -153,7 +152,7 @@ async def test_fetch_plugin_data(self, loop): my_response = ClientResponse('GET', URL('https://api.wordpress.org/plugins/info/1.0/better-wp-security.json')) my_response.status = 200 my_response.headers = {'Content-Type': 'application/json'} - my_response._content = read_file(__file__, 'better-wp-security.json').encode('utf8') + my_response._body = read_file(__file__, 'better-wp-security.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session) @@ -183,7 +182,7 @@ async def test_flag_as_popular_from_api(self, loop): '&request[browse]=popular&request[per_page]=200')) my_response.status = 200 my_response.headers = {'Content-Type': 'application/json'} - my_response._content = read_file(__file__, 'popular-plugins.json').encode('utf8') + my_response._body = read_file(__file__, 'popular-plugins.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session, storage=MagicMock()) diff --git a/tests/wordpress_test/enumerate_themes_test.py b/tests/wordpress_test/enumerate_themes_test.py index c07daa6..af8dafe 100644 --- a/tests/wordpress_test/enumerate_themes_test.py +++ b/tests/wordpress_test/enumerate_themes_test.py @@ -16,12 +16,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. from yarl import URL -from aiohttp import ClientResponse from asyncio import TimeoutError from unittest import TestCase from unittest.mock import MagicMock, call -from fixtures import read_file, async_test, fake_future, ClientSessionMock +from fixtures import read_file, async_test, fake_future, ClientSessionMock, ClientResponse from openwebvulndb.wordpress.repository import WordPressRepository, RepositoryUnreachable from openwebvulndb.wordpress.errors import PluginNotFound from openwebvulndb.common import Meta, Repository @@ -155,7 +154,7 @@ async def test_fetch_theme_data(self, loop): my_response = ClientResponse('GET', URL('https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=twentyeleven')) # noqa my_response.status = 200 my_response.headers = {'Content-Type': 'application/json'} - my_response._content = read_file(__file__, 'twentyeleven.json').encode('utf8') + my_response._body = read_file(__file__, 'twentyeleven.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session) @@ -186,7 +185,7 @@ async def test_flag_as_popular_from_api(self, loop): '&request[browse]=popular&request[per_page]=100')) my_response.status = 100 my_response.headers = {'Content-Type': 'application/json'} - my_response._content = read_file(__file__, 'popular-themes.json').encode('utf8') + my_response._body = read_file(__file__, 'popular-themes.json').encode('utf8') aiohttp_session = ClientSessionMock(get_response=my_response) handler = WordPressRepository(loop=loop, aiohttp_session=aiohttp_session, storage=MagicMock())