| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 | import pathlibcurrent = pathlib.Path(__file__).parentroot = current.parentimport syssys.path.append(str(root))import assetsimport sqlmodeldef drop_database() -> None:    db = pathlib.Path("./009-reservation.db")    if db.is_file():        db.unlink()drop_database()connection = sqlmodel.create_engine("sqlite:///009-reservation.db")sqlmodel.SQLModel.metadata.create_all(connection)builder = assets.product_factory()builder.name = "Sample name"builder.author = "Simple UwU Artist"builder.description = "This is simple description"builder.barcode = "123456789012"builder.stock_count = 10product = builder.resultprint("Create first product:")print(product)print()with assets.product_loader(connection) as loader:    print("Inserting product...")    loader.store(product)    print("Inserted:")    print(product)    print()with assets.product_loader(connection) as loader:    print("Loading product to make reservation...")    target = loader.get_by_barcode("123456789012")    print("Loaded: ")    print(target)    before = target.on_stock    reservation = assets \    .reservation_factory() \    .target(target) \    .email("[email protected]") \    .result()    print(reservation)    print()with assets.reservation_loader(connection) as loader:    print("Inserting it into database...")    loader.store(reservation)    print(reservation)with assets.product_loader(connection) as loader:    print("Loading product to make reservation...")    target = loader.get_by_barcode("123456789012")    print("Loaded: ")    print(target)    reservation = assets \    .reservation_factory() \    .target(target) \    .email("[email protected]") \    .result()    print(reservation)    print()with assets.reservation_loader(connection) as loader:    print("Inserting it into database...")    loader.store(reservation)    print(reservation)with assets.product_loader(connection) as loader:    print("Loading product to check that on stock calc work...")    target = loader.get_by_barcode("123456789012")    after = target.on_stock        print("Before: " + str(before))    print("After: " + str(after))    print()    before = afterwith assets.reservation_loader(connection) as loader:    print("Loading reservation for product...")        collection = loader \    .get_by_target(target) \    .by_email("[email protected]") \    .results()        if len(collection) != 1:        print("Fail, collection:")        print(collection)        raise Exception("Collection is not propertly filtered.")        reservation = collection[0]    print("Loaded.")    print(reservation)    print()        print("Removing it from database...")    loader.drop(reservation)    print("Removed.")    print()with assets.product_loader(connection) as loader:    print("Loading product to check that on stock calc work...")    target = loader.get_by_barcode("123456789012")    after = target.on_stock        print("Before: " + str(before))    print("After: " + str(after))    print()    print("Trying to drop product...")    loader.drop(target)    print("Removed.")drop_database()
 |