@@ -41,48 +41,50 @@ def response_data(response, operation):
4141 return data
4242
4343
44- def feature_step (scenario , collection_name , feature_id , kind ):
45- steps = scenario .get (collection_name )
46- if not isinstance (steps , list ):
47- fail (f" { collection_name } must be a list" )
48-
49- for index , step in enumerate (steps ):
50- if not isinstance (step , dict ):
51- fail (f"{ collection_name } [{ index } ] must be an object" )
52- if step .get ("featureId" ) != feature_id :
44+ def sdk_feature_call (scenario , feature_id ):
45+ feature_calls = scenario .get ("sdkFeatureCalls" )
46+ if not isinstance (feature_calls , list ):
47+ fail ("sdkFeatureCalls must be a list" )
48+
49+ for index , feature_call in enumerate (feature_calls ):
50+ if not isinstance (feature_call , dict ):
51+ fail (f"sdkFeatureCalls [{ index } ] must be an object" )
52+ if feature_call .get ("featureId" ) != feature_id :
5353 continue
54- if step .get ("kind" ) != kind :
55- fail (f"{ collection_name } [{ index } ] must have kind { kind !r } " )
56- return step
54+ if feature_call .get ("kind" ) != "sdk-feature-call" :
55+ fail (f"sdkFeatureCalls [{ index } ] must have kind 'sdk-feature-call' " )
56+ return feature_call
5757
58- fail (f"scenario has no { collection_name } step for feature { feature_id !r} " )
58+ fail (f"scenario has no SDK feature call for feature { feature_id !r} " )
5959
6060
61- def file_count (scenario ):
62- feature = feature_step (scenario , "preparations" , "createTusAssembly" , "feature-call " )
63- input_values = list ( feature [ "input" ]. values () )
64- if len (input_values ) != 1 :
65- fail (f" { feature [ 'featureId' ] } expected exactly one input value " )
61+ def upload_tus_assembly_input (scenario ):
62+ feature_call = sdk_feature_call (scenario , "uploadTusAssembly " )
63+ input_values = feature_call . get ( "input" )
64+ if not isinstance (input_values , dict ) :
65+ fail ("sdkFeatureCalls.uploadTusAssembly.input must be an object " )
6666
67- return input_values [ 0 ]
67+ return input_values
6868
6969
70- def scenario_bytes (scenario ):
71- source = scenario ["upload" ]["source" ]
72- if source ["kind" ] != "bytes" :
73- fail (f"unsupported scenario source kind { source ['kind' ]!r} " )
74- if source ["encoding" ] != "utf8" :
75- fail (f"unsupported scenario source encoding { source ['encoding' ]!r} " )
76- return source ["value" ].encode ("utf-8" )
70+ def scenario_bytes (upload ):
71+ content = upload .get ("content" )
72+ if not isinstance (content , str ):
73+ fail ("sdkFeatureCalls.uploadTusAssembly.input.upload.content must be a string" )
7774
75+ return content .encode ("utf-8" )
76+
77+
78+ def upload_config (input_values ):
79+ upload = input_values .get ("upload" )
80+ if not isinstance (upload , dict ):
81+ fail ("sdkFeatureCalls.uploadTusAssembly.input.upload must be an object" )
7882
79- def upload_config (scenario ):
80- upload = scenario ["upload" ]
8183 return {
82- "content" : scenario_bytes (scenario ),
83- "fieldname" : upload ["fieldName " ],
84- "filename" : upload ["fileName " ],
85- "user_meta" : upload .get ("userMeta " ) or {},
84+ "content" : scenario_bytes (upload ),
85+ "fieldname" : upload ["fieldname " ],
86+ "filename" : upload ["filename " ],
87+ "user_meta" : upload .get ("user_meta " ) or {},
8688 }
8789
8890
@@ -113,9 +115,10 @@ def main():
113115 service = endpoint ,
114116 )
115117
116- upload = upload_config (scenario )
118+ input_values = upload_tus_assembly_input (scenario )
119+ upload = upload_config (input_values )
117120 completed_assembly , upload_url = client .upload_tus_assembly (
118- file_count ( scenario ) ,
121+ input_values [ " file_count" ] ,
119122 upload ["content" ],
120123 upload ["fieldname" ],
121124 upload ["filename" ],
0 commit comments