Skip to content

Commit 1e1f238

Browse files
committed
fixture function for batches [services_factory_function]
1 parent f341bee commit 1e1f238

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tests/unit/test_services.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66

77
class 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

2832
def 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

3638
def 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

4444
def 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

Comments
 (0)