File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55
66class AbstractRepository (abc .ABC ):
7- @abc .abstractmethod
7+ def __init__ (self ):
8+ self .seen = set () # type: Set[model.Product]
9+
810 def add (self , product : model .Product ):
11+ self ._add (product )
12+ self .seen .add (product )
13+
14+ def get (self , sku ) -> model .Product :
15+ product = self ._get (sku )
16+ if product :
17+ self .seen .add (product )
18+ return product
19+
20+ @abc .abstractmethod
21+ def _add (self , product : model .Product ):
922 raise NotImplementedError
1023
1124 @abc .abstractmethod
12- def get (self , sku ) -> model .Product :
25+ def _get (self , sku ) -> model .Product :
1326 raise NotImplementedError
1427
1528
1629class SqlAlchemyRepository (AbstractRepository ):
1730 def __init__ (self , session ):
31+ super ().__init__ ()
1832 self .session = session
19- self .seen = set () # type: Set[model.Product]
2033
21- def add (self , product ):
22- self .seen .add (product )
34+ def _add (self , product ):
2335 self .session .add (product )
2436
25- def get (self , sku ):
26- product = self .session .query (model .Product ).filter_by (sku = sku ).first ()
27- if product :
28- self .seen .add (product )
29- return product
37+ def _get (self , sku ):
38+ return self .session .query (model .Product ).filter_by (sku = sku ).first ()
Original file line number Diff line number Diff line change 66
77class FakeRepository (repository .AbstractRepository ):
88 def __init__ (self , products ):
9+ super ().__init__ ()
910 self ._products = set (products )
1011
11- def add (self , product ):
12+ def _add (self , product ):
1213 self ._products .add (product )
1314
14- def get (self , sku ):
15+ def _get (self , sku ):
1516 return next ((p for p in self ._products if p .sku == sku ), None )
1617
1718
You can’t perform that action at this time.
0 commit comments