LP1857060: Tests for ISBNs with 979 prefix
authorJane Sandberg <sandbej@linnbenton.edu>
Thu, 19 Dec 2019 23:54:18 +0000 (15:54 -0800)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 13 Jul 2021 14:33:51 +0000 (10:33 -0400)
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 <sandbej@linnbenton.edu>
Signed-off-by: Jason Boyer <JBoyer@equinoxOLI.org>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/Amazon.pm
Open-ILS/src/perlmods/t/16-OpenILS-WWW-AddedContent.t
Open-ILS/src/sql/Pg/t/lp1857060_handle_all_types_of_isbn.pg [new file with mode: 0644]

index 9e2c13c..0cf9d1a 100644 (file)
@@ -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;
index 10f79c9..29633d4 100644 (file)
@@ -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 (file)
index 0000000..bbc4d2f
--- /dev/null
@@ -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;