Files
gomag-vending/api/tests/test_pack_json_direct.py
Marius Mutu 52454a5925 Complete P1-004: Testing Manual Packages and reorganize test files
- Complete manual testing of all Oracle PL/SQL packages
- Document 75% success rate (3/4 components passing)
- Move all test scripts from api/ to api/tests/ subdirectory
- Update P1-004 story with comprehensive test results
- Identify external dependency blocking full order import
- Mark Phase 1 as 95% complete, ready for Phase 2

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-10 01:25:27 +03:00

110 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Test PACK_JSON with direct Oracle calls
"""
import oracledb
import os
from dotenv import load_dotenv
# Load environment
load_dotenv('.env')
# Oracle configuration
user = os.environ['ORACLE_USER']
password = os.environ['ORACLE_PASSWORD']
dsn = os.environ['ORACLE_DSN']
# Initialize Oracle client
try:
instantclient_path = os.environ.get('INSTANTCLIENTPATH', '/opt/oracle/instantclient_23_9')
oracledb.init_oracle_client(lib_dir=instantclient_path)
except Exception as e:
pass
def test_pack_json_simple():
"""Test PACK_JSON with hardcoded JSON"""
print("🧪 Testing PACK_JSON with simple JSON...")
try:
with oracledb.connect(user=user, password=password, dsn=dsn) as conn:
with conn.cursor() as cur:
# Test with simple hardcoded JSON
print("Testing parse_array...")
cur.execute("""
SELECT * FROM TABLE(PACK_JSON.parse_array('[{"sku":"TEST01","cantitate":2,"pret":10.5}]'))
""")
results = cur.fetchall()
print(f"Parse array results: {len(results)} items")
for result in results:
json_item = result[0]
print(f"JSON item: {json_item}")
# Test get functions
cur.execute(f"SELECT PACK_JSON.get_string('{json_item}', 'sku') FROM DUAL")
sku = cur.fetchone()[0]
print(f"SKU: {sku}")
except Exception as e:
print(f"❌ PACK_JSON test failed: {e}")
def test_pack_comenzi_direct():
"""Test PACK_COMENZI.adauga_comanda directly to check for CASE issues"""
print("\n🧪 Testing PACK_COMENZI.adauga_comanda directly...")
try:
with oracledb.connect(user=user, password=password, dsn=dsn) as conn:
with conn.cursor() as cur:
partner_id = -1 # Known test partner
# Test direct call to adauga_comanda
print("Testing PACK_COMENZI.adauga_comanda...")
try:
# Create a simple cursor to test the call
cur.execute("""
DECLARE
v_id_comanda NUMBER;
BEGIN
PACK_COMENZI.adauga_comanda(
V_NR_COMANDA => 'TEST-DIRECT-001',
V_DATA_COMANDA => SYSDATE,
V_ID => :partner_id,
V_DATA_LIVRARE => SYSDATE + 1,
V_PROC_DISCOUNT => 0,
V_INTERNA => 0,
V_ID_UTIL => -3,
V_ID_SECTIE => 1,
V_ID_ADRESA_FACTURARE => NULL,
V_ID_ADRESA_LIVRARE => NULL,
V_ID_CODCLIENT => NULL,
V_COMANDA_EXTERNA => 'TEST-DIRECT-001',
V_ID_CTR => NULL,
V_ID_COMANDA => v_id_comanda
);
:result := v_id_comanda;
END;
""", {'partner_id': partner_id, 'result': cur.var(oracledb.NUMBER)})
result_var = cur.getvar('result')
print(f"✅ PACK_COMENZI.adauga_comanda succeeded: ID = {result_var}")
except Exception as e:
print(f"❌ PACK_COMENZI.adauga_comanda failed: {e}")
except Exception as e:
print(f"❌ Direct test failed: {e}")
def main():
print("🔍 Direct PACK_JSON and PACK_COMENZI Tests")
print("=" * 50)
test_pack_json_simple()
test_pack_comenzi_direct()
if __name__ == "__main__":
main()