44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
# setup_test_db.py
|
|
|
|
from pymongo import MongoClient
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def setup_test_db():
|
|
client = MongoClient("mongodb://localhost:27017")
|
|
db = client["test_pos_system"]
|
|
|
|
# Clear existing data
|
|
db.items.drop()
|
|
db.orders.drop()
|
|
|
|
# Insert test items
|
|
items = [
|
|
{"name": "Apple", "price": 0.5, "quantity": 100, "unit": "piece"},
|
|
{"name": "Banana", "price": 0.3, "quantity": 150, "unit": "piece"},
|
|
{"name": "Milk", "price": 2.5, "quantity": 50, "unit": "liter"},
|
|
{"name": "Bread", "price": 1.5, "quantity": 30, "unit": "loaf"}
|
|
]
|
|
result = db.items.insert_many(items)
|
|
logger.info(f"Inserted {len(result.inserted_ids)} items")
|
|
|
|
# Insert test orders
|
|
orders = [
|
|
{"customer_name": "John Doe", "items": [
|
|
"Apple", "Milk"], "total_amount": 3.0, "payment_method": "cash", "date": "2024-03-15"},
|
|
{"customer_name": "Jane Smith", "items": [
|
|
"Banana", "Bread"], "total_amount": 1.8, "payment_method": "credit_card", "date": "2024-03-16"}
|
|
]
|
|
result = db.orders.insert_many(orders)
|
|
logger.info(f"Inserted {len(result.inserted_ids)} orders")
|
|
|
|
logger.info("Test database setup complete")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
setup_test_db()
|