File tree Expand file tree Collapse file tree 8 files changed +25
-24
lines changed
Expand file tree Collapse file tree 8 files changed +25
-24
lines changed Original file line number Diff line number Diff line change 66@V1 .get ("/confirmed" )
77async def confirmed ():
88 """Confirmed cases."""
9- confirmed = await get_category ("confirmed" )
9+ confirmed_data = await get_category ("confirmed" )
1010
11- return confirmed
11+ return confirmed_data
Original file line number Diff line number Diff line change 66@V1 .get ("/deaths" )
77async def deaths ():
88 """Total deaths."""
9- deaths = await get_category ("deaths" )
9+ deaths_data = await get_category ("deaths" )
1010
11- return deaths
11+ return deaths_data
Original file line number Diff line number Diff line change 66@V1 .get ("/recovered" )
77async def recovered ():
88 """Recovered cases."""
9- recovered = await get_category ("recovered" )
9+ recovered_data = await get_category ("recovered" )
1010
11- return recovered
11+ return recovered_data
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ async def get_locations():
3939 :returns: The locations.
4040 :rtype: dict
4141 """
42- async with httputils .client_session .get (BASE_URL ) as response :
42+ async with httputils .CLIENT_SESSION .get (BASE_URL ) as response :
4343 text = await response .text ()
4444
4545 data = list (csv .DictReader (text .splitlines ()))
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ async def get_category(category):
5555 url = BASE_URL + "time_series_covid19_%s_global.csv" % category
5656
5757 # Request the data
58- async with httputils .client_session .get (url ) as response :
58+ async with httputils .CLIENT_SESSION .get (url ) as response :
5959 text = await response .text ()
6060
6161 # Parse the CSV.
Original file line number Diff line number Diff line change 1+ """app.utils.httputils.py"""
12import logging
23
34from aiohttp import ClientSession
45
56
67# Singleton aiohttp.ClientSession instance.
7- client_session : ClientSession
8+ CLIENT_SESSION : ClientSession
89
910
1011LOGGER = logging .getLogger (__name__ )
@@ -17,14 +18,14 @@ async def setup_client_session():
1718 See: https://docs.aiohttp.org/en/stable/client_quickstart.html#make-a-request
1819
1920 """
20- global client_session
21+ global CLIENT_SESSION # pylint: disable=global-statement
2122 LOGGER .info ("Setting up global aiohttp.ClientSession." )
22- client_session = ClientSession ()
23+ CLIENT_SESSION = ClientSession ()
2324
2425
2526async def teardown_client_session ():
2627 """Close the application-global aiohttp.ClientSession.
2728 """
28- global client_session
29+ global CLIENT_SESSION # pylint: disable=global-statement
2930 LOGGER .info ("Closing global aiohttp.ClientSession." )
30- await client_session .close ()
31+ await CLIENT_SESSION .close ()
Original file line number Diff line number Diff line change @@ -80,12 +80,12 @@ def mock_client_session_class(request):
8080 See: https://docs.pytest.org/en/5.4.1/unittest.html#mixing-pytest-fixtures-into-unittest-testcase-subclasses-using-marks
8181 """
8282
83- httputils .client_session = request .cls .mock_client_session = mock .AsyncMock ()
84- httputils .client_session .get = mocked_session_get
83+ httputils .CLIENT_SESSION = request .cls .mock_client_session = mock .AsyncMock ()
84+ httputils .CLIENT_SESSION .get = mocked_session_get
8585 try :
8686 yield
8787 finally :
88- del httputils .client_session
88+ del httputils .CLIENT_SESSION
8989
9090
9191@pytest .fixture
@@ -94,12 +94,12 @@ async def mock_client_session():
9494 instance.
9595 """
9696
97- httputils .client_session = mock .AsyncMock ()
98- httputils .client_session .get = mocked_session_get
97+ httputils .CLIENT_SESSION = mock .AsyncMock ()
98+ httputils .CLIENT_SESSION .get = mocked_session_get
9999 try :
100- yield httputils .client_session
100+ yield httputils .CLIENT_SESSION
101101 finally :
102- del httputils .client_session
102+ del httputils .CLIENT_SESSION
103103
104104
105105@asynccontextmanager
Original file line number Diff line number Diff line change 77async def test_setup_teardown_client_session ():
88 with pytest .raises (AttributeError ):
99 # Ensure client_session is undefined prior to setup
10- httputils .client_session
10+ httputils .CLIENT_SESSION
1111
1212 await httputils .setup_client_session ()
1313
14- assert httputils .client_session
14+ assert httputils .CLIENT_SESSION
1515
1616 await httputils .teardown_client_session ()
17- assert httputils .client_session .closed
17+ assert httputils .CLIENT_SESSION .closed
1818
19- del httputils .client_session
19+ del httputils .CLIENT_SESSION
You can’t perform that action at this time.
0 commit comments