Paws the V (The Joy of Paws)

Lest see I last left off with this in my test;

not ok 10207 - Exception accessing status: Can't locate object method "status"
via package "Paws::S3::RestoreObjectOutput" at t/lib/Paws/Crawler.pm line 19.

I think I am going to fix that but first I will as a general question up on the Paws website to get a little advice in case I am going down a rabbit hole.

While I am waiting for a response this is a good opportunity to have a look at why test driven development is fun.

Right now I have that failing test and I would like to make it pass, but first, let's create the second test for the '202' case.

In Paws test when we are writing more than one test for the same call we add in a sequential number in the test name and data so it will keep the same order when the test cases are run.

So a quick rename and copy I know have


s3-restore-object.1.response
s3-restore-object.1.response.test.yml
s3-restore-object.2.response
s3-restore-object.2.response.test.ym

and a quick edit to the '2' file for the 200 response and my tests now give


ok 10205 - Call S3->RestoreObject from t/10_responses/s3-restore-object.1.response
ok 10206 - Got _request_id eq 9C4494F17CFA569D from result
not ok 10207 - Exception accessing status: Can't locate object method "status" via package
"Paws::S3::RestoreObjectOutput" at t/lib/Paws/Crawler.pm line 19.
not ok 10208 - Got status eq 200 from result
ok 10209 - Call S3->RestoreObject from t/10_responses/s3-restore-object.2.response
ok 10210 - Got _request_id eq 9C4494F17CFA569D from result
not ok 10211 - Exception accessing status: Can't locate object method "status" via package
"Paws::S3::RestoreObjectOutput" at t/lib/Paws/Crawler.pm line 19.
not ok 10212 - Got status eq 202 from result

Ok so how to fix that!

I was thinking that all I need to do was go into botocore/data/s3/2006-03-01/service-2.json and add in 'Status' to the 'boto' data for the RestoreObjectOutput object but there is a problem with that.
Presently with the way Paws is set up one can only get data for a generated class from the 'header' or 'content' of response object.
Remembering the response we where working with;


 bless( {
                 'content' => '',
                 'headers' => {
                                'server' => 'AmazonS3',
                                'date' => 'Fri, 20 Sep 2019 23:18:30 GMT',
                                'content-length' => '0',
                                'x-amz-version-id' => 'null',
                                'x-amz-id-2' => 'F/Aqv8iKKyDxL9zJdqkDtm4iBgKtL2B+AXlEiNE=',
                                'x-amz-request-id' => '9C4494F17CFA569D'
                              },
                 'status' => '202'
               }, 'Paws::Net::APIResponse' );

we have 'content' and 'headers' but no way to get the data out of that 'status' attribute and into a generated class. Looking a little closer adding that new attribute directly on the ' RestoreObjectOutput' might break the intention of the Paws as now I am putting 'response' data directly on an instance of an object.
I do see that the '_request-id' is present in “Paws::S3::RestoreObjectOutput”


package Paws::S3::RestoreObjectOutput;
  use Moose;
  has RequestCharged => (is => 'ro', isa => 'Str', traits => ['ParamInHeader'], header_name => 'x-amz-request-charged');
  has RestoreOutputPath => (is => 'ro', isa => 'Str', traits => ['ParamInHeader'], header_name => 'x-amz-restore-output-path');
  has _request_id => (is => 'ro', isa => 'Str');
1;

perhaps I can add it in as a private in the same way.

Well the first this it to find out how '_request-id' is added to the generated code. Fortunately I have been playing with Paws for a while so I looked in the templates dir where all the generated classes start out.


ack '_request_id' aws-sdk-perl/ templates/
EC2/callresult_class.tt
18: has _request_id => (is => 'ro', isa => 'Str');
default/class_documentation.tt
17:=head2 _request_id => Str
restxml/callresult_class.tt
26: has _request_id => (is => 'ro', isa => 'Str');
restjson/callresult_class.tt
21: has _request_id => (is => 'ro', isa => 'Str');
query/callresult_class.tt
18: has _request_id => (is => 'ro', isa => 'Str');
json/callresult_class.tt
13: has _request_id => (is => 'ro', isa => 'Str');

Ok that is good. I made a quick change in ' templates/restxml/callresult_class.tt'


    has _request_id => (is => 'ro', isa => 'Str');
++  has _status => (is => 'ro', isa => 'Str');

and now I have to populate it somehow and so out of the templates and back into the 'aws-sdk-perl/lib/Paws/Net' dir and have a siff about. Now I know we are calling 'Paws::Net::RestXMLResponse' so I made this change in there


    $unserialized_struct->{ _request_id } = $request_id;
++  $unserialized_struct->{ _status }     = $http_status;

and then I updated the two tests like this


--  path: Status
++  path: _status

regenerated the botocore;


carton exec builder-bin/gen_classes.pl --classes botocore/botocore/data/s3/2006-03-01/service-2.json

and then ran my tests again;


ok 10205 - Call S3->RestoreObject from t/10_responses/s3-restore-object.1.response
ok 10206 - Got _request_id eq 9C4494F17CFA569D from result
ok 10207 - Got _status eq 202 from result
ok 10208 - Call S3->RestoreObject from t/10_responses/s3-restore-object.2.response
ok 10209 - Got _request_id eq 9C4494F17CFA569D from result
ok 10210 - Got _status eq 200 from result
ok 10211 - Call S3->UploadPart from t/10_responses/s3-upload-part.response

So that works. Now I wonder if the powers that be at the Paws project will allow it as I changed a template and effected some 59 files in auto-lib.

Goodness knows how many files I will effect if add in the patch to the other templates and regenerate all the code.

henry.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations