@@ -314,11 +314,12 @@ import model #<1>
314
314
metadata = MetaData()
315
315
316
316
order_lines = Table( #<2>
317
- 'order_lines', metadata,
318
- Column('id', Integer, primary_key=True, autoincrement=True),
319
- Column('sku', String(255)),
320
- Column('qty', Integer, nullable=False),
321
- Column('orderid', String(255)),
317
+ "order_lines",
318
+ metadata,
319
+ Column("id", Integer, primary_key=True, autoincrement=True),
320
+ Column("sku", String(255)),
321
+ Column("qty", Integer, nullable=False),
322
+ Column("orderid", String(255)),
322
323
)
323
324
324
325
...
@@ -364,7 +365,7 @@ tests for it, as in the following example:
364
365
----
365
366
def test_orderline_mapper_can_load_lines(session): #<1>
366
367
session.execute(
367
- ' INSERT INTO order_lines (orderid, sku, qty) VALUES '
368
+ " INSERT INTO order_lines (orderid, sku, qty) VALUES "
368
369
'("order1", "RED-CHAIR", 12),'
369
370
'("order1", "RED-TABLE", 13),'
370
371
'("order2", "BLUE-LIPSTICK", 14)'
@@ -525,7 +526,6 @@ Here's what an abstract base class (ABC) for our repository would look like:
525
526
[source,python]
526
527
----
527
528
class AbstractRepository(abc.ABC):
528
-
529
529
@abc.abstractmethod #<1>
530
530
def add(self, batch: model.Batch):
531
531
raise NotImplementedError #<2>
@@ -659,10 +659,10 @@ def test_repository_can_save_a_batch(session):
659
659
repo.add(batch) #<1>
660
660
session.commit() #<2>
661
661
662
- rows = list( session.execute(
663
- 'SELECT reference, sku, _purchased_quantity, eta FROM "batches"' #<3>
664
- ))
665
- assert rows == [("batch1", "RUSTY-SOAPDISH", 100, None)]
662
+ rows = session.execute( #<3>
663
+ 'SELECT reference, sku, _purchased_quantity, eta FROM "batches"'
664
+ )
665
+ assert list( rows) == [("batch1", "RUSTY-SOAPDISH", 100, None)]
666
666
----
667
667
====
668
668
@@ -688,15 +688,16 @@ complex:
688
688
----
689
689
def insert_order_line(session):
690
690
session.execute( #<1>
691
- ' INSERT INTO order_lines (orderid, sku, qty)'
691
+ " INSERT INTO order_lines (orderid, sku, qty)"
692
692
' VALUES ("order1", "GENERIC-SOFA", 12)'
693
693
)
694
694
[[orderline_id]] = session.execute(
695
- ' SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku' ,
696
- dict(orderid="order1", sku="GENERIC-SOFA")
695
+ " SELECT id FROM order_lines WHERE orderid=:orderid AND sku=:sku" ,
696
+ dict(orderid="order1", sku="GENERIC-SOFA"),
697
697
)
698
698
return orderline_id
699
699
700
+
700
701
def insert_batch(session, batch_id): #<2>
701
702
...
702
703
@@ -752,7 +753,6 @@ You end up with something like this:
752
753
[source,python]
753
754
----
754
755
class SqlAlchemyRepository(AbstractRepository):
755
-
756
756
def __init__(self, session):
757
757
self.session = session
758
758
0 commit comments