@@ -993,6 +993,55 @@ def test_bulk_variables(self, test_client, actions, expected_results, session):
993
993
assert response_data [key ] == value
994
994
check_last_log (session , dag_id = None , event = "bulk_variables" , logical_date = None )
995
995
996
+ @pytest .mark .parametrize (
997
+ "entity_key, entity_value, entity_description" ,
998
+ [
999
+ (
1000
+ "my_dict_var_param" ,
1001
+ {"name" : "Test Dict Param" , "id" : 123 , "active" : True },
1002
+ "A dict value (param)" ,
1003
+ ),
1004
+ ("my_list_var_param" , ["alpha" , 42 , False , {"nested" : "item param" }], "A list value (param)" ),
1005
+ ("my_string_var_param" , "plain string param" , "A plain string (param)" ),
1006
+ ],
1007
+ ids = [
1008
+ "dict_variable" ,
1009
+ "list_variable" ,
1010
+ "string_variable" ,
1011
+ ],
1012
+ )
1013
+ def test_bulk_create_entity_serialization (
1014
+ self , test_client , session , entity_key , entity_value , entity_description
1015
+ ):
1016
+ actions = {
1017
+ "actions" : [
1018
+ {
1019
+ "action" : "create" ,
1020
+ "entities" : [
1021
+ {"key" : entity_key , "value" : entity_value , "description" : entity_description },
1022
+ ],
1023
+ "action_on_existence" : "fail" ,
1024
+ }
1025
+ ]
1026
+ }
1027
+
1028
+ response = test_client .patch ("/variables" , json = actions )
1029
+ assert response .status_code == 200
1030
+
1031
+ if isinstance (entity_value , (dict , list )):
1032
+ retrieved_value_deserialized = Variable .get (entity_key , deserialize_json = True )
1033
+ assert retrieved_value_deserialized == entity_value
1034
+ retrieved_value_raw_string = Variable .get (entity_key , deserialize_json = False )
1035
+ assert retrieved_value_raw_string == json .dumps (entity_value , indent = 2 )
1036
+ else :
1037
+ retrieved_value_raw = Variable .get (entity_key , deserialize_json = False )
1038
+ assert retrieved_value_raw == str (entity_value )
1039
+
1040
+ with pytest .raises (json .JSONDecodeError ):
1041
+ Variable .get (entity_key , deserialize_json = True )
1042
+
1043
+ check_last_log (session , dag_id = None , event = "bulk_variables" , logical_date = None )
1044
+
996
1045
def test_bulk_variables_should_respond_401 (self , unauthenticated_test_client ):
997
1046
response = unauthenticated_test_client .patch ("/api/v2/variables" , json = {})
998
1047
assert response .status_code == 401
0 commit comments