11# mypy: ignore-errors
2+ from urllib .parse import urlsplit
23
34import json
45import os
910import pytest
1011import yaml
1112from jsonschema import validate
13+ from referencing import Resource
14+ from referencing .jsonschema import DRAFT6 , SchemaRegistry
1215
1316from tools .ci .tc import decision
1417
@@ -86,13 +89,24 @@ def test_verify_payload():
8689 """Verify that the decision task produces tasks with a valid payload"""
8790 from tools .ci .tc .decision import decide
8891
89- r = httpx .get ("https://community-tc.services.mozilla.com/schemas/queue/v1/create-task-request.json" )
90- r .raise_for_status ()
91- create_task_schema = r .json ()
92+ schema_urls = ["https://community-tc.services.mozilla.com/schemas/common/metaschema.json" ,
93+ "https://community-tc.services.mozilla.com/schemas/queue/v1/task-metadata.json" ,
94+ "https://community-tc.services.mozilla.com/schemas/queue/v1/task.json" ,
95+ "https://community-tc.services.mozilla.com/schemas/queue/v1/create-task-request.json" ,
96+ "https://community-tc.services.mozilla.com/references/schemas/docker-worker/v1/payload.json" ]
9297
93- r = httpx .get ("https://community-tc.services.mozilla.com/references/schemas/docker-worker/v1/payload.json" )
94- r .raise_for_status ()
95- payload_schema = r .json ()
98+ schemas = {}
99+ for schema_url in schema_urls :
100+ name = urlsplit (schema_url ).path .rsplit ("/" , 1 )[- 1 ].rsplit ("." , 1 )[0 ]
101+ r = httpx .get (schema_url )
102+ r .raise_for_status ()
103+ schemas [name ]= (schema_url , r .json ())
104+
105+
106+ registry = SchemaRegistry ()
107+ for url , schema_doc in schemas .values ():
108+ resource = Resource .from_contents (schema_doc , default_specification = DRAFT6 )
109+ registry = registry .with_resource (url , resource )
96110
97111 jobs = ["lint" ,
98112 "manifest_upload" ,
@@ -111,8 +125,12 @@ def test_verify_payload():
111125 task_id_map = decide (event )
112126 for name , (task_id , task_data ) in task_id_map .items ():
113127 try :
114- validate (instance = task_data , schema = create_task_schema )
115- validate (instance = task_data ["payload" ], schema = payload_schema )
128+ validate (instance = task_data ,
129+ schema = schemas ["create-task-request" ][1 ],
130+ registry = registry )
131+ validate (instance = task_data ["payload" ],
132+ schema = schemas ["payload" ][1 ],
133+ registry = registry )
116134 except Exception as e :
117135 print (f"Validation failed for task '{ name } ':\n { json .dumps (task_data , indent = 2 )} " )
118136 raise e
0 commit comments