Skip to content

Commit

Permalink
Upgrade to latest aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
lphuberdeau committed Apr 20, 2018
1 parent 3152921 commit b87ea71
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
7 changes: 3 additions & 4 deletions tests/wordpress_test/enumerate_plugins_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
7 changes: 3 additions & 4 deletions tests/wordpress_test/enumerate_themes_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit b87ea71

Please sign in to comment.