From: Jane Sandberg Date: Thu, 19 Dec 2019 23:54:18 +0000 (-0800) Subject: LP1857060: Tests for ISBNs with 979 prefix X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=3831d36cfdad71bb9afbff03ac3ce9eb3ec0f499;p=evergreen%2Ftadl.git LP1857060: Tests for ISBNs with 979 prefix Also includes a slight tweak to the Amazon AddedContent code to avoid attempting to convert 979 ISBNs to ISBN-10s (which is not possible). Signed-off-by: Jane Sandberg Signed-off-by: Jason Boyer Signed-off-by: Galen Charlton --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Amazon.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Amazon.pm index 9e2c13c595..0cf9d1a689 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Amazon.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Amazon.pm @@ -65,9 +65,18 @@ sub fetch_content { # returns the HTTP response object from the URL fetch sub fetch_response { - my( $self, $page, $key ) = @_; + my( $self, $page, $raw_key ) = @_; my $uname = $self->userid; + my $key = $self->normalize_key($raw_key); + return 0 if $key eq 0; + my $url = $self->base_url . "$key.01.$page"; + return $AC->get_url($url); +} + +sub normalize_key { + my( $self, $key ) = @_; + # Some sites have entered Amazon IDs in 020 $a, thus we cannot # simply pass all incoming keys to Business::ISBN for normalization if (length($key) > 10) { @@ -79,14 +88,11 @@ sub fetch_response { } # Amazon prefers ISBN10 - $isbn = $isbn->as_isbn10 if $isbn->type eq 'ISBN13'; + $isbn = $isbn->as_isbn10 if $isbn->prefix eq '978'; $key = $isbn->as_string([]); } - - my $url = $self->base_url . "$key.01.$page"; - return $AC->get_url($url); + return $key; } - 1; diff --git a/Open-ILS/src/perlmods/t/16-OpenILS-WWW-AddedContent.t b/Open-ILS/src/perlmods/t/16-OpenILS-WWW-AddedContent.t index 10f79c9ec4..29633d42c6 100644 --- a/Open-ILS/src/perlmods/t/16-OpenILS-WWW-AddedContent.t +++ b/Open-ILS/src/perlmods/t/16-OpenILS-WWW-AddedContent.t @@ -1,6 +1,6 @@ #!perl -T -use Test::More tests => 5; +use Test::More tests => 9; BEGIN { use_ok( 'OpenILS::WWW::AddedContent' ); @@ -10,3 +10,9 @@ use_ok( 'OpenILS::WWW::AddedContent::Amazon' ); use_ok( 'OpenILS::WWW::AddedContent::ContentCafe' ); use_ok( 'OpenILS::WWW::AddedContent::OpenLibrary' ); use_ok( 'OpenILS::WWW::AddedContent::Syndetic' ); + +my $amazon = OpenILS::WWW::AddedContent::Amazon; +is($amazon->normalize_key('9791186178140'), '9791186178140', 'Amazon Added Content can handle 979 ISBNs'); +is($amazon->normalize_key('9780735220171'), '0735220174', 'Amazon Added Content converts ISBN-13s to ISBN-10s'); +is($amazon->normalize_key('0735220174'), '0735220174', 'Amazon Added Content leaves ISBN-10s as they are'); +is($amazon->normalize_key('978-0735220171'), '0735220174', 'Amazon Added Content removes hyphens from ISBNs'); diff --git a/Open-ILS/src/sql/Pg/t/lp1857060_handle_all_types_of_isbn.pg b/Open-ILS/src/sql/Pg/t/lp1857060_handle_all_types_of_isbn.pg new file mode 100644 index 0000000000..bbc4d2f3da --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/lp1857060_handle_all_types_of_isbn.pg @@ -0,0 +1,30 @@ +BEGIN; + +SELECT plan(4); + +SELECT is( + (SELECT public.translate_isbn1013('9791186178140')), + '9791186178140 ', + 'public.translate_isbn1013 can handle 979 ISBNs' +); + +SELECT is( + (SELECT public.translate_isbn1013('9780735220171')), + '9780735220171 0735220174 ', + 'public.translate_isbn1013 can translate 978 ISBNs to ISBN10s' +); + +SELECT is( + (SELECT public.translate_isbn1013('0735220174')), + '0735220174 9780735220171 ', + 'public.translate_isbn1013 can translate ISBN10s to ISBN13s' +); + +SELECT is( + (SELECT public.translate_isbn1013('979-1186178140')), + '9791186178140 ', + 'public.translate_isbn1013 can remove hyphens' +); + + +ROLLBACK;