コード例 #1
0
ファイル: add_order.py プロジェクト: valhuber/fab-quick-start
cls = sqlalchemy_utils.functions.get_class_by_table(models.Base,
                                                    "Product",
                                                    data=None)

# Add Order - works
pre_cust = session.query(
    models.Customer).filter(models.Customer.Id == "ALFKI").one()
session.expunge(pre_cust)

# First, try one to fail
bad_order = models.Order(AmountTotal=0,
                         CustomerId="ALFKI",
                         ShipCity="Richmond",
                         EmployeeId=6,
                         Freight=1)
session.add(bad_order)

# OrderDetails - https://docs.sqlalchemy.org/en/13/orm/backref.html
bad_item1 = models.OrderDetail(ProductId=1,
                               Amount=0,
                               Quantity=1,
                               UnitPrice=18,
                               Discount=0)
bad_order.OrderDetailList.append(bad_item1)
bad_item2 = models.OrderDetail(ProductId=2,
                               Amount=0,
                               Quantity=20000,
                               UnitPrice=18,
                               Discount=0)
bad_order.OrderDetailList.append(bad_item2)
did_fail_as_expected = False
コード例 #2
0
ファイル: add_cust.py プロジェクト: valhuber/Logic-Bank
run_environment_info += "sys.path: (Python imports)\n" + sys_path + "\n"
run_environment_info += "From: " + sys.argv[0] + "\n\n"
run_environment_info += "Using Python: " + sys.version + "\n\n"
run_environment_info += "At: " + str(datetime.now()) + "\n\n"

print("\n" + run_environment_info + "\n\n")

from nw.tests import setup_db  # careful - this must follow fix-path, above
setup_db()

import nw.db.models as models
from nw.logic import session  # opens db, activates logic listener <--

# first delete, so can add
delete_cust = session.query(
    models.Customer).filter(models.Customer.Id == "$$New Cust").delete()
print("\nadd_cust, deleting: " + str(delete_cust) + "\n\n")
session.commit()

# Add a Customer - works
new_cust = models.Customer(Id="$$New Cust", Balance=0, CreditLimit=0)
session.add(new_cust)
session.commit()

verify_cust = session.query(
    models.Customer).filter(models.Customer.Id == "$$New Cust").one()

print("\nadd_cust, completed: " + str(verify_cust) + "\n\n")

assert True