|
1 | 1 | import pytest |
2 | | -from domain import model |
3 | 2 | from adapters import repository |
4 | 3 | from service_layer import services |
5 | 4 |
|
6 | 5 |
|
7 | 6 | 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 | | - |
12 | 7 | def __init__(self, batches): |
13 | 8 | self._batches = set(batches) |
14 | 9 |
|
@@ -36,20 +31,24 @@ def test_add_batch(): |
36 | 31 | assert session.committed |
37 | 32 |
|
38 | 33 |
|
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) |
42 | 38 | assert result == "batch1" |
43 | 39 |
|
44 | 40 |
|
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 | + |
47 | 45 | with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"): |
48 | 46 | services.allocate("o1", "NONEXISTENTSKU", 10, repo, FakeSession()) |
49 | 47 |
|
50 | 48 |
|
51 | 49 | def test_commits(): |
52 | | - repo = FakeRepository.for_batch("b1", "OMINOUS-MIRROR", 100, eta=None) |
| 50 | + repo, session = FakeRepository([]), FakeSession() |
53 | 51 | session = FakeSession() |
| 52 | + services.add_batch("b1", "OMINOUS-MIRROR", 100, None, repo, session) |
54 | 53 | services.allocate("o1", "OMINOUS-MIRROR", 10, repo, session) |
55 | 54 | assert session.committed is True |
0 commit comments