Bugzilla – Attachment 172011 Details for
Bug 37963
Improve error handling and testing of ERM eUsage SUSHI
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37963: (QA follow-up) Tidy
Bug-37963-QA-follow-up-Tidy.patch (text/plain), 8.36 KB, created by
Nick Clemens (kidclamp)
on 2024-09-26 18:38:06 UTC
(
hide
)
Description:
Bug 37963: (QA follow-up) Tidy
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-09-26 18:38:06 UTC
Size:
8.36 KB
patch
obsolete
>From 5d9bf78e6d36eebe170ad8c88219615c13852b7f Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 26 Sep 2024 18:34:35 +0000 >Subject: [PATCH] Bug 37963: (QA follow-up) Tidy > >--- > Koha/ERM/EUsage/UsageDataProvider.pm | 8 +- > .../Koha/BackgroundJob/ErmSushiHarvester.t | 128 ++++++++++++------ > 2 files changed, 88 insertions(+), 48 deletions(-) > >diff --git a/Koha/ERM/EUsage/UsageDataProvider.pm b/Koha/ERM/EUsage/UsageDataProvider.pm >index b13a7609255..f6d9ef7b92a 100644 >--- a/Koha/ERM/EUsage/UsageDataProvider.pm >+++ b/Koha/ERM/EUsage/UsageDataProvider.pm >@@ -180,7 +180,7 @@ sub harvest_sushi { > $ua->agent( 'Koha/' . Koha::version() ); > my $response = $ua->simple_request($request); > >- my $result = decode_json( $response->decoded_content ); >+ my $result = decode_json( $response->decoded_content ); > > if ( $response->code >= 400 ) { > >@@ -459,10 +459,10 @@ sub _sushi_errors { > my ( $self, $decoded_response ) = @_; > > my $severity = $decoded_response->{Severity} // $decoded_response->{severity}; >- my $message = $decoded_response->{Message} // $decoded_response->{message}; >- my $code = $decoded_response->{Code} // $decoded_response->{code}; >+ my $message = $decoded_response->{Message} // $decoded_response->{message}; >+ my $code = $decoded_response->{Code} // $decoded_response->{code}; > >- if ( $severity ) { >+ if ($severity) { > $self->{job_callbacks}->{add_message_callback}->( > { > type => 'error', >diff --git a/t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t b/t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t >index f0e736006c3..d6a7440eaef 100755 >--- a/t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t >+++ b/t/db_dependent/Koha/BackgroundJob/ErmSushiHarvester.t >@@ -24,7 +24,7 @@ use Koha::BackgroundJobs; > use Koha::BackgroundJob::ErmSushiHarvester; > > use File::Basename qw( dirname ); >-use JSON qw( decode_json ); >+use JSON qw( decode_json ); > use File::Slurp; > > use t::lib::Mocks; >@@ -75,28 +75,42 @@ subtest 'invalid_date_arguments() tests' => sub { > $schema->storage->txn_begin; > > my $ua = Test::MockModule->new('LWP::UserAgent'); >- $ua->mock('simple_request', sub { >- return mock_sushi_response({'error'=>'invalid_date_arguments'}); >- }); >+ $ua->mock( >+ 'simple_request', >+ sub { >+ return mock_sushi_response( { 'error' => 'invalid_date_arguments' } ); >+ } >+ ); > > my $usage_data_provider = $builder->build_object( > { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); > > my $job_args = { >- ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, >- report_type => 'TR_J1', >- begin_date => '2023-08-01', >- end_date => '2023-09-30', >- ud_provider_name => $usage_data_provider->name, >- }; >+ ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, >+ report_type => 'TR_J1', >+ begin_date => '2023-08-01', >+ end_date => '2023-09-30', >+ ud_provider_name => $usage_data_provider->name, >+ }; > > my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); >- my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >- $job->process( $job_args ); >- >- is( $job->{messages}[0]->{message}, decode_json($sushi_response_errors->{invalid_date_arguments})->{severity} . ' - ' . decode_json($sushi_response_errors->{invalid_date_arguments})->{message},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); >- is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); >- is( $job->{messages}[0]->{code},decode_json($sushi_response_errors->{invalid_date_arguments})->{code},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); >+ my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >+ $job->process($job_args); >+ >+ is( >+ $job->{messages}[0]->{message}, >+ decode_json( $sushi_response_errors->{invalid_date_arguments} )->{severity} . ' - ' >+ . decode_json( $sushi_response_errors->{invalid_date_arguments} )->{message}, >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); >+ is( >+ $job->{messages}[0]->{type}, 'error', >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); >+ is( >+ $job->{messages}[0]->{code}, decode_json( $sushi_response_errors->{invalid_date_arguments} )->{code}, >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); > > $schema->storage->txn_rollback; > }; >@@ -108,28 +122,42 @@ subtest 'invalid_api_key() tests' => sub { > $schema->storage->txn_begin; > > my $ua = Test::MockModule->new('LWP::UserAgent'); >- $ua->mock('simple_request', sub { >- return mock_sushi_response({'error'=>'invalid_api_key', 'code'=>401}); >- }); >+ $ua->mock( >+ 'simple_request', >+ sub { >+ return mock_sushi_response( { 'error' => 'invalid_api_key', 'code' => 401 } ); >+ } >+ ); > > my $usage_data_provider = $builder->build_object( > { class => 'Koha::ERM::EUsage::UsageDataProviders', value => { name => 'TestProvider' } } ); > > my $job_args = { >- ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, >- report_type => 'TR_J1', >- begin_date => '2023-08-01', >- end_date => '2023-09-30', >- ud_provider_name => $usage_data_provider->name, >- }; >+ ud_provider_id => $usage_data_provider->erm_usage_data_provider_id, >+ report_type => 'TR_J1', >+ begin_date => '2023-08-01', >+ end_date => '2023-09-30', >+ ud_provider_name => $usage_data_provider->name, >+ }; > > my $job_id = Koha::BackgroundJob::ErmSushiHarvester->new->enqueue($job_args); >- my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >- $job->process( $job_args ); >- >- is( $job->{messages}[0]->{message}, decode_json($sushi_response_errors->{invalid_api_key})->{Severity} . ' - ' . decode_json($sushi_response_errors->{invalid_api_key})->{Message},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); >- is( $job->{messages}[0]->{type},'error','SUSHI error invalid_date_arguments is stored on job messages correctly' ); >- is( $job->{messages}[0]->{code},decode_json($sushi_response_errors->{invalid_api_key})->{Code},'SUSHI error invalid_date_arguments is stored on job messages correctly' ); >+ my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >+ $job->process($job_args); >+ >+ is( >+ $job->{messages}[0]->{message}, >+ decode_json( $sushi_response_errors->{invalid_api_key} )->{Severity} . ' - ' >+ . decode_json( $sushi_response_errors->{invalid_api_key} )->{Message}, >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); >+ is( >+ $job->{messages}[0]->{type}, 'error', >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); >+ is( >+ $job->{messages}[0]->{code}, decode_json( $sushi_response_errors->{invalid_api_key} )->{Code}, >+ 'SUSHI error invalid_date_arguments is stored on job messages correctly' >+ ); > > $schema->storage->txn_rollback; > }; >@@ -138,16 +166,28 @@ sub mock_sushi_response { > my ($args) = @_; > my $response = Test::MockObject->new(); > >- $response->mock('code', sub { >- return $args->{code} || 200; >- }); >- $response->mock('is_error', sub { >- return 0; >- }); >- $response->mock('is_redirect', sub { >- return 0; >- }); >- $response->mock('decoded_content', sub { >- return $sushi_response_errors->{$args->{error}}; >- }); >-} >\ No newline at end of file >+ $response->mock( >+ 'code', >+ sub { >+ return $args->{code} || 200; >+ } >+ ); >+ $response->mock( >+ 'is_error', >+ sub { >+ return 0; >+ } >+ ); >+ $response->mock( >+ 'is_redirect', >+ sub { >+ return 0; >+ } >+ ); >+ $response->mock( >+ 'decoded_content', >+ sub { >+ return $sushi_response_errors->{ $args->{error} }; >+ } >+ ); >+} >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37963
:
171769
|
171770
|
171771
|
171772
|
171887
|
171888
|
171889
|
171890
|
172007
|
172008
|
172009
|
172010
| 172011