mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-04 20:33:13 +03:00
Migrate ext.aiohttp tests
This commit is contained in:
parent
602d9336e1
commit
56c39554e7
|
@ -1,3 +1,5 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
testpaths = tests/unit
|
testpaths = tests/unit
|
||||||
python_files = test_*_py2_py3.py
|
python_files = test_*_py2_py3.py
|
||||||
|
filterwarnings =
|
||||||
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
testpaths = tests/unit
|
testpaths = tests/unit
|
||||||
python_files = test_*_py3.py
|
python_files = test_*_py3.py
|
||||||
|
filterwarnings =
|
||||||
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
testpaths = tests/unit
|
testpaths = tests/unit
|
||||||
python_files = test_*_py3*.py
|
python_files = test_*_py3*.py
|
||||||
|
filterwarnings =
|
||||||
|
ignore:Module \"dependency_injector.ext.aiohttp\" is deprecated since version 4\.0\.0:DeprecationWarning
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
"""Dependency injector Aiohttp extension unit tests."""
|
"""Aiohttp extension tests."""
|
||||||
|
|
||||||
from aiohttp import web
|
|
||||||
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop
|
|
||||||
|
|
||||||
|
from aiohttp import web, test_utils
|
||||||
from dependency_injector import containers, providers
|
from dependency_injector import containers, providers
|
||||||
from dependency_injector.ext import aiohttp
|
from dependency_injector.ext import aiohttp
|
||||||
|
from pytest import fixture, mark
|
||||||
|
|
||||||
|
|
||||||
async def index_view(_):
|
async def index_view(_):
|
||||||
|
@ -51,12 +50,8 @@ class ApplicationContainer(containers.DeclarativeContainer):
|
||||||
other_class_based_view = aiohttp.ClassBasedView(OtherClassBasedView)
|
other_class_based_view = aiohttp.ClassBasedView(OtherClassBasedView)
|
||||||
|
|
||||||
|
|
||||||
class ApplicationTests(AioHTTPTestCase):
|
@fixture
|
||||||
|
def app():
|
||||||
async def get_application(self):
|
|
||||||
"""
|
|
||||||
Override the get_app method to return your application.
|
|
||||||
"""
|
|
||||||
container = ApplicationContainer()
|
container = ApplicationContainer()
|
||||||
app = container.app()
|
app = container.app()
|
||||||
app.container = container
|
app.container = container
|
||||||
|
@ -67,27 +62,36 @@ class ApplicationTests(AioHTTPTestCase):
|
||||||
])
|
])
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@unittest_run_loop
|
|
||||||
async def test_index(self):
|
|
||||||
response = await self.client.get("/")
|
|
||||||
|
|
||||||
self.assertEqual(response.status, 200)
|
@fixture
|
||||||
self.assertEqual(await response.text(), "Hello World! wink2 wink1")
|
async def client(app):
|
||||||
|
async with test_utils.TestClient(test_utils.TestServer(app)) as client:
|
||||||
|
yield client
|
||||||
|
|
||||||
@unittest_run_loop
|
|
||||||
async def test_second(self):
|
|
||||||
response = await self.client.get("/second")
|
|
||||||
|
|
||||||
self.assertEqual(response.status, 200)
|
@mark.asyncio
|
||||||
self.assertEqual(await response.text(), "Test! wink2 wink1")
|
async def test_index(client):
|
||||||
|
response = await client.get("/")
|
||||||
|
|
||||||
@unittest_run_loop
|
assert response.status == 200
|
||||||
async def test_class_based(self):
|
assert await response.text() == "Hello World! wink2 wink1"
|
||||||
response = await self.client.get("/class-based")
|
|
||||||
|
|
||||||
self.assertEqual(response.status, 200)
|
|
||||||
self.assertEqual(await response.text(), "Test class-based! wink2 wink1")
|
|
||||||
|
|
||||||
@unittest_run_loop
|
@mark.asyncio
|
||||||
async def test_endpoints(self):
|
async def test_second(client):
|
||||||
self.assertEqual(str(self.app.router["second"].url_for()), "/second")
|
response = await client.get("/second")
|
||||||
|
|
||||||
|
assert response.status == 200
|
||||||
|
assert await response.text() == "Test! wink2 wink1"
|
||||||
|
|
||||||
|
|
||||||
|
@mark.asyncio
|
||||||
|
async def test_class_based(client):
|
||||||
|
response = await client.get("/class-based")
|
||||||
|
|
||||||
|
assert response.status == 200
|
||||||
|
assert await response.text() == "Test class-based! wink2 wink1"
|
||||||
|
|
||||||
|
|
||||||
|
def test_endpoints(app):
|
||||||
|
assert str(app.router["second"].url_for()) == "/second"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user