Skip to content

Commit 7e794c4

Browse files
committed
Update quotes in aiohttp tutorial
1 parent 93dad6b commit 7e794c4

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

docs/tutorials/aiohttp.rst

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,16 @@ Edit ``handlers.py``:
177177
178178
179179
async def index(request: web.Request) -> web.Response:
180-
query = request.query.get('query', 'Dependency Injector')
181-
limit = int(request.query.get('limit', 10))
180+
query = request.query.get("query", "Dependency Injector")
181+
limit = int(request.query.get("limit", 10))
182182
183183
gifs = []
184184
185185
return web.json_response(
186186
{
187-
'query': query,
188-
'limit': limit,
189-
'gifs': gifs,
187+
"query": query,
188+
"limit": limit,
189+
"gifs": gifs,
190190
},
191191
)
192192
@@ -228,7 +228,7 @@ Put next into the ``application.py``:
228228
app = web.Application()
229229
app.container = container
230230
app.add_routes([
231-
web.get('/', handlers.index),
231+
web.get("/", handlers.index),
232232
])
233233
return app
234234
@@ -304,19 +304,19 @@ and put next into it:
304304
305305
class GiphyClient:
306306
307-
API_URL = 'https://api.giphy.com/v1'
307+
API_URL = "https://api.giphy.com/v1"
308308
309309
def __init__(self, api_key, timeout):
310310
self._api_key = api_key
311311
self._timeout = ClientTimeout(timeout)
312312
313313
async def search(self, query, limit):
314314
"""Make search API call and return result."""
315-
url = f'{self.API_URL}/gifs/search'
315+
url = f"{self.API_URL}/gifs/search"
316316
params = {
317-
'q': query,
318-
'api_key': self._api_key,
319-
'limit': limit,
317+
"q": query,
318+
"api_key": self._api_key,
319+
"limit": limit,
320320
}
321321
async with ClientSession(timeout=self._timeout) as session:
322322
async with session.get(url, params=params) as response:
@@ -409,13 +409,13 @@ Edit ``application.py``:
409409
410410
def create_app() -> web.Application:
411411
container = Container()
412-
container.config.from_yaml('config.yml')
413-
container.config.giphy.api_key.from_env('GIPHY_API_KEY')
412+
container.config.from_yaml("config.yml")
413+
container.config.giphy.api_key.from_env("GIPHY_API_KEY")
414414
415415
app = web.Application()
416416
app.container = container
417417
app.add_routes([
418-
web.get('/', handlers.index),
418+
web.get("/", handlers.index),
419419
])
420420
return app
421421
@@ -483,7 +483,7 @@ and put next into it:
483483
484484
result = await self._giphy_client.search(query, limit)
485485
486-
return [{'url': gif['url']} for gif in result['data']]
486+
return [{"url": gif["url"]} for gif in result["data"]]
487487
488488
The ``SearchService`` has a dependency on the ``GiphyClient``. This dependency will be
489489
injected when we add ``SearchService`` to the container.
@@ -531,7 +531,7 @@ Edit ``handlers.py``:
531531
"""Handlers module."""
532532
533533
from aiohttp import web
534-
from dependency_injector.wiring import inject, Provide
534+
from dependency_injector.wiring import Provide, inject
535535
536536
from .services import SearchService
537537
from .containers import Container
@@ -542,16 +542,16 @@ Edit ``handlers.py``:
542542
request: web.Request,
543543
search_service: SearchService = Provide[Container.search_service],
544544
) -> web.Response:
545-
query = request.query.get('query', 'Dependency Injector')
546-
limit = int(request.query.get('limit', 10))
545+
query = request.query.get("query", "Dependency Injector")
546+
limit = int(request.query.get("limit", 10))
547547
548548
gifs = await search_service.search(query, limit)
549549
550550
return web.json_response(
551551
{
552-
'query': query,
553-
'limit': limit,
554-
'gifs': gifs,
552+
"query": query,
553+
"limit": limit,
554+
"gifs": gifs,
555555
},
556556
)
557557
@@ -574,14 +574,14 @@ Edit ``application.py``:
574574
575575
def create_app() -> web.Application:
576576
container = Container()
577-
container.config.from_yaml('config.yml')
578-
container.config.giphy.api_key.from_env('GIPHY_API_KEY')
577+
container.config.from_yaml("config.yml")
578+
container.config.giphy.api_key.from_env("GIPHY_API_KEY")
579579
container.wire(modules=[handlers])
580580
581581
app = web.Application()
582582
app.container = container
583583
app.add_routes([
584-
web.get('/', handlers.index),
584+
web.get("/", handlers.index),
585585
])
586586
return app
587587
@@ -651,7 +651,7 @@ Edit ``handlers.py``:
651651
"""Handlers module."""
652652
653653
from aiohttp import web
654-
from dependency_injector.wiring import inject, Provide
654+
from dependency_injector.wiring import Provide, inject
655655
656656
from .services import SearchService
657657
from .containers import Container
@@ -664,16 +664,16 @@ Edit ``handlers.py``:
664664
default_query: str = Provide[Container.config.default.query],
665665
default_limit: int = Provide[Container.config.default.limit.as_int()],
666666
) -> web.Response:
667-
query = request.query.get('query', default_query)
668-
limit = int(request.query.get('limit', default_limit))
667+
query = request.query.get("query", default_query)
668+
limit = int(request.query.get("limit", default_limit))
669669
670670
gifs = await search_service.search(query, limit)
671671
672672
return web.json_response(
673673
{
674-
'query': query,
675-
'limit': limit,
676-
'gifs': gifs,
674+
"query": query,
675+
"limit": limit,
676+
"gifs": gifs,
677677
},
678678
)
679679
@@ -745,60 +745,60 @@ and put next into it:
745745
async def test_index(client, app):
746746
giphy_client_mock = mock.AsyncMock(spec=GiphyClient)
747747
giphy_client_mock.search.return_value = {
748-
'data': [
749-
{'url': 'https://giphy.com/gif1.gif'},
750-
{'url': 'https://giphy.com/gif2.gif'},
748+
"data": [
749+
{"url": "https://giphy.com/gif1.gif"},
750+
{"url": "https://giphy.com/gif2.gif"},
751751
],
752752
}
753753
754754
with app.container.giphy_client.override(giphy_client_mock):
755755
response = await client.get(
756-
'/',
756+
"/",
757757
params={
758-
'query': 'test',
759-
'limit': 10,
758+
"query": "test",
759+
"limit": 10,
760760
},
761761
)
762762
763763
assert response.status == 200
764764
data = await response.json()
765765
assert data == {
766-
'query': 'test',
767-
'limit': 10,
768-
'gifs': [
769-
{'url': 'https://giphy.com/gif1.gif'},
770-
{'url': 'https://giphy.com/gif2.gif'},
766+
"query": "test",
767+
"limit": 10,
768+
"gifs": [
769+
{"url": "https://giphy.com/gif1.gif"},
770+
{"url": "https://giphy.com/gif2.gif"},
771771
],
772772
}
773773
774774
775775
async def test_index_no_data(client, app):
776776
giphy_client_mock = mock.AsyncMock(spec=GiphyClient)
777777
giphy_client_mock.search.return_value = {
778-
'data': [],
778+
"data": [],
779779
}
780780
781781
with app.container.giphy_client.override(giphy_client_mock):
782-
response = await client.get('/')
782+
response = await client.get("/")
783783
784784
assert response.status == 200
785785
data = await response.json()
786-
assert data['gifs'] == []
786+
assert data["gifs"] == []
787787
788788
789789
async def test_index_default_params(client, app):
790790
giphy_client_mock = mock.AsyncMock(spec=GiphyClient)
791791
giphy_client_mock.search.return_value = {
792-
'data': [],
792+
"data": [],
793793
}
794794
795795
with app.container.giphy_client.override(giphy_client_mock):
796-
response = await client.get('/')
796+
response = await client.get("/")
797797
798798
assert response.status == 200
799799
data = await response.json()
800-
assert data['query'] == app.container.config.default.query()
801-
assert data['limit'] == app.container.config.default.limit()
800+
assert data["query"] == app.container.config.default.query()
801+
assert data["limit"] == app.container.config.default.limit()
802802
803803
Now let's run it and check the coverage:
804804

0 commit comments

Comments
 (0)