#!/usr/bin/env python3 import importlib.util from pathlib import Path import unittest SCRIPT = Path(__file__).with_name("cognitive-gateway.py") SPEC = importlib.util.spec_from_file_location("gateway", SCRIPT) MODULE = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(MODULE) class CognitiveGatewayTest(unittest.TestCase): def test_dynamic_persona_routes_are_bounded_to_registered_id_shape(self): self.assertEqual(MODULE.endpoint("zy-rpc persona-status ICE-BB-0005"), ("GET", "/v1/persona/ICE-BB-0005/status")) self.assertEqual(MODULE.endpoint("zy-rpc persona-ingest ICE-BB-0003"), ("POST", "/v1/persona/ICE-BB-0003/ingest")) self.assertEqual(MODULE.endpoint("zy-rpc persona-time ICE-P-ZY001"), ("GET", "/v1/persona/ICE-P-ZY001/time-master")) def test_unknown_or_injected_persona_command_is_rejected(self): with self.assertRaisesRegex(ValueError, "ACTION_NOT_REGISTERED"): MODULE.endpoint("zy-rpc persona-status ICE-BB-0005;id") with self.assertRaisesRegex(ValueError, "ACTION_NOT_REGISTERED"): MODULE.endpoint("zy-rpc persona-status ICE-GL-SY001") if __name__ == "__main__": unittest.main()