1616import java .util .logging .Logger ;
1717import java .util .stream .Collectors ;
1818import java .util .stream .Stream ;
19+ import software .amazon .smithy .aws .traits .auth .SigV4Trait ;
1920import software .amazon .smithy .codegen .core .CodegenException ;
2021import software .amazon .smithy .codegen .core .Symbol ;
2122import software .amazon .smithy .model .Model ;
@@ -188,12 +189,14 @@ private void generateRequestTest(OperationShape operation, HttpRequestTestCase t
188189 endpoint_uri="https://$L/$L",
189190 transport = $T(),
190191 retry_strategy=SimpleRetryStrategy(max_attempts=1),
192+ ${C|}
191193 )
192194 """ ,
193195 CodegenUtils .getConfigSymbol (context .settings ()),
194196 host ,
195197 path ,
196- REQUEST_TEST_ASYNC_HTTP_CLIENT_SYMBOL );
198+ REQUEST_TEST_ASYNC_HTTP_CLIENT_SYMBOL ,
199+ (Runnable ) this ::writeSigV4TestConfig );
197200 }));
198201
199202 // Generate the input using the expected shape and params
@@ -418,6 +421,16 @@ private void compareMediaBlob(HttpMessageTestCase testCase, PythonWriter writer)
418421 """ );
419422 return ;
420423 }
424+ if (contentType .equals ("application/x-www-form-urlencoded" )) {
425+ writer .addStdlibImport ("urllib.parse" , "parse_qsl" );
426+ writer .write ("""
427+ actual_params = sorted(parse_qsl(actual_body_content.decode(), keep_blank_values=True))
428+ expected_params = sorted(parse_qsl(expected_body_content.decode(), keep_blank_values=True))
429+ assert actual_params == expected_params
430+
431+ """ );
432+ return ;
433+ }
421434 writer .write ("assert actual_body_content == expected_body_content\n " );
422435 }
423436
@@ -437,13 +450,15 @@ private void generateResponseTest(OperationShape operation, HttpResponseTestCase
437450 headers=$J,
438451 body=b$S,
439452 ),
453+ ${C|}
440454 )
441455 """ ,
442456 CodegenUtils .getConfigSymbol (context .settings ()),
443457 RESPONSE_TEST_ASYNC_HTTP_CLIENT_SYMBOL ,
444458 testCase .getCode (),
445459 CodegenUtils .toTuples (testCase .getHeaders ()),
446- testCase .getBody ().filter (body -> !body .isEmpty ()).orElse ("" ));
460+ testCase .getBody ().filter (body -> !body .isEmpty ()).orElse ("" ),
461+ (Runnable ) this ::writeSigV4TestConfig );
447462 }));
448463 // Create an empty input object to pass
449464 var inputShape = model .expectShape (operation .getInputShape (), StructureShape .class );
@@ -490,13 +505,15 @@ private void generateErrorResponseTest(
490505 headers=$J,
491506 body=b$S,
492507 ),
508+ ${C|}
493509 )
494510 """ ,
495511 CodegenUtils .getConfigSymbol (context .settings ()),
496512 RESPONSE_TEST_ASYNC_HTTP_CLIENT_SYMBOL ,
497513 testCase .getCode (),
498514 CodegenUtils .toTuples (testCase .getHeaders ()),
499- testCase .getBody ().orElse ("" ));
515+ testCase .getBody ().orElse ("" ),
516+ (Runnable ) this ::writeSigV4TestConfig );
500517 }));
501518 // Create an empty input object to pass
502519 var inputShape = model .expectShape (operation .getInputShape (), StructureShape .class );
@@ -607,6 +624,19 @@ private void writeClientBlock(
607624 });
608625 }
609626
627+ private void writeSigV4TestConfig () {
628+ if (!service .hasTrait (SigV4Trait .class )) {
629+ return ;
630+ }
631+ writer .addImport ("smithy_aws_core.identity" , "StaticCredentialsResolver" );
632+ writer .write ("""
633+ region="us-east-1",
634+ aws_access_key_id="test-access-key-id",
635+ aws_secret_access_key="test-secret-access-key",
636+ aws_credentials_identity_resolver=StaticCredentialsResolver(),
637+ """ );
638+ }
639+
610640 private void writeUtilStubs (Symbol serviceSymbol ) {
611641 LOGGER .fine (String .format ("Writing utility stubs for %s : %s" , serviceSymbol .getName (), protocol .getName ()));
612642 writer .addDependency (SmithyPythonDependency .SMITHY_CORE );
0 commit comments