@@ -58,6 +58,60 @@ def test_number_pool_invalid_range() -> None:
5858 NodeSchema (** node_schema )
5959
6060
61+ def test_number_pool_optional () -> None :
62+ node_schema_definition : dict [str , Any ] = {
63+ "name" : "NumberAttribute" ,
64+ "namespace" : "Test" ,
65+ "attributes" : [
66+ {"name" : "name" , "kind" : "Text" , "unique" : True },
67+ {
68+ "name" : "assigned_number" ,
69+ "kind" : "NumberPool" ,
70+ "optional" : True ,
71+ "unique" : True ,
72+ "read_only" : True ,
73+ "parameters" : {"start_range" : 10 , "end_range" : 25 },
74+ },
75+ ],
76+ }
77+ node_schema = NodeSchema (** node_schema_definition )
78+
79+ schema = SchemaRoot (nodes = [node_schema ])
80+ schema_branch = SchemaBranch (cache = {})
81+ schema_branch .load_schema (schema = schema )
82+ with pytest .raises (
83+ ValidationError , match = "TestNumberAttribute.assigned_number is a NumberPool it can't be optional"
84+ ):
85+ schema_branch .process ()
86+
87+
88+ def test_number_pool_read_only () -> None :
89+ node_schema_definition : dict [str , Any ] = {
90+ "name" : "NumberAttribute" ,
91+ "namespace" : "Test" ,
92+ "attributes" : [
93+ {"name" : "name" , "kind" : "Text" , "unique" : True },
94+ {
95+ "name" : "assigned_number" ,
96+ "kind" : "NumberPool" ,
97+ "optional" : False ,
98+ "unique" : True ,
99+ "read_only" : False ,
100+ "parameters" : {"start_range" : 10 , "end_range" : 25 },
101+ },
102+ ],
103+ }
104+ node_schema = NodeSchema (** node_schema_definition )
105+
106+ schema = SchemaRoot (nodes = [node_schema ])
107+ schema_branch = SchemaBranch (cache = {})
108+ schema_branch .load_schema (schema = schema )
109+ with pytest .raises (
110+ ValidationError , match = "TestNumberAttribute.assigned_number is a NumberPool it has to be a read_only attribute"
111+ ):
112+ schema_branch .process ()
113+
114+
61115def test_number_pool_assign_from_generics () -> None :
62116 schema = SchemaRoot (generics = [SNOW_TASK ], nodes = [SNOW_INCIDENT , SNOW_REQUEST ])
63117 schema_branch = SchemaBranch (cache = {})
0 commit comments