Bugzilla – Attachment 173096 Details for
Bug 35659
OAI harvester
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35659: (QA follow-up): Add init function tests by using Koha's OAI server
Bug-35659-QA-follow-up-Add-init-function-tests-by-.patch (text/plain), 7.85 KB, created by
David Cook
on 2024-10-22 01:36:41 UTC
(
hide
)
Description:
Bug 35659: (QA follow-up): Add init function tests by using Koha's OAI server
Filename:
MIME Type:
Creator:
David Cook
Created:
2024-10-22 01:36:41 UTC
Size:
7.85 KB
patch
obsolete
>From c721426793ac5911a1619f68d4c3af65612ce422 Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Tue, 10 Sep 2024 15:34:07 +0000 >Subject: [PATCH] Bug 35659: (QA follow-up): Add init function tests by using > Koha's OAI server > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >Signed-off-by: David Cook <dcook@prosentient.com.au> >Sponsored-by: Association KohaLa - https://koha-fr.org/ >--- > Koha/OAI/Client/Harvester.pm | 13 ++++--- > t/db_dependent/Koha/OAIHarvester.t | 55 +++++++++++++++++++++++++----- > 2 files changed, 55 insertions(+), 13 deletions(-) > >diff --git a/Koha/OAI/Client/Harvester.pm b/Koha/OAI/Client/Harvester.pm >index 779632824d..9e60214be1 100644 >--- a/Koha/OAI/Client/Harvester.pm >+++ b/Koha/OAI/Client/Harvester.pm >@@ -87,10 +87,10 @@ Starts harvesting > > sub init { > my ( $self, $args ) = @_; >- > $self->printlog("Starting OAI Harvest from repository"); > my $server = $self->{server}; > my $days = $self->{days}; >+ my $init_results; > > my $h = HTTP::OAI::Harvester->new( > repository => HTTP::OAI::Identify->new( >@@ -117,6 +117,7 @@ sub init { > $lmdflog .= $_->metadataPrefix . " "; > } > $self->printlog("Available metadata formats for this repository: $lmdflog"); >+ $init_results->{metadata_formats} = $lmdflog; > } catch { > $self->printlog("ListMetadataFormats failed"); > }; >@@ -148,7 +149,8 @@ sub init { > ); > if ( $response->is_error ) { > $self->printlog( "Error requesting ListRecords: " . $response->code . " " . $response->message ); >- exit; >+ $init_results->{is_error} = $response->message; >+ return $init_results; > } > $self->printlog( "Request URL: " . $response->requestURL ); > >@@ -164,6 +166,7 @@ sub init { > my $status = $self->processRecord($oai_record); > $stats{$status}++; > } >+ $init_results->{total} = $stats{'total'}; > > my $results = ''; > foreach my $status (@statuses) { >@@ -193,20 +196,22 @@ sub init { > ) > ) or $self->printlog("OAI_HARVEST_REPORT letter not found"); > >- my $success = C4::Letters::EnqueueLetter( >+ my $message_id = C4::Letters::EnqueueLetter( > { > letter => $letter, > to_address => C4::Context->preference("OAI-PMH:HarvestEmailReport"), message_transport_type => 'email' > } > ); >- if ($success) { >+ if ($message_id) { > $self->printlog("Email report enqueued"); >+ $init_results->{letter_message_id} = $message_id; > } else { > $self->printlog("Unable to enqueue report email"); > } > } > > $self->printlog("Ending OAI Harvest from repository"); >+ return $init_results; > } > > =head2 processRecord >diff --git a/t/db_dependent/Koha/OAIHarvester.t b/t/db_dependent/Koha/OAIHarvester.t >index c8ecd701b4..1a64ed22e2 100755 >--- a/t/db_dependent/Koha/OAIHarvester.t >+++ b/t/db_dependent/Koha/OAIHarvester.t >@@ -18,11 +18,13 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 24; >+use Test::More tests => 28; > use Test::Exception; > use File::Temp qw/tempfile/; > > use t::lib::TestBuilder; >+use t::lib::Mocks; >+ > use HTTP::OAI; > use HTTP::OAI::Metadata::OAI_DC; > use HTTP::OAI::Record; >@@ -39,8 +41,8 @@ $schema->storage->txn_begin; > > my $new_oai_biblio = Koha::OAIServer->new( > { >- endpoint => 'my_host1.org', >- oai_set => 'set1', >+ endpoint => C4::Context->preference('OPACBaseURL') . '/cgi-bin/koha/oai.pl', >+ oai_set => '', > servername => 'my_test_1', > dataformat => 'oai_dc', > recordtype => 'biblio', >@@ -48,8 +50,25 @@ my $new_oai_biblio = Koha::OAIServer->new( > } > )->store; > >+C4::Context->set_preference( 'OAI-PMH', 1 ); >+t::lib::Mocks::mock_preference( >+ 'OAI-PMH:HarvestEmailReport', >+ C4::Context->preference('KohaAdminEmailAddress') >+); >+ > my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 1 } ); > >+my $init_results = $harvester->init(); >+ >+like( >+ $init_results->{metadata_formats}, >+ qr/oai_dc marc21 marcxml/, >+ 'Got list of supported metadata formats' >+); >+is( $init_results->{is_error}, undef, 'ListRecords request worked' ); >+cmp_ok( $init_results->{total}, '>', 0, 'Records have been processed' ); >+isnt( $init_results->{letter_message_id}, undef, 'Report has been enqueued' ); >+ > my $record = > '<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>'; > >@@ -80,7 +99,10 @@ is( $status, 'updated', 'When force is used, record is updated' ); > > $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 0 } ); > $status = $harvester->processRecord($r); >-is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' ); >+is( >+ $status, 'skipped', >+ 'When force is not used, record is skipped (already up to date)' >+); > > $r->header->datestamp('2018-05-10T09:18:13Z'); > $status = $harvester->processRecord($r); >@@ -105,7 +127,10 @@ isnt( > > $r->header->status('deleted'); > $status = $harvester->processRecord($r); >-is( $status, 'deleted', 'When a record is marked to be deleted, status is deleted' ); >+is( >+ $status, 'deleted', >+ 'When a record is marked to be deleted, status is deleted' >+); > > $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); > is( $imported_record, undef, 'Record has been deleted' ); >@@ -145,7 +170,10 @@ $status = $harvester->processRecord($r); > is( $status, 'updated', 'Authority with no date is updated' ); > > $status = $harvester->processRecord($r); >-is( $status, 'updated', 'Authority with no date is updated even without force' ); >+is( >+ $status, 'updated', >+ 'Authority with no date is updated even without force' >+); > > $r->header->identifier('oai:myarchive.org:oid-162'); > $r->header->datestamp('2017-05-10T09:18:13Z'); >@@ -158,11 +186,17 @@ is( $status, 'updated', 'When force is used, authority is updated' ); > > $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 0 } ); > $status = $harvester->processRecord($r); >-is( $status, 'skipped', 'When force is not used, authority is skipped (already up to date)' ); >+is( >+ $status, 'skipped', >+ 'When force is not used, authority is skipped (already up to date)' >+); > > $r->header->datestamp('2018-05-10T09:18:13Z'); > $status = $harvester->processRecord($r); >-is( $status, 'updated', 'When force is not used, authority is updated if newer' ); >+is( >+ $status, 'updated', >+ 'When force is not used, authority is updated if newer' >+); > > my $imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } ); > $imported_authority->update( >@@ -183,7 +217,10 @@ isnt( > > $r->header->status('deleted'); > $status = $harvester->processRecord($r); >-is( $status, 'deleted', 'When an authority is marked to be deleted, status is deleted' ); >+is( >+ $status, 'deleted', >+ 'When an authority is marked to be deleted, status is deleted' >+); > > $imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-162' } ); > is( $imported_record, undef, 'Authority has been deleted' ); >-- >2.39.2
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 35659
:
160356
|
160357
|
160744
|
161813
|
161960
|
162004
|
162005
|
162006
|
162007
|
162008
|
162009
|
162010
|
162011
|
162527
|
162528
|
162692
|
162693
|
162694
|
163527
|
164586
|
164590
|
164602
|
164603
|
164604
|
164605
|
164606
|
164618
|
164619
|
164620
|
164621
|
164622
|
165199
|
165594
|
165595
|
165596
|
165597
|
165598
|
167106
|
167107
|
167171
|
167172
|
167173
|
167174
|
167175
|
167176
|
168982
|
168983
|
169941
|
171255
|
171258
|
171260
|
171264
|
171265
|
171267
|
171675
|
171676
|
171678
|
171679
|
172072
|
172073
|
172074
|
172075
|
172076
|
172077
|
172078
|
172079
|
172080
|
172081
|
172082
|
172083
|
172202
|
172203
|
172204
|
172205
|
172206
|
172207
|
172208
|
172209
|
172210
|
172211
|
172212
|
172213
|
173088
|
173089
|
173090
|
173091
|
173092
|
173093
|
173094
|
173095
| 173096 |
173097
|
173098
|
173099
|
173100
|
173101
|
173561
|
173599
|
173600
|
173601
|
173614