|
1 | 1 | # pylint: disable=protected-access |
| 2 | +from datetime import date |
| 3 | +import pytest |
2 | 4 | from allocation.domain import model |
3 | 5 | from allocation.adapters import repository |
4 | | -from allocation import django_model |
5 | 6 |
|
6 | 7 |
|
7 | | -def test_repository_can_save_a_batch(session): |
| 8 | +@pytest.fixture |
| 9 | +def django_models(django_db_setup): |
| 10 | + from djangoproject.alloc import models |
| 11 | + |
| 12 | + return models |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.django_db |
| 16 | +def test_repository_can_save_a_batch(django_models): |
8 | 17 | batch = model.Batch("batch1", "RUSTY-SOAPDISH", 100, eta=date(2011, 12, 25)) |
9 | 18 |
|
10 | | - repo = repository.SqlAlchemyRepository(session) |
| 19 | + repo = repository.DjangoRepository() |
11 | 20 | repo.add(batch) |
12 | 21 |
|
13 | | - [saved_batch] = django_model.Batch.objects.all() |
| 22 | + [saved_batch] = django_models.Batch.objects.all() |
14 | 23 | assert saved_batch.reference == batch.reference |
15 | 24 | assert saved_batch.sku == batch.sku |
16 | | - assert saved_batch.qty == batch.qty |
| 25 | + assert saved_batch.qty == batch._purchased_quantity |
17 | 26 | assert saved_batch.eta == batch.eta |
18 | 27 |
|
19 | 28 |
|
20 | | -def test_repository_can_retrieve_a_batch_with_allocations(session): |
| 29 | +@pytest.mark.skip("foo") |
| 30 | +@pytest.mark.django_db |
| 31 | +def test_repository_can_retrieve_a_batch_with_allocations(django_models): |
21 | 32 | sku = "PONY-STATUE" |
22 | | - line = django_model.OrderLine.objects.create(orderid="order1", sku=sku, qty=12) |
23 | | - django_model.Batch.objects.create(reference="batch1", sku=sku, qty=100, eta=None) |
24 | | - django_model.Batch.objects.create(reference="batch2", sku=sku, qty=100, eta=None) |
25 | | - django_model.Allocation.objects.create( |
| 33 | + d_line = django_models.OrderLine.objects.create(orderid="order1", sku=sku, qty=12) |
| 34 | + d_batch1 = django_models.Batch.objects.create( |
| 35 | + reference="batch1", sku=sku, qty=100, eta=None |
| 36 | + ) |
| 37 | + d_batch2 = django_models.Batch.objects.create( |
26 | 38 | reference="batch2", sku=sku, qty=100, eta=None |
27 | 39 | ) |
| 40 | + django_models.Allocation.objects.create(line=d_line, batch=d_batch1) |
28 | 41 |
|
29 | | - repo = repository.SqlAlchemyRepository(session) |
| 42 | + repo = repository.DjangoRepository() |
30 | 43 | retrieved = repo.get("batch1") |
31 | 44 |
|
32 | 45 | expected = model.Batch("batch1", sku, 100, eta=None) |
|
0 commit comments