@@ -253,6 +253,70 @@ def test_gen_ai_configuration_round_trip(self):
253253 self .assertEqual (original .max_concurrency , restored .max_concurrency )
254254 self .assertEqual (original .enable_tracing , restored .enable_tracing )
255255
256+ def test_version_not_in_json_when_none (self ):
257+ """Tests that Version key is omitted from JSON when version is None."""
258+ config = GenAiConfiguration (
259+ name = "TestGenAi" ,
260+ identifier = "test-gen-ai-1" ,
261+ collection = "Documents" ,
262+ connection_string_name = "my-connection" ,
263+ prompt = "Test prompt" ,
264+ gen_ai_transformation = GenAiTransformation (script = "ai.genContext(ctx);" ),
265+ update_script = "this.Summary = $result;" ,
266+ sample_object = '{"summary": "test"}' ,
267+ )
268+ json_data = config .to_json ()
269+ self .assertNotIn ("Version" , json_data )
270+
271+ def test_version_in_json_when_set (self ):
272+ """Tests that Version key is included in JSON when version has a value."""
273+ config = GenAiConfiguration (
274+ name = "TestGenAi" ,
275+ identifier = "test-gen-ai-1" ,
276+ collection = "Documents" ,
277+ connection_string_name = "my-connection" ,
278+ prompt = "Test prompt" ,
279+ gen_ai_transformation = GenAiTransformation (script = "ai.genContext(ctx);" ),
280+ update_script = "this.Summary = $result;" ,
281+ sample_object = '{"summary": "test"}' ,
282+ version = 1 ,
283+ )
284+ json_data = config .to_json ()
285+ self .assertEqual (1 , json_data ["Version" ])
286+
287+ def test_version_round_trip (self ):
288+ """Tests that version survives serialization -> deserialization."""
289+ config = GenAiConfiguration (
290+ name = "TestGenAi" ,
291+ identifier = "test-gen-ai-1" ,
292+ collection = "Documents" ,
293+ connection_string_name = "my-connection" ,
294+ prompt = "Test prompt" ,
295+ gen_ai_transformation = GenAiTransformation (script = "ai.genContext(ctx);" ),
296+ update_script = "this.Summary = $result;" ,
297+ sample_object = '{"summary": "test"}' ,
298+ version = 1 ,
299+ )
300+ json_data = config .to_json ()
301+ restored = GenAiConfiguration .from_json (json_data )
302+ self .assertEqual (1 , restored .version )
303+
304+ def test_version_none_round_trip (self ):
305+ """Tests that None version survives serialization -> deserialization."""
306+ config = GenAiConfiguration (
307+ name = "TestGenAi" ,
308+ identifier = "test-gen-ai-1" ,
309+ collection = "Documents" ,
310+ connection_string_name = "my-connection" ,
311+ prompt = "Test prompt" ,
312+ gen_ai_transformation = GenAiTransformation (script = "ai.genContext(ctx);" ),
313+ update_script = "this.Summary = $result;" ,
314+ sample_object = '{"summary": "test"}' ,
315+ )
316+ json_data = config .to_json ()
317+ restored = GenAiConfiguration .from_json (json_data )
318+ self .assertIsNone (restored .version )
319+
256320
257321class TestGenAiTransformation (unittest .TestCase ):
258322 """Tests for GenAiTransformation. No server required."""
0 commit comments