feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -362,6 +362,88 @@ class AssessmentContractTest(unittest.TestCase):
|
||||
self.assertIn("employer", result_description)
|
||||
self.assertIn("404", self.paths["/api/v1/me/assessment-attempts/{attempt_id}"]["get"]["responses"])
|
||||
|
||||
def test_signal_operation_is_bounded_private_and_separate_from_results(self) -> None:
|
||||
operation = self.paths[
|
||||
"/api/v1/me/assessment-attempts/{attempt_id}/signals"
|
||||
]["post"]
|
||||
self.assertEqual(operation["operationId"], "RecordMyAssessmentAttemptSignals")
|
||||
self.assertIn("sessionCsrf", operation["security"][0])
|
||||
self.assertIn("IdempotencyKey", [
|
||||
parameter.get("$ref", "").rsplit("/", 1)[-1]
|
||||
for parameter in operation["parameters"]
|
||||
])
|
||||
self.assertIn("413", operation["responses"])
|
||||
self.assertIn("429", operation["responses"])
|
||||
self.assertIn("32 KiB", operation["description"])
|
||||
self.assertIn("10,000", operation["description"])
|
||||
|
||||
request_schema = resolve_schema(
|
||||
operation["requestBody"]["content"]["application/json"]["schema"],
|
||||
self.schemas,
|
||||
)
|
||||
self.assertFalse(request_schema.get("additionalProperties", True))
|
||||
self.assertEqual(request_schema["required"], ["events"])
|
||||
self.assertEqual(request_schema["properties"]["events"]["maxItems"], 50)
|
||||
event_schema = resolve_schema(
|
||||
request_schema["properties"]["events"]["items"], self.schemas
|
||||
)
|
||||
variants = [resolve_schema(branch, self.schemas) for branch in event_schema["oneOf"]]
|
||||
self.assertEqual(
|
||||
{tuple(sorted(variant["properties"])) for variant in variants},
|
||||
{
|
||||
("duration_ms", "item_instance_id", "kind", "occurred_at"),
|
||||
("item_instance_id", "kind", "occurred_at", "size_bytes"),
|
||||
("item_instance_id", "kind", "occurred_at"),
|
||||
},
|
||||
)
|
||||
for variant in variants:
|
||||
self.assertFalse(variant.get("additionalProperties", True))
|
||||
receipt_schema = resolve_schema(
|
||||
operation["responses"]["200"]["content"]["application/json"]["schema"],
|
||||
self.schemas,
|
||||
)
|
||||
self.assertEqual(
|
||||
set(receipt_schema["properties"]), {"status", "accepted_events", "received_at"}
|
||||
)
|
||||
self.assertTrue(
|
||||
{"answer", "answer_text", "clipboard", "content", "score", "threshold"}.isdisjoint(
|
||||
receipt_schema["properties"]
|
||||
)
|
||||
)
|
||||
|
||||
def schema_references(value: Any) -> set[str]:
|
||||
if isinstance(value, dict):
|
||||
references = set()
|
||||
reference = value.get("$ref", "")
|
||||
if reference.startswith("#/components/schemas/"):
|
||||
references.add(reference.rsplit("/", 1)[-1])
|
||||
for child in value.values():
|
||||
references.update(schema_references(child))
|
||||
return references
|
||||
if isinstance(value, list):
|
||||
references: set[str] = set()
|
||||
for child in value:
|
||||
references.update(schema_references(child))
|
||||
return references
|
||||
return set()
|
||||
|
||||
attempt_result_operations = (
|
||||
self.paths["/api/v1/me/assessment-attempts/{attempt_id}"],
|
||||
self.paths["/api/v1/me/assessment-attempts/{attempt_id}/result"],
|
||||
)
|
||||
for path_item in attempt_result_operations:
|
||||
self.assertFalse(
|
||||
any(name.startswith("AssessmentSignal") for name in schema_references(path_item)),
|
||||
"attempt and result responses must remain independent of signal storage",
|
||||
)
|
||||
for path, path_item in self.paths.items():
|
||||
if not path.startswith("/api/v1/organizations"):
|
||||
continue
|
||||
self.assertFalse(
|
||||
any(name.startswith("AssessmentSignal") for name in schema_references(path_item)),
|
||||
f"organization operation {path} must not reach assessment signal schemas",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user