Skip to content

Commit aa59d09

Browse files
committed
remove inititalize and close
1 parent f9662f6 commit aa59d09

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

eventsourcingdb/client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ async def __aexit__(
4545
) -> None:
4646
await self.__http_client.__aexit__(exc_type, exc_val, exc_tb)
4747

48-
async def initialize(self) -> None:
49-
await self.__http_client.initialize()
50-
51-
async def close(self) -> None:
52-
await self.__http_client.close()
53-
5448
@property
5549
def http_client(self) -> HttpClient:
5650
return self.__http_client

eventsourcingdb/http_client/http_client.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import aiohttp
44
from aiohttp import ClientSession
55

6-
from ..errors.custom_error import CustomError
7-
86
from .get_get_headers import get_get_headers
97
from .get_post_headers import get_post_headers
108
from .response import Response
@@ -21,7 +19,7 @@ def __init__(
2119
self.__session: ClientSession | None = None
2220

2321
async def __aenter__(self):
24-
await self.initialize()
22+
await self.__initialize()
2523
return self
2624

2725
async def __aexit__(
@@ -30,12 +28,12 @@ async def __aexit__(
3028
exc_val: BaseException | None = None,
3129
exc_tb: TracebackType | None = None,
3230
) -> None:
33-
await self.close()
31+
await self.__close()
3432

35-
async def initialize(self) -> None:
33+
async def __initialize(self) -> None:
3634
self.__session = aiohttp.ClientSession()
3735

38-
async def close(self):
36+
async def __close(self):
3937
if self.__session is not None:
4038
await self.__session.close()
4139
self.__session = None
@@ -49,7 +47,7 @@ def join_segments(first: str, *rest: str) -> str:
4947

5048
async def post(self, path: str, request_body: str) -> Response:
5149
if self.__session is None:
52-
await self.initialize()
50+
await self.__initialize()
5351

5452
url_path = HttpClient.join_segments(self.__base_url, path)
5553
headers = get_post_headers(self.__api_token)
@@ -70,8 +68,7 @@ async def get(
7068
with_authorization: bool = True,
7169
) -> Response:
7270
if self.__session is None:
73-
raise CustomError(
74-
"HTTP client session not initialized. Call initialize() before making requests.")
71+
await self.__initialize()
7572

7673
async def __request_executor() -> Response:
7774
url_path = HttpClient.join_segments(self.__base_url, path)

tests/conftest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
@pytest_asyncio.fixture
77
async def database():
88
testing_db = await Database.create()
9-
yield testing_db
10-
11-
if testing_db is not None:
12-
await testing_db.stop()
9+
try:
10+
yield testing_db
11+
finally:
12+
if testing_db is not None:
13+
await testing_db.stop()
1314

1415

1516
class TestData:

tests/shared/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def _create_container(cls, api_token, image_tag):
3535
@staticmethod
3636
async def _initialize_clients(container, api_token):
3737
with_authorization_client = container.get_client()
38-
await with_authorization_client.initialize()
38+
#await with_authorization_client.initialize()
3939

4040
with_invalid_url_client = Client(
4141
base_url='http://localhost.invalid',
4242
api_token=api_token
4343
)
44-
await with_invalid_url_client.initialize()
44+
#await with_invalid_url_client.initialize()
4545

4646
return with_authorization_client, with_invalid_url_client
4747

tests/shared/start_local_http_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ def stop_server():
7373
f'http://localhost:{local_http_server.port}',
7474
'access-token',
7575
)
76-
await client.initialize()
76+
# await client.initialize()
7777

7878
return client, stop_server

0 commit comments

Comments
 (0)