Bug 19440: Identify overlimit problems in XISBN tests

This patch makes C4::XISBN::get_xisbns() return an errors hashref
including information of the failing fetches from xisbn services.

It tackles the situation of XISBN, which in some cases returns 'overlimit'
errors.

The patch makes the relevant functions check if the response->{stat} string
is 'ok' and returns the string in $errors otherwise.

This only happens when in list context. This allows to fix the randomly failing
tests while keeping the current behaviour.

All this code should be rewritten. It does the job bug doesn't have problems handling
or reoprting. This is just a band aid.

To test:
- Make sure
 k$ prove t/db_dependent/XISBN.t
=> SUCCESS :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit e908742418)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomas Cohen Arazi 2017-10-09 15:36:41 -03:00 committed by Fridolin Somers
parent c94e660652
commit aaf0d3dc47
2 changed files with 13 additions and 6 deletions

View File

@ -88,7 +88,7 @@ sub _get_biblio_from_xisbn {
sub get_xisbns {
my ( $isbn ) = @_;
my ($response,$thing_response,$xisbn_response,$syndetics_response);
my ($response,$thing_response,$xisbn_response,$syndetics_response,$errors);
# THINGISBN
if ( C4::Context->preference('ThingISBN') ) {
my $url = "http://www.librarything.com/api/thingISBN/".$isbn;
@ -114,6 +114,8 @@ sub get_xisbns {
unless ($reached_limit) {
$xisbn_response = _get_url($url,'xisbn');
}
$errors->{xisbn} = $xisbn_response->{ stat }
if $xisbn_response->{ stat } ne 'ok';
}
$response->{isbn} = [ @{ $xisbn_response->{isbn} or [] }, @{ $syndetics_response->{isbn} or [] }, @{ $thing_response->{isbn} or [] } ];
@ -129,7 +131,12 @@ sub get_xisbns {
my $xbiblio= _get_biblio_from_xisbn($response_data->{content});
push @xisbns, $xbiblio if $xbiblio;
}
return \@xisbns;
if ( wantarray ) {
return (\@xisbns, $errors);
}
else {
return \@xisbns;
}
}
sub _get_url {

View File

@ -25,7 +25,7 @@ $dbh->{AutoCommit} = 0;
my $search_module = new Test::MockModule('C4::Search');
$search_module->mock('SimpleSearch', \&Mock_SimpleSearch );
my $errors;
my $context = C4::Context->new;
my ( $biblionumber_tag, $biblionumber_subfield ) =
@ -73,10 +73,10 @@ t::lib::Mocks::mock_preference( 'ThingISBN', 0 );
t::lib::Mocks::mock_preference( 'XISBN', 1 );
my $results_xisbn;
eval { $results_xisbn = C4::XISBN::get_xisbns($isbn1); };
eval { ($results_xisbn, $errors) = C4::XISBN::get_xisbns($isbn1); };
SKIP: {
skip "Problem retrieving XISBN", 1
unless $@ eq '';
skip "Problem retrieving XISBN (" . $errors->{xisbn} . ")", 1
if $errors->{xisbn};
is( $results_xisbn->[0]->{biblionumber},
$biblionumber3,
"Gets correct biblionumber from a book with a similar isbn using XISBN." );