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>
This commit is contained in:
162
api/tests/test_final_success.py
Normal file
162
api/tests/test_final_success.py
Normal file
@@ -0,0 +1,162 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Final test for complete end-to-end order import
|
||||
"""
|
||||
|
||||
import oracledb
|
||||
import os
|
||||
import json
|
||||
from datetime import datetime
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv('.env')
|
||||
|
||||
user = os.environ['ORACLE_USER']
|
||||
password = os.environ['ORACLE_PASSWORD']
|
||||
dsn = os.environ['ORACLE_DSN']
|
||||
|
||||
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_gaseste_articol_direct():
|
||||
"""Test gaseste_articol_roa directly to see if it works"""
|
||||
print("🔍 Testing gaseste_articol_roa directly...")
|
||||
|
||||
try:
|
||||
with oracledb.connect(user=user, password=password, dsn=dsn) as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
||||
# Test CAFE100 mapping directly with same params as order
|
||||
cur.execute("""
|
||||
SELECT * FROM TABLE(PACK_IMPORT_COMENZI.gaseste_articol_roa('CAFE100', 25.0, 1))
|
||||
""")
|
||||
|
||||
results = cur.fetchall()
|
||||
print(f"CAFE100 results: {len(results)} items")
|
||||
for result in results:
|
||||
print(f" - ID: {result[0]}, CODMAT: {result[1]}, Qty: {result[2]}, Price: {result[3]}, Success: {result[4]}")
|
||||
if result[4] == 1:
|
||||
print(" ✅ Article mapping successful")
|
||||
return True
|
||||
else:
|
||||
print(f" ❌ Article mapping failed: {result[5]}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Direct test failed: {e}")
|
||||
return False
|
||||
|
||||
def test_complete_workflow():
|
||||
"""Test the complete workflow with minimal complexity"""
|
||||
print("\n🧪 Testing complete workflow...")
|
||||
|
||||
try:
|
||||
with oracledb.connect(user=user, password=password, dsn=dsn) as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
||||
# Create partner
|
||||
import time
|
||||
unique_suffix = int(time.time()) % 10000
|
||||
partner_name = f'Final Test Partner {unique_suffix}'
|
||||
|
||||
partner_var = cur.var(oracledb.NUMBER)
|
||||
cur.execute("""
|
||||
DECLARE
|
||||
v_partner_id NUMBER;
|
||||
BEGIN
|
||||
v_partner_id := PACK_IMPORT_PARTENERI.cauta_sau_creeaza_partener(
|
||||
NULL,
|
||||
:partner_name,
|
||||
'JUD:Bucuresti;BUCURESTI;Str. Final;1',
|
||||
'0722000000',
|
||||
'final@test.com'
|
||||
);
|
||||
:result := v_partner_id;
|
||||
END;
|
||||
""", {'partner_name': partner_name, 'result': partner_var})
|
||||
|
||||
partner_id = partner_var.getvalue()
|
||||
print(f"✅ Partner created: ID {partner_id}")
|
||||
|
||||
# Try with CAFE100 (ARTICOLE_TERTI mapping) which we know works
|
||||
simple_json = '[{"sku": "CAFE100", "cantitate": 1, "pret": 25.0}]'
|
||||
order_number = f'FINAL-TEST-{unique_suffix}'
|
||||
|
||||
print(f"Testing order: {order_number}")
|
||||
print(f"Articles: {simple_json}")
|
||||
|
||||
result_var = cur.var(oracledb.NUMBER)
|
||||
cur.execute("""
|
||||
DECLARE
|
||||
v_order_id NUMBER;
|
||||
BEGIN
|
||||
v_order_id := PACK_IMPORT_COMENZI.importa_comanda(
|
||||
:order_num,
|
||||
SYSDATE,
|
||||
:partner_id,
|
||||
:articles_json,
|
||||
NULL,
|
||||
NULL,
|
||||
'Final P1-004 test - simple CAFE100'
|
||||
);
|
||||
:result := v_order_id;
|
||||
END;
|
||||
""", {
|
||||
'order_num': order_number,
|
||||
'partner_id': partner_id,
|
||||
'articles_json': simple_json,
|
||||
'result': result_var
|
||||
})
|
||||
|
||||
order_id = result_var.getvalue()
|
||||
print(f"Order import result: {order_id}")
|
||||
|
||||
# Check for errors
|
||||
cur.execute("SELECT PACK_IMPORT_COMENZI.get_last_error FROM DUAL")
|
||||
error = cur.fetchone()[0]
|
||||
|
||||
if order_id > 0:
|
||||
print(f"🎉 SUCCESS! Order imported with ID: {order_id}")
|
||||
|
||||
# Quick verification
|
||||
cur.execute("SELECT numar, data_comanda FROM comenzi WHERE id_comanda = :id", {'id': order_id})
|
||||
order_info = cur.fetchone()
|
||||
if order_info:
|
||||
print(f"Order verified: {order_info[0]} on {order_info[1]}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ Failed: {error}")
|
||||
return False
|
||||
|
||||
conn.commit()
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Complete workflow failed: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("🎯 FINAL P1-004 SUCCESS TEST")
|
||||
print("=" * 50)
|
||||
|
||||
# Test article mapping first
|
||||
article_ok = test_gaseste_articol_direct()
|
||||
|
||||
if article_ok:
|
||||
# Test complete workflow
|
||||
success = test_complete_workflow()
|
||||
|
||||
if success:
|
||||
print("\n🎉 P1-004 FINAL SUCCESS!")
|
||||
print("✅ All package components working")
|
||||
print("✅ End-to-end order import functional")
|
||||
print("🚀 Phase 1 COMPLETED - Ready for Phase 2!")
|
||||
else:
|
||||
print("\n⚠️ Partial success - components work individually")
|
||||
else:
|
||||
print("\n❌ Article mapping issues need resolution")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user