55
66
77class FakeRepository (repository .AbstractRepository ):
8+ @staticmethod
9+ def for_batch (ref , sku , qty , eta = None ):
10+ return FakeRepository ([model .Batch (ref , sku , qty , eta ),])
11+
812 def __init__ (self , batches ):
913 self ._batches = set (batches )
1014
@@ -26,25 +30,19 @@ def commit(self):
2630
2731
2832def test_returns_allocation ():
29- batch = model .Batch ("batch1" , "COMPLICATED-LAMP" , 100 , eta = None )
30- repo = FakeRepository ([batch ])
31-
33+ repo = FakeRepository .for_batch ("batch1" , "COMPLICATED-LAMP" , 100 , eta = None )
3234 result = services .allocate ("o1" , "COMPLICATED-LAMP" , 10 , repo , FakeSession ())
3335 assert result == "batch1"
3436
3537
3638def test_error_for_invalid_sku ():
37- batch = model .Batch ("b1" , "AREALSKU" , 100 , eta = None )
38- repo = FakeRepository ([batch ])
39-
39+ repo = FakeRepository .for_batch ("b1" , "AREALSKU" , 100 , eta = None )
4040 with pytest .raises (services .InvalidSku , match = "Invalid sku NONEXISTENTSKU" ):
4141 services .allocate ("o1" , "NONEXISTENTSKU" , 10 , repo , FakeSession ())
4242
4343
4444def test_commits ():
45- batch = model .Batch ("b1" , "OMINOUS-MIRROR" , 100 , eta = None )
46- repo = FakeRepository ([batch ])
45+ repo = FakeRepository .for_batch ("b1" , "OMINOUS-MIRROR" , 100 , eta = None )
4746 session = FakeSession ()
48-
4947 services .allocate ("o1" , "OMINOUS-MIRROR" , 10 , repo , session )
5048 assert session .committed is True
0 commit comments