Skip to content

Commit f38ac9e

Browse files
committed
Turn RequestScope into context manager
1 parent 91f0cd6 commit f38ac9e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

auctioning_platform/main/main/modules.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def exit(self) -> None:
3535

3636
delattr(self._locals, self.REGISTRY_KEY)
3737

38+
def __enter__(self) -> None:
39+
self.enter()
40+
41+
def __exit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore
42+
self.exit()
43+
3844
def get(self, key: Type[T], provider: Provider[T]) -> Provider[T]:
3945
try:
4046
return getattr(self._locals, repr(key)) # type: ignore

auctioning_platform/web_app/web_app/tests/test_auctions.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from datetime import datetime, timedelta
2-
31
import factory
42
from flask.testing import FlaskClient
53
import injector
@@ -26,14 +24,10 @@ def example_auction(container: injector.Injector) -> int:
2624
"""It should rather use a sequence of other API calls, maybe auctions'
2725
module use cases specific for creating an auction, not adding directly to the DB.
2826
"""
29-
scope = container.get(RequestScope)
30-
scope.enter()
31-
try:
27+
with container.get(RequestScope):
3228
uc = container.get(BeginningAuction)
3329
dto = BeginningAuctionInputDtoFactory.build()
3430
uc.execute(dto)
35-
finally:
36-
scope.exit()
3731

3832
return int(dto.auction_id)
3933

0 commit comments

Comments
 (0)