Skip to content

Commit b5eeb52

Browse files
committed
fixture function for batches [services_factory_function]
1 parent c76a54f commit b5eeb52

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎test_services.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
class FakeRepository(repository.AbstractRepository):
88

9+
@staticmethod
10+
def for_batch(ref, sku, qty, eta=None):
11+
return FakeRepository([
12+
model.Batch(ref, sku, qty, eta),
13+
])
14+
915
def __init__(self, batches):
1016
self._batches = set(batches)
1117

@@ -27,25 +33,19 @@ def commit(self):
2733

2834

2935
def test_returns_allocation():
30-
batch = model.Batch("batch1", "COMPLICATED-LAMP", 100, eta=None)
31-
repo = FakeRepository([batch])
32-
36+
repo = FakeRepository.for_batch("batch1", "COMPLICATED-LAMP", 100, eta=None)
3337
result = services.allocate("o1", "COMPLICATED-LAMP", 10, repo, FakeSession())
3438
assert result == "batch1"
3539

3640

3741
def test_error_for_invalid_sku():
38-
batch = model.Batch("b1", "AREALSKU", 100, eta=None)
39-
repo = FakeRepository([batch])
40-
42+
repo = FakeRepository.for_batch('b1', 'AREALSKU', 100, eta=None)
4143
with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"):
4244
services.allocate("o1", "NONEXISTENTSKU", 10, repo, FakeSession())
4345

4446

4547
def test_commits():
46-
batch = model.Batch("b1", "OMINOUS-MIRROR", 100, eta=None)
47-
repo = FakeRepository([batch])
48+
repo = FakeRepository.for_batch("b1", "OMINOUS-MIRROR", 100, eta=None)
4849
session = FakeSession()
49-
5050
services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
5151
assert session.committed is True

0 commit comments

Comments
 (0)