fixed up the testing function
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000">
|
<OTA_ResRetrieveRS xmlns="http://www.opentravel.org/OTA/2003/05" Version="7.000">
|
||||||
<ReservationsList>
|
<ReservationsList>
|
||||||
<HotelReservation CreateDateTime="2025-09-29T11:03:09.401052+00:00" ResStatus="Requested" RoomStayReservation="true">
|
<HotelReservation CreateDateTime="2025-09-29T12:08:55.313540+00:00" ResStatus="Requested" RoomStayReservation="true">
|
||||||
<UniqueID Type="14" ID="e084006b-ae83-4e4d-b2f5-074118cdb3b1"/>
|
<UniqueID Type="14" ID="e084006b-ae83-4e4d-b2f5-074118cdb3b1"/>
|
||||||
<RoomStays>
|
<RoomStays>
|
||||||
<RoomStay>
|
<RoomStay>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from .alpinebits_guestrequests import ResGuest, RoomStay
|
from .alpinebits_guestrequests import ResGuest, RoomStay
|
||||||
from .generated import alpinebits as ab
|
from .generated import alpinebits as ab
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
@@ -20,20 +21,40 @@ from .simplified_access import (
|
|||||||
|
|
||||||
# DB and config
|
# DB and config
|
||||||
from .db import (
|
from .db import (
|
||||||
|
Base,
|
||||||
Customer as DBCustomer,
|
Customer as DBCustomer,
|
||||||
Reservation as DBReservation,
|
Reservation as DBReservation,
|
||||||
HashedCustomer,
|
HashedCustomer,
|
||||||
get_async_session,
|
get_database_url,
|
||||||
)
|
)
|
||||||
from .config_loader import load_config
|
from .config_loader import load_config
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from alpine_bits_python import db
|
from alpine_bits_python import db
|
||||||
|
|
||||||
|
# Configure logging
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def setup_db(config):
|
||||||
|
DATABASE_URL = get_database_url(config)
|
||||||
|
engine = create_async_engine(DATABASE_URL, echo=True)
|
||||||
|
AsyncSessionLocal = async_sessionmaker(engine, expire_on_commit=False)
|
||||||
|
|
||||||
|
# Create tables
|
||||||
|
async with engine.begin() as conn:
|
||||||
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
_LOGGER.info("Database tables checked/created at startup.")
|
||||||
|
|
||||||
|
return engine, AsyncSessionLocal
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
print("🚀 Starting AlpineBits XML generation script...")
|
print("🚀 Starting AlpineBits XML generation script...")
|
||||||
@@ -58,12 +79,14 @@ async def main():
|
|||||||
print(f"Deleted existing SQLite DB at {db_path} for clean testing.")
|
print(f"Deleted existing SQLite DB at {db_path} for clean testing.")
|
||||||
|
|
||||||
# # Ensure DB schema is created (async)
|
# # Ensure DB schema is created (async)
|
||||||
from .db import engine, Base
|
|
||||||
|
|
||||||
|
engine, AsyncSessionLocal = await setup_db(config)
|
||||||
|
|
||||||
async with engine.begin() as conn:
|
async with engine.begin() as conn:
|
||||||
await conn.run_sync(Base.metadata.create_all)
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
|
||||||
async for db in get_async_session():
|
async with AsyncSessionLocal() as db:
|
||||||
# Load data from JSON file
|
# Load data from JSON file
|
||||||
json_path = os.path.join(
|
json_path = os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
|
|||||||
Reference in New Issue
Block a user