fix: adapt autotest to updated service APIs
This commit is contained in:
@@ -4,7 +4,10 @@
|
||||
ручные операции + сценарии + переключения + краевые случаи.
|
||||
Запуск: python3 tests/test_user_simulation.py
|
||||
"""
|
||||
import time, requests, json, sys
|
||||
import time, requests, json, sys, pytest
|
||||
|
||||
if __name__ != "__main__":
|
||||
pytest.skip("live test against deployed atest service; run this file directly", allow_module_level=True)
|
||||
|
||||
BASE = "https://atest.pythonk8s.dev.nubes.ru"
|
||||
PASS = FAIL = 0
|
||||
@@ -31,6 +34,14 @@ def post(path, data, cookies=None, code=200):
|
||||
assert r.status_code == code, f"POST {path}: {r.status_code} {r.text[:100]}"
|
||||
return r.json() if r.text.strip() else {}
|
||||
|
||||
def operation_id(service_id, operation, cookies=None):
|
||||
operations = get(f"/api/operations/{service_id}", cookies)
|
||||
match = next((item for item in operations.get("operations", [])
|
||||
if item.get("operation") == operation), None)
|
||||
if not match:
|
||||
raise RuntimeError(f"Operation {operation!r} not found for service {service_id}")
|
||||
return match["svcOperationId"]
|
||||
|
||||
def poll(op_uid, cookies=None, timeout=15):
|
||||
deadline = time.time() + timeout
|
||||
while time.time() < deadline:
|
||||
@@ -42,7 +53,7 @@ def poll(op_uid, cookies=None, timeout=15):
|
||||
|
||||
def create_instance(sid, name=None, cookies=None):
|
||||
r = post("/api/test",
|
||||
{"serviceId": sid, "operation": "create", "svcOperationId": 18,
|
||||
{"serviceId": sid, "operation": "create", "svcOperationId": operation_id(sid, "create", cookies),
|
||||
"params": {}, "displayName": name or f"autotest-user-{sid}"},
|
||||
cookies)
|
||||
return r["opUid"], r.get("instanceUid")
|
||||
@@ -249,7 +260,7 @@ try:
|
||||
# 9.1 Создать PostgreSQL
|
||||
pg_name = f"autotest-pg-{int(time.time())}"
|
||||
r = post("/api/test",
|
||||
{"serviceId": 90, "operation": "create", "svcOperationId": 19,
|
||||
{"serviceId": 90, "operation": "create", "svcOperationId": operation_id(90, "create"),
|
||||
"params": {}, "displayName": pg_name})
|
||||
pg_op = r["opUid"]
|
||||
pg_uid = r.get("instanceUid")
|
||||
@@ -260,7 +271,7 @@ try:
|
||||
# 9.2 Создать пользователя
|
||||
user_name = f"testuser_{int(time.time()) % 10000}"
|
||||
r = post("/api/test",
|
||||
{"serviceId": 90, "operation": "create_user", "svcOperationId": 241,
|
||||
{"serviceId": 90, "operation": "create_user", "svcOperationId": operation_id(90, "create_user"),
|
||||
"instanceUid": pg_uid,
|
||||
"params": {"733": user_name, "740": "app_user", "1096": "false"}})
|
||||
user_op = r["opUid"]
|
||||
@@ -270,7 +281,7 @@ try:
|
||||
# 9.3 Создать базу данных
|
||||
db_name = f"testdb_{int(time.time()) % 10000}"
|
||||
r = post("/api/test",
|
||||
{"serviceId": 90, "operation": "create_database", "svcOperationId": 245,
|
||||
{"serviceId": 90, "operation": "create_database", "svcOperationId": operation_id(90, "create_database"),
|
||||
"instanceUid": pg_uid,
|
||||
"params": {"741": db_name, "742": user_name}})
|
||||
db_op = r["opUid"]
|
||||
@@ -279,7 +290,7 @@ try:
|
||||
|
||||
# 9.4 Удалить PostgreSQL
|
||||
r = post("/api/test",
|
||||
{"serviceId": 90, "operation": "delete", "svcOperationId": 20,
|
||||
{"serviceId": 90, "operation": "delete", "svcOperationId": operation_id(90, "delete"),
|
||||
"instanceUid": pg_uid, "params": {}})
|
||||
del_op = r["opUid"]
|
||||
result = poll(del_op)
|
||||
|
||||
Reference in New Issue
Block a user