1- # Copyright (c) 2019, IRIS-HEP
1+ # Copyright (c) 2019-2025 , IRIS-HEP
22# All rights reserved.
33#
44# Redistribution and use in source and binary forms, with or without
@@ -76,6 +76,7 @@ def test_post_good_query_with_params(self, mocker):
7676
7777 select_stmt = "(call ResultTTree (call Select (call SelectMany (call EventDataset (list 'localds://did_01')" # noqa: E501
7878
79+ # Note we will ignore any image sent in the request!
7980 response = client .post ("/servicex/generated-code" , json = {
8081 "transformer_image" : "sslhep/servicex_func_adl_xaod_transformer:develop" ,
8182 "code" : select_stmt
@@ -92,6 +93,7 @@ def test_post_good_query_with_params(self, mocker):
9293 print ("Zip File: " , zip_file )
9394
9495 assert response .status_code == 200
96+ assert transformer_image == 'foo/bar:latest'
9597 check_zip_file (zip_file , 2 )
9698 # Capture the temporary directory that was generated
9799 cache_dir = mock_ast_translator .generate_code .call_args [1 ]['cache_path' ]
@@ -137,6 +139,53 @@ def test_post_good_query_without_params(self, mocker):
137139 print ("Zip File: " , zip_file )
138140
139141 assert response .status_code == 200
142+ assert transformer_image == 'sslhep/servicex_func_adl_xaod_transformer:develop'
143+ check_zip_file (zip_file , 2 )
144+ # Capture the temporary directory that was generated
145+ cache_dir = mock_ast_translator .generate_code .call_args [1 ]['cache_path' ]
146+ mock_ast_translator .generate_code .assert_called_with (select_stmt ,
147+ cache_path = cache_dir )
148+
149+ def test_post_good_query_with_params_and_image (self , mocker ):
150+ """Produce code for a simple good query"""
151+
152+ with TemporaryDirectory () as tempdir , \
153+ open (os .path .join (tempdir , "baz.txt" ), 'w' ), \
154+ open (os .path .join (tempdir , "foo.txt" ), 'w' ):
155+
156+ mock_ast_translator = mocker .Mock ()
157+ mock_ast_translator .generate_code = mocker .Mock (
158+ return_value = GeneratedFileResult (hash = "1234" , output_dir = tempdir ,
159+ image = 'sslhep/servicex_func_adl_xaod_transformer:develop' )
160+ )
161+
162+ config = {
163+ 'TARGET_BACKEND' : 'uproot' ,
164+ 'TRANSFORMER_SCIENCE_IMAGE' : "foo/bar:latest"
165+ }
166+ app = create_app (config , provided_translator = mock_ast_translator )
167+ client = app .test_client ()
168+
169+ print (app .config )
170+
171+ select_stmt = "(call ResultTTree (call Select (call SelectMany (call EventDataset (list 'localds://did_01')" # noqa: E501
172+
173+ response = client .post ("/servicex/generated-code" , json = {
174+ "code" : select_stmt
175+ })
176+
177+ boundary = response .data [2 :34 ].decode ('utf-8' )
178+ content_type = f"multipart/form-data; boundary={ boundary } "
179+ decoder_parts = decoder .MultipartDecoder (response .data , content_type )
180+
181+ transformer_image = str (decoder_parts .parts [0 ].content , 'utf-8' )
182+ zip_file = decoder_parts .parts [3 ].content
183+
184+ print ("Transformer Image: " , transformer_image )
185+ print ("Zip File: " , zip_file )
186+
187+ assert response .status_code == 200
188+ assert transformer_image == 'sslhep/servicex_func_adl_xaod_transformer:develop'
140189 check_zip_file (zip_file , 2 )
141190 # Capture the temporary directory that was generated
142191 cache_dir = mock_ast_translator .generate_code .call_args [1 ]['cache_path' ]
0 commit comments