Skip to content

Commit 2a29db0

Browse files
committed
batches with no allocations
1 parent 3b35504 commit 2a29db0

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎orm.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from sqlalchemy import Table, MetaData, Column, Integer, String
1+
from sqlalchemy import Table, MetaData, Column, Integer, String, Date
22
from sqlalchemy.orm import mapper
33

44
import model
@@ -13,6 +13,15 @@
1313
Column('qty', Integer),
1414
)
1515

16+
batches = Table(
17+
'batches', metadata,
18+
Column('reference', String(255), primary_key=True),
19+
Column('sku', String(255), primary_key=True),
20+
Column('_purchased_qty', Integer),
21+
Column('eta', Date),
22+
)
23+
1624

1725
def start_mappers():
1826
mapper(model.OrderLine, order_lines)
27+
mapper(model.Batch, batches)

‎test_orm.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import model
2+
from datetime import date
23

34
def test_orderline_mapper_can_load_lines(session):
45
session.execute(
@@ -23,3 +24,15 @@ def test_orderline_mapper_can_save_lines(session):
2324
rows = list(session.execute('SELECT orderid, sku, qty FROM "order_lines"'))
2425
assert rows == [("order1", "DECORATIVE-WIDGET", 12)]
2526

27+
28+
29+
def test_batches(session):
30+
session.execute('INSERT INTO "batches" VALUES ("batch1", "sku1", 100, null)')
31+
session.execute('INSERT INTO "batches" VALUES ("batch2", "sku2", 200, "2011-04-11")')
32+
expected = [
33+
model.Batch("batch1", "sku1", 100, eta=None),
34+
model.Batch("batch2", "sku2", 200, eta=date(2011, 4, 11)),
35+
]
36+
37+
assert session.query(model.Batch).all() == expected
38+

0 commit comments

Comments
 (0)