Skip to content

Commit c8fbb60

Browse files
committed
all service-layer tests now services [services_tests_all_services]
1 parent 262eec0 commit c8fbb60

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

tests/unit/test_services.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import pytest
2-
from domain import model
32
from adapters import repository
43
from service_layer import services
54

65

76
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-
127
def __init__(self, batches):
138
self._batches = set(batches)
149

@@ -36,20 +31,24 @@ def test_add_batch():
3631
assert session.committed
3732

3833

39-
def test_returns_allocation():
40-
repo = FakeRepository.for_batch("batch1", "COMPLICATED-LAMP", 100, eta=None)
41-
result = services.allocate("o1", "COMPLICATED-LAMP", 10, repo, FakeSession())
34+
def test_allocate_returns_allocation():
35+
repo, session = FakeRepository([]), FakeSession()
36+
services.add_batch("batch1", "COMPLICATED-LAMP", 100, None, repo, session)
37+
result = services.allocate("o1", "COMPLICATED-LAMP", 10, repo, session)
4238
assert result == "batch1"
4339

4440

45-
def test_error_for_invalid_sku():
46-
repo = FakeRepository.for_batch("b1", "AREALSKU", 100, eta=None)
41+
def test_allocate_errors_for_invalid_sku():
42+
repo, session = FakeRepository([]), FakeSession()
43+
services.add_batch("b1", "AREALSKU", 100, None, repo, session)
44+
4745
with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"):
4846
services.allocate("o1", "NONEXISTENTSKU", 10, repo, FakeSession())
4947

5048

5149
def test_commits():
52-
repo = FakeRepository.for_batch("b1", "OMINOUS-MIRROR", 100, eta=None)
50+
repo, session = FakeRepository([]), FakeSession()
5351
session = FakeSession()
52+
services.add_batch("b1", "OMINOUS-MIRROR", 100, None, repo, session)
5453
services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session)
5554
assert session.committed is True

0 commit comments

Comments
 (0)