verify_test_data.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """Verify test data script"""
  2. import psycopg2
  3. DB_CONFIG = {
  4. "host": "192.168.3.143",
  5. "port": 5432,
  6. "database": "dataops",
  7. "user": "postgres",
  8. "password": "dataOps",
  9. }
  10. def main():
  11. conn = psycopg2.connect(**DB_CONFIG)
  12. cur = conn.cursor()
  13. print("=" * 70)
  14. print("Database Test Data Verification")
  15. print("=" * 70)
  16. # data_products
  17. print("\n[data_products]")
  18. cur.execute(
  19. "SELECT id, product_name, target_table, record_count, column_count, status "
  20. "FROM public.data_products ORDER BY id"
  21. )
  22. for row in cur.fetchall():
  23. print(
  24. f" ID={row[0]}, name={row[1]}, table={row[2]}, "
  25. f"records={row[3]}, columns={row[4]}, status={row[5]}"
  26. )
  27. # test_sales_data
  28. print("\n[test_sales_data - first 5 rows]")
  29. cur.execute(
  30. "SELECT order_id, order_date, customer_name, product_name, quantity, total_amount "
  31. "FROM public.test_sales_data LIMIT 5"
  32. )
  33. for row in cur.fetchall():
  34. print(
  35. f" order={row[0]}, date={row[1]}, customer={row[2]}, "
  36. f"product={row[3]}, qty={row[4]}, amount={row[5]}"
  37. )
  38. # test_user_statistics
  39. print("\n[test_user_statistics - first 5 rows]")
  40. cur.execute(
  41. "SELECT user_id, username, login_count, total_orders, total_amount, user_level "
  42. "FROM public.test_user_statistics LIMIT 5"
  43. )
  44. for row in cur.fetchall():
  45. print(
  46. f" user={row[0]}, name={row[1]}, logins={row[2]}, "
  47. f"orders={row[3]}, amount={row[4]}, level={row[5]}"
  48. )
  49. # test_product_inventory
  50. print("\n[test_product_inventory - first 5 rows]")
  51. cur.execute(
  52. "SELECT sku, product_name, brand, current_stock, stock_status, selling_price "
  53. "FROM public.test_product_inventory LIMIT 5"
  54. )
  55. for row in cur.fetchall():
  56. print(
  57. f" sku={row[0]}, product={row[1]}, brand={row[2]}, "
  58. f"stock={row[3]}, status={row[4]}, price={row[5]}"
  59. )
  60. print("\n" + "=" * 70)
  61. print("Verification complete!")
  62. print("=" * 70)
  63. cur.close()
  64. conn.close()
  65. if __name__ == "__main__":
  66. main()