11import pytest
22
3- from dstack ._internal .core .models .common import EntityReference
3+ from dstack ._internal .core .models .common import EntityReference , pop_null_field
44
55
66class TestEntityReferenceParse :
@@ -25,3 +25,39 @@ def test_valid(self, value, expected):
2525 def test_invalid (self , value : str ):
2626 with pytest .raises (ValueError , match = "Invalid entity reference" ):
2727 EntityReference .parse (value )
28+
29+
30+ class TestPopNullField :
31+ def test_drops_null_field_at_top_level (self ):
32+ values = {"router" : None , "backend" : "aws" }
33+ assert pop_null_field (values , "router" ) == {"backend" : "aws" }
34+
35+ def test_drops_null_field_in_nested_dict (self ):
36+ values = {"spec" : {"configuration" : {"router" : None , "backend" : "aws" }}}
37+ assert pop_null_field (values , "spec" , "configuration" , "router" ) == {
38+ "spec" : {"configuration" : {"backend" : "aws" }}
39+ }
40+
41+ def test_leaves_non_null_field_untouched (self ):
42+ values = {"configuration" : {"router" : "some-router" }}
43+ assert pop_null_field (values , "configuration" , "router" ) == {
44+ "configuration" : {"router" : "some-router" }
45+ }
46+
47+ def test_field_absent (self ):
48+ values = {"configuration" : {"backend" : "aws" }}
49+ assert pop_null_field (values , "configuration" , "router" ) == {
50+ "configuration" : {"backend" : "aws" }
51+ }
52+
53+ def test_intermediate_path_missing (self ):
54+ values = {"backend" : "aws" }
55+ assert pop_null_field (values , "configuration" , "router" ) == {"backend" : "aws" }
56+
57+ def test_intermediate_path_not_a_dict (self ):
58+ values = {"configuration" : None }
59+ assert pop_null_field (values , "configuration" , "router" ) == {"configuration" : None }
60+
61+ def test_top_level_not_a_dict (self ):
62+ values = "not-a-dict"
63+ assert pop_null_field (values , "configuration" , "router" ) == "not-a-dict"
0 commit comments