410 lines
12 KiB
Python
410 lines
12 KiB
Python
import json
|
|
|
|
with open("fixtures/merger.json", "r") as f:
|
|
data = json.load(f)
|
|
|
|
db = data[0]["database"]
|
|
|
|
# 1. Update entity schema
|
|
entity_type = next(t for t in db["types"] if t["name"] == "entity")
|
|
entity_type["schemas"]["entity"]["properties"]["organization_id"] = {"type": "string"}
|
|
entity_type["fields"].append("organization_id")
|
|
entity_type["grouped_fields"]["entity"].append("organization_id")
|
|
|
|
# 2. Update person schema
|
|
person_type = next(t for t in db["types"] if t["name"] == "person")
|
|
person_type["schemas"]["person"]["properties"]["organization_id"] = {
|
|
"type": "string",
|
|
"const": "ffffffff-ffff-ffff-ffff-ffffffffffff"
|
|
}
|
|
|
|
# 3. Add the test case
|
|
test_case = {
|
|
"description": "Test organization_id syntactic sugar permutations",
|
|
"action": "merge",
|
|
"data": {
|
|
"type": "order",
|
|
"organization_id": "parent-org-id",
|
|
"customer": {
|
|
"type": "person",
|
|
"first_name": "Const",
|
|
"last_name": "Person"
|
|
},
|
|
"lines": [
|
|
{
|
|
"type": "order_line"
|
|
},
|
|
{
|
|
"type": "order_line",
|
|
"organization_id": "explicit-org-id"
|
|
}
|
|
]
|
|
},
|
|
"schema_id": "order",
|
|
"expect": {
|
|
"success": True,
|
|
"sql": [
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"organization_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" NULL,",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"organization\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"user\" (",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"person\" (",
|
|
" \"first_name\",",
|
|
" \"id\",",
|
|
" \"last_name\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" 'Const',",
|
|
" '{{uuid:person_id}}',",
|
|
" 'Person',",
|
|
" 'person'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" \"old\",",
|
|
" \"new\",",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" NULL,",
|
|
" '{",
|
|
" \"first_name\":\"Const\",",
|
|
" \"last_name\":\"Person\",",
|
|
" \"type\":\"person\"",
|
|
" }',",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"organization_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:line1_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'parent-org-id',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order_line\" (",
|
|
" \"id\",",
|
|
" \"order_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:line1_id}}',",
|
|
" '{{uuid:order_id}}',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" \"old\",",
|
|
" \"new\",",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" NULL,",
|
|
" '{",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" }',",
|
|
" '{{uuid:line1_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"organization_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:line2_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'explicit-org-id',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order_line\" (",
|
|
" \"id\",",
|
|
" \"order_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:line2_id}}',",
|
|
" '{{uuid:order_id}}',",
|
|
" 'order_line'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" \"old\",",
|
|
" \"new\",",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" NULL,",
|
|
" '{",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"explicit-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" }',",
|
|
" '{{uuid:line2_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"entity\" (",
|
|
" \"created_at\",",
|
|
" \"created_by\",",
|
|
" \"id\",",
|
|
" \"modified_at\",",
|
|
" \"modified_by\",",
|
|
" \"organization_id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" '{{uuid:order_id}}',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000',",
|
|
" 'parent-org-id',",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.\"order\" (",
|
|
" \"customer_id\",",
|
|
" \"id\",",
|
|
" \"type\"",
|
|
")",
|
|
"VALUES (",
|
|
" '{{uuid:person_id}}',",
|
|
" '{{uuid:order_id}}',",
|
|
" 'order'",
|
|
")"
|
|
],
|
|
[
|
|
"INSERT INTO agreego.change (",
|
|
" \"old\",",
|
|
" \"new\",",
|
|
" entity_id,",
|
|
" id,",
|
|
" kind,",
|
|
" modified_at,",
|
|
" modified_by",
|
|
")",
|
|
"VALUES (",
|
|
" NULL,",
|
|
" '{",
|
|
" \"customer_id\":\"{{uuid:person_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order\"",
|
|
" }',",
|
|
" '{{uuid:order_id}}',",
|
|
" '{{uuid}}',",
|
|
" 'create',",
|
|
" '{{timestamp}}',",
|
|
" '00000000-0000-0000-0000-000000000000'",
|
|
")"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"first_name\":\"Const\",",
|
|
" \"id\":\"{{uuid:person_id}}\",",
|
|
" \"last_name\":\"Person\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" },",
|
|
" \"new\":{",
|
|
" \"first_name\":\"Const\",",
|
|
" \"last_name\":\"Person\",",
|
|
" \"type\":\"person\"",
|
|
" }",
|
|
" }')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:line1_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" },",
|
|
" \"new\":{",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" }",
|
|
" }')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:line2_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"explicit-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" },",
|
|
" \"new\":{",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"explicit-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" }",
|
|
" }')"
|
|
],
|
|
[
|
|
"SELECT pg_notify('entity', '{",
|
|
" \"complete\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"customer\":{",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"first_name\":\"Const\",",
|
|
" \"id\":\"{{uuid:person_id}}\",",
|
|
" \"last_name\":\"Person\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"type\":\"person\"",
|
|
" },",
|
|
" \"customer_id\":\"{{uuid:person_id}}\",",
|
|
" \"id\":\"{{uuid:order_id}}\",",
|
|
" \"lines\":[",
|
|
" {",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:line1_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" },",
|
|
" {",
|
|
" \"created_at\":\"{{timestamp}}\",",
|
|
" \"created_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"id\":\"{{uuid:line2_id}}\",",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"order_id\":\"{{uuid:order_id}}\",",
|
|
" \"organization_id\":\"explicit-org-id\",",
|
|
" \"type\":\"order_line\"",
|
|
" }",
|
|
" ],",
|
|
" \"modified_at\":\"{{timestamp}}\",",
|
|
" \"modified_by\":\"00000000-0000-0000-0000-000000000000\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order\"",
|
|
" },",
|
|
" \"new\":{",
|
|
" \"customer_id\":\"{{uuid:person_id}}\",",
|
|
" \"organization_id\":\"parent-org-id\",",
|
|
" \"type\":\"order\"",
|
|
" }",
|
|
" }')"
|
|
]
|
|
]
|
|
}
|
|
}
|
|
|
|
data[0]["tests"].append(test_case)
|
|
|
|
with open("fixtures/merger.json", "w") as f:
|
|
json.dump(data, f, indent=2)
|
|
|