Reorganize testing infrastructure and fix Oracle cursor loop syntax
Major changes: - Fix cursor loop syntax in 04_import_comenzi.sql using BULK COLLECT pattern - Remove obsolete test scripts (apply_fix.py, check_*.py, debug_functions.py, test_*.py) - Add comprehensive README.md files for api/ and api/tests/ directories - Keep only essential testing scripts (final_validation.py, test_syntax.py) - Update PRD.md with latest project status 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
114
test_import_comanda.py
Normal file
114
test_import_comanda.py
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script for updated IMPORT_COMENZI package
|
||||
Tests the fixed FOR LOOP issue
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import oracledb
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv('/mnt/e/proiecte/vending/gomag-vending/api/.env')
|
||||
|
||||
def test_import_comanda():
|
||||
"""Test the updated importa_comanda function"""
|
||||
|
||||
# Connection parameters
|
||||
user = os.environ['ORACLE_USER']
|
||||
password = os.environ['ORACLE_PASSWORD']
|
||||
dsn = os.environ['ORACLE_DSN']
|
||||
|
||||
try:
|
||||
# Connect to Oracle
|
||||
print("🔗 Conectare la Oracle...")
|
||||
with oracledb.connect(user=user, password=password, dsn=dsn) as conn:
|
||||
with conn.cursor() as cursor:
|
||||
|
||||
print("\n📋 Test 1: Recompilare Package PACK_IMPORT_COMENZI")
|
||||
|
||||
# Read and execute the updated package
|
||||
with open('/mnt/e/proiecte/vending/gomag-vending/api/database-scripts/04_import_comenzi.sql', 'r') as f:
|
||||
sql_script = f.read()
|
||||
|
||||
cursor.execute(sql_script)
|
||||
print("✅ Package recompiled successfully")
|
||||
|
||||
print("\n📋 Test 2: Import comandă completă cu multiple articole")
|
||||
|
||||
# Test data - comandă cu 2 articole (CAFE100 + SET01)
|
||||
test_json = '''[
|
||||
{"sku": "CAFE100", "cantitate": 2, "pret": 50.00},
|
||||
{"sku": "SET01", "cantitate": 1, "pret": 120.00}
|
||||
]'''
|
||||
|
||||
test_partner_id = 878 # Partner din teste anterioare
|
||||
test_order_num = "TEST-MULTI-" + str(int(os.time()))
|
||||
|
||||
# Call importa_comanda
|
||||
cursor.execute("""
|
||||
SELECT PACK_IMPORT_COMENZI.importa_comanda_web(
|
||||
:p_nr_comanda_ext,
|
||||
SYSDATE,
|
||||
:p_id_partener,
|
||||
:p_json_articole,
|
||||
NULL,
|
||||
'Test import multiple articole'
|
||||
) AS id_comanda FROM dual
|
||||
""", {
|
||||
'p_nr_comanda_ext': test_order_num,
|
||||
'p_id_partener': test_partner_id,
|
||||
'p_json_articole': test_json
|
||||
})
|
||||
|
||||
result = cursor.fetchone()
|
||||
if result and result[0] > 0:
|
||||
comanda_id = result[0]
|
||||
print(f"✅ Comandă importată cu succes! ID: {comanda_id}")
|
||||
|
||||
# Verifică articolele adăugate
|
||||
cursor.execute("""
|
||||
SELECT ca.id_articol, na.codmat, ca.cantitate, ca.pret
|
||||
FROM comenzi_articole ca
|
||||
JOIN nom_articole na ON na.id_articol = ca.id_articol
|
||||
WHERE ca.id_comanda = :id_comanda
|
||||
ORDER BY ca.id_articol
|
||||
""", {'id_comanda': comanda_id})
|
||||
|
||||
articole = cursor.fetchall()
|
||||
print(f"\n📦 Articole în comandă (Total: {len(articole)}):")
|
||||
for art in articole:
|
||||
print(f" • CODMAT: {art[1]}, Cantitate: {art[2]}, Preț: {art[3]}")
|
||||
|
||||
# Expected:
|
||||
# - CAFFE (din CAFE100: 2 * 10 = 20 bucăți)
|
||||
# - CAFE-SET (din SET01: 2 * 60% = 72.00)
|
||||
# - FILT-SET (din SET01: 1 * 40% = 48.00)
|
||||
print("\n🎯 Expected:")
|
||||
print(" • CAFFE: 20 bucăți (reîmpachetare 2*10)")
|
||||
print(" • CAFE-SET: 2 bucăți, preț 36.00 (120*60%/2)")
|
||||
print(" • FILT-SET: 1 bucăți, preț 48.00 (120*40%/1)")
|
||||
|
||||
else:
|
||||
print("❌ Import eșuat")
|
||||
# Check for errors
|
||||
cursor.execute("SELECT PACK_IMPORT_COMENZI.get_last_error() FROM dual")
|
||||
error = cursor.fetchone()
|
||||
if error:
|
||||
print(f"Eroare: {error[0]}")
|
||||
|
||||
conn.commit()
|
||||
print("\n✅ Test completed!")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Eroare: {e}")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
os.time = lambda: int(time.time())
|
||||
success = test_import_comanda()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user