@@ -1060,6 +1060,55 @@ def test_bulk_variables(self, test_client, actions, expected_results, session):
1060
1060
assert response_data [key ] == value
1061
1061
check_last_log (session , dag_id = None , event = "bulk_variables" , logical_date = None )
1062
1062
1063
+ @pytest .mark .parametrize (
1064
+ "entity_key, entity_value, entity_description" ,
1065
+ [
1066
+ (
1067
+ "my_dict_var_param" ,
1068
+ {"name" : "Test Dict Param" , "id" : 123 , "active" : True },
1069
+ "A dict value (param)" ,
1070
+ ),
1071
+ ("my_list_var_param" , ["alpha" , 42 , False , {"nested" : "item param" }], "A list value (param)" ),
1072
+ ("my_string_var_param" , "plain string param" , "A plain string (param)" ),
1073
+ ],
1074
+ ids = [
1075
+ "dict_variable" ,
1076
+ "list_variable" ,
1077
+ "string_variable" ,
1078
+ ],
1079
+ )
1080
+ def test_bulk_create_entity_serialization (
1081
+ self , test_client , session , entity_key , entity_value , entity_description
1082
+ ):
1083
+ actions = {
1084
+ "actions" : [
1085
+ {
1086
+ "action" : "create" ,
1087
+ "entities" : [
1088
+ {"key" : entity_key , "value" : entity_value , "description" : entity_description },
1089
+ ],
1090
+ "action_on_existence" : "fail" ,
1091
+ }
1092
+ ]
1093
+ }
1094
+
1095
+ response = test_client .patch ("/variables" , json = actions )
1096
+ assert response .status_code == 200
1097
+
1098
+ if isinstance (entity_value , (dict , list )):
1099
+ retrieved_value_deserialized = Variable .get (entity_key , deserialize_json = True )
1100
+ assert retrieved_value_deserialized == entity_value
1101
+ retrieved_value_raw_string = Variable .get (entity_key , deserialize_json = False )
1102
+ assert retrieved_value_raw_string == json .dumps (entity_value , indent = 2 )
1103
+ else :
1104
+ retrieved_value_raw = Variable .get (entity_key , deserialize_json = False )
1105
+ assert retrieved_value_raw == str (entity_value )
1106
+
1107
+ with pytest .raises (json .JSONDecodeError ):
1108
+ Variable .get (entity_key , deserialize_json = True )
1109
+
1110
+ check_last_log (session , dag_id = None , event = "bulk_variables" , logical_date = None )
1111
+
1063
1112
def test_bulk_variables_should_respond_401 (self , unauthenticated_test_client ):
1064
1113
response = unauthenticated_test_client .patch ("/variables" , json = {})
1065
1114
assert response .status_code == 401
0 commit comments