Add versioned event registry and transactional feature rules
Docker test deployment / test-build-deploy (push) Successful in 4m44s
Docker test deployment / test-build-deploy (push) Successful in 4m44s
This commit is contained in:
@@ -4,6 +4,7 @@ import argparse
|
||||
import http.cookiejar
|
||||
import json
|
||||
import urllib.request
|
||||
from datetime import UTC, datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from adcloud_server.settings import Settings
|
||||
@@ -19,10 +20,11 @@ opener = urllib.request.build_opener(
|
||||
)
|
||||
|
||||
|
||||
def api(path, body=None, trusted=False, method=None):
|
||||
def api(path, body=None, trusted=False, method=None, extra_headers=None):
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if trusted:
|
||||
headers["Authorization"] = "Bearer " + settings.service_token
|
||||
headers.update(extra_headers or {})
|
||||
request = urllib.request.Request(
|
||||
args.base_url.rstrip("/") + path,
|
||||
data=None if body is None else json.dumps(body).encode(),
|
||||
@@ -34,7 +36,31 @@ def api(path, body=None, trusted=False, method=None):
|
||||
|
||||
|
||||
anon = api("/v1/identity/anonymous?rotate=true", {})
|
||||
api("/v1/events", {"name": "product.view", "properties": {"sku": "demo-running-shoe"}})
|
||||
app_id = "demo-" + uuid4().hex
|
||||
application = api(
|
||||
"/v1/registry/apps", {"app_id": app_id, "name": "Identity demo"}, trusted=True
|
||||
)
|
||||
registration = "/v1/registry/apps/" + app_id + "/events/product.view/versions/1"
|
||||
management = {"X-Adcloud-Management-Key": application["management_key"]}
|
||||
api(
|
||||
registration,
|
||||
{"standard_event": "commerce.product.view", "description": "Demo product view"},
|
||||
method="PUT",
|
||||
extra_headers=management,
|
||||
)
|
||||
api(registration + "/publish", {}, extra_headers=management)
|
||||
api(
|
||||
"/v1/events",
|
||||
{
|
||||
"name": "product.view",
|
||||
"app_id": app_id,
|
||||
"event_version": 1,
|
||||
"event_id": str(uuid4()),
|
||||
"occurred_at": datetime.now(UTC).isoformat(),
|
||||
"properties": {"product_id": "demo-running-shoe"},
|
||||
},
|
||||
extra_headers={"X-Adcloud-Key": application["collection_key"]},
|
||||
)
|
||||
api(
|
||||
"/v1/users/" + anon["master_id"],
|
||||
{"attributes": {"interest": "running", "unused": None}, "tags": ["runner"]},
|
||||
|
||||
Reference in New Issue
Block a user