test: +PostgreSQL сценарий — create_user, create_database (тесты 9, 10)
This commit is contained in:
@@ -22,7 +22,7 @@ def log(ok, msg):
|
|||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def get(path, cookies=None, code=200):
|
def get(path, cookies=None, code=200):
|
||||||
r = requests.get(f"{BASE}{path}", cookies=cookies or cookie(), timeout=15)
|
r = requests.get(f"{BASE}{path}", cookies=cookies or cookie(), timeout=30)
|
||||||
assert r.status_code == code, f"GET {path}: {r.status_code}"
|
assert r.status_code == code, f"GET {path}: {r.status_code}"
|
||||||
return r.json() if r.text.strip() else {}
|
return r.json() if r.text.strip() else {}
|
||||||
|
|
||||||
@@ -241,6 +241,85 @@ r = requests.post(f"{BASE}/api/scenario/run",
|
|||||||
log(r.status_code == 404, f"run definition_id=99999 -> 404")
|
log(r.status_code == 404, f"run definition_id=99999 -> 404")
|
||||||
|
|
||||||
|
|
||||||
|
print(f"\n{'='*60}")
|
||||||
|
print("ТЕСТ 9: PostgreSQL — create + create_user + create_database + delete")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 9.1 Создать PostgreSQL
|
||||||
|
pg_name = f"autotest-pg-{int(time.time())}"
|
||||||
|
r = post("/api/test",
|
||||||
|
{"serviceId": 90, "operation": "create", "svcOperationId": 19,
|
||||||
|
"params": {}, "displayName": pg_name})
|
||||||
|
pg_op = r["opUid"]
|
||||||
|
pg_uid = r.get("instanceUid")
|
||||||
|
result = poll(pg_op, timeout=15)
|
||||||
|
log(result.get("status") == "OK", f"create PostgreSQL -> {pg_uid[:8] if pg_uid else '?'}")
|
||||||
|
|
||||||
|
if pg_uid:
|
||||||
|
# 9.2 Создать пользователя
|
||||||
|
user_name = f"testuser_{int(time.time()) % 10000}"
|
||||||
|
r = post("/api/test",
|
||||||
|
{"serviceId": 90, "operation": "create_user", "svcOperationId": 241,
|
||||||
|
"instanceUid": pg_uid,
|
||||||
|
"params": {"733": user_name, "740": "app_user", "1096": "false"}})
|
||||||
|
user_op = r["opUid"]
|
||||||
|
result = poll(user_op)
|
||||||
|
log(result.get("status") == "OK", f"create_user '{user_name}' -> {result.get('status')}")
|
||||||
|
|
||||||
|
# 9.3 Создать базу данных
|
||||||
|
db_name = f"testdb_{int(time.time()) % 10000}"
|
||||||
|
r = post("/api/test",
|
||||||
|
{"serviceId": 90, "operation": "create_database", "svcOperationId": 245,
|
||||||
|
"instanceUid": pg_uid,
|
||||||
|
"params": {"741": db_name, "742": user_name}})
|
||||||
|
db_op = r["opUid"]
|
||||||
|
result = poll(db_op)
|
||||||
|
log(result.get("status") == "OK", f"create_database '{db_name}' -> {result.get('status')}")
|
||||||
|
|
||||||
|
# 9.4 Удалить PostgreSQL
|
||||||
|
r = post("/api/test",
|
||||||
|
{"serviceId": 90, "operation": "delete", "svcOperationId": 20,
|
||||||
|
"instanceUid": pg_uid, "params": {}})
|
||||||
|
del_op = r["opUid"]
|
||||||
|
result = poll(del_op)
|
||||||
|
log(result.get("status") == "OK", f"delete PostgreSQL -> {result.get('status')}")
|
||||||
|
except Exception as e:
|
||||||
|
log(False, f"PostgreSQL test: {str(e)[:80]}")
|
||||||
|
|
||||||
|
|
||||||
|
print(f"\n{'='*60}")
|
||||||
|
print("ТЕСТ 10: Сценарий PostgreSQL — create -> create_user -> create_database -> delete")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
try:
|
||||||
|
pg_scenario_name = f"pg-scenario-{int(time.time())}"
|
||||||
|
pg_steps = [
|
||||||
|
{"service_id": 90, "operation": "create", "params": {}, "output": "pg"},
|
||||||
|
{"service_id": 90, "operation": "create_user", "instance_ref": "pg",
|
||||||
|
"params": {"username": "scenario_user", "role": "app_user", "mtlsAccess": "false"}},
|
||||||
|
{"service_id": 90, "operation": "create_database", "instance_ref": "pg",
|
||||||
|
"params": {"dbName": "scenario_db", "dbOwner": "scenario_user"}},
|
||||||
|
{"service_id": 90, "operation": "delete", "instance_ref": "pg", "params": {}},
|
||||||
|
]
|
||||||
|
r = requests.post(f"{BASE}/api/scenario/definitions",
|
||||||
|
json={"name": pg_scenario_name, "steps": pg_steps},
|
||||||
|
cookies=cookie(), timeout=10)
|
||||||
|
pg_def = r.json()
|
||||||
|
log("id" in pg_def, f"создан сценарий PostgreSQL (id={pg_def.get('id')})")
|
||||||
|
|
||||||
|
if "id" in pg_def:
|
||||||
|
pg_run_id = run_scenario(pg_def["id"])
|
||||||
|
pg_result = poll_scenario(pg_run_id, timeout=30)
|
||||||
|
log(pg_result.get("status") == "OK",
|
||||||
|
f"запуск PG сценария: {pg_result.get('status')} (шаг {pg_result.get('current_step')}/{pg_result.get('total_steps')})")
|
||||||
|
|
||||||
|
requests.delete(f"{BASE}/api/scenario/definitions/{pg_def['id']}",
|
||||||
|
cookies=cookie(), timeout=10)
|
||||||
|
except Exception as e:
|
||||||
|
log(False, f"PG scenario: {str(e)[:80]}")
|
||||||
|
|
||||||
|
|
||||||
print(f"\n{'='*60}")
|
print(f"\n{'='*60}")
|
||||||
print(f"ИТОГО: PASS={PASS} FAIL={FAIL}")
|
print(f"ИТОГО: PASS={PASS} FAIL={FAIL}")
|
||||||
print(f"{'='*60}")
|
print(f"{'='*60}")
|
||||||
|
|||||||
Reference in New Issue
Block a user