Bugzilla – Attachment 110882 Details for
Bug 25265
Elasticsearch - Batch editing items on a biblio can lead to incorrect index
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 25265: [20.05.x] Unit tests
Bug-25265-2005x-Unit-tests.patch (text/plain), 8.35 KB, created by
Nick Clemens (kidclamp)
on 2020-09-28 16:48:21 UTC
(
hide
)
Description:
Bug 25265: [20.05.x] Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2020-09-28 16:48:21 UTC
Size:
8.35 KB
patch
obsolete
>From 17af2bc360f79236a940a4003296ecd270a35d52 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 17 Sep 2020 11:43:44 +0000 >Subject: [PATCH] Bug 25265: [20.05.x] Unit tests > >These cover Koha::SearchEngine::Indexer and ensure that all calls in the code >are routed correctly to the expected search engine > >Bug 25265: (follow-up) Skip tests if elastic not configured > >Signed-off-by: Bob Bennhoff <bbennhoff@clicweb.org> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > .../Koha/SearchEngine/Elasticsearch/Indexer.t | 10 +- > t/db_dependent/Koha/SearchEngine/Indexer.t | 156 +++++++++++++++++++++ > 2 files changed, 165 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Koha/SearchEngine/Indexer.t > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >index b05a15eec7..6eebea84cc 100644 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t >@@ -29,6 +29,13 @@ my $schema = Koha::Database->schema(); > > use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); > >+SKIP: { >+ >+ eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; >+ >+ skip 'Elasticsearch configuration not available', 2 >+ if $@; >+ > subtest 'create_index() tests' => sub { > plan tests => 5; > my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); >@@ -71,7 +78,6 @@ subtest 'create_index() tests' => sub { > ); > }; > >- > subtest 'update_index() tests' => sub { > plan tests => 2; > my $kse = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); >@@ -96,3 +102,5 @@ subtest 'update_index() tests' => sub { > my $bibnumber_array = $indexer->update_index([13],["faked"]); > is( $bibnumber_array->[0]->{index}->{_id},"13", "We should get a string matching the bibnumber"); > }; >+ >+} >diff --git a/t/db_dependent/Koha/SearchEngine/Indexer.t b/t/db_dependent/Koha/SearchEngine/Indexer.t >new file mode 100755 >index 0000000000..abcbc9a9cb >--- /dev/null >+++ b/t/db_dependent/Koha/SearchEngine/Indexer.t >@@ -0,0 +1,156 @@ >+#!/usr/bin/perl >+ >+# Tests for Koha/SearchEngine/Search >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Warn; >+ >+use MARC::Field; >+use MARC::Record; >+use Test::MockModule; >+use Test::MockObject; >+ >+use t::lib::Mocks; >+ >+#use C4::Biblio qw//; >+use C4::AuthoritiesMarc; >+use C4::Biblio; >+use C4::Circulation; >+use Koha::Database; >+use Koha::SearchEngine::Indexer; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+subtest 'Test indexer object creation' => sub { >+ plan tests => 6; >+ >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); >+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Zebra::Indexer', 'We get the correct class for Zebra biblios'); >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Zebra::Indexer', 'We get the correct class for Zebra authorities'); >+ >+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); >+ >+ SKIP: { >+ >+ eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; >+ >+ skip 'Elasticsearch configuration not available', 4 >+ if $@; >+ >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Elasticsearch::Indexer', 'We get the correct class for Elasticsearch biblios'); >+ ok( $indexer->index_name =~ /biblios$/, "The index is set correctly for biblios"); >+ $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); >+ is( ref $indexer, 'Koha::SearchEngine::Elasticsearch::Indexer', 'We get the correct class for Elasticsearch authorities'); >+ ok( $indexer->index_name =~ /authorities$/, "The index is set correctly for authorities"); >+ >+ } >+}; >+ >+subtest 'Test indexer calls' => sub { >+ plan tests => 24; >+ >+ my @engines = ('Zebra'); >+ eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; }; >+ push @engines, 'Elasticsearch' unless $@; >+ SKIP: { >+ skip 'Elasticsearch configuration not available', 12 >+ if scalar @engines == 1; >+ } >+ >+ for my $engine ( @engines ){ >+ t::lib::Mocks::mock_preference( 'SearchEngine', $engine ); >+ my $mock_index = Test::MockModule->new("Koha::SearchEngine::".$engine."::Indexer"); >+ >+ my $biblionumber1 = $builder->build_sample_biblio()->biblionumber; >+ my $biblionumber2 = $builder->build_sample_biblio()->biblionumber; >+ >+ my $mock_zebra = Test::MockModule->new("Koha::SearchEngine::Zebra::Indexer"); >+ $mock_zebra->mock( ModZebra => sub { warn "ModZebra"; } ); >+ my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >+ warnings_are{ >+ $indexer->index_records([$biblionumber1,$biblionumber1],"specialUpdate","biblioserver",undef); >+ } ["ModZebra","ModZebra"],"ModZebra called for each record being indexed for $engine"; >+ >+ $mock_index->mock( index_records => sub { >+ warn $engine; >+ my ($package, undef, undef) = caller; >+ warn $package; >+ }); >+ >+ my $auth = MARC::Record->new; >+ my $authid; >+ warnings_are{ >+ $authid = AddAuthority( $auth, undef, 'TOPIC_TERM' ); >+ } [$engine,"C4::AuthoritiesMarc"], "index_records is called for $engine is called when adding authority"; >+ >+ warnings_are{ >+ $authid = DelAuthority({ authid => $authid }); >+ } [$engine,"C4::AuthoritiesMarc"], "index_records is called for $engine is called when adding authority"; >+ >+ my $biblio; >+ my $biblio2; >+ warnings_are{ >+ $biblio = $builder->build_sample_biblio(); >+ $biblio2 = $builder->build_sample_biblio(); >+ } [$engine,'C4::Biblio',$engine,'C4::Biblio'], "index_records is called for $engine when adding a biblio (ModBiblioMarc)"; >+ >+ >+ my $item; >+ my $item2; >+ warnings_are{ >+ $item = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); >+ $item2 = $builder->build_sample_item({biblionumber => $biblio->biblionumber}); >+ } [$engine,"Koha::Item",$engine,"Koha::Item"], "index_records is called for $engine when adding an item (Item->store)"; >+ warnings_are{ >+ $item->store({ skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_modzebra_update passed"; >+ >+ $builder->build({ >+ source => 'Branchtransfer', >+ value => { >+ itemnumber => $item->itemnumber, >+ datearrived => undef} >+ }); >+ warnings_are{ >+ LostItem( $item->itemnumber, "tests"); >+ } [$engine,"Koha::Item"], "index_records is called for $engine when calling LostItem and transfer exists"; >+ $builder->build({ >+ source => 'Branchtransfer', >+ value => { >+ itemnumber => $item2->itemnumber, >+ datearrived => undef} >+ }); >+ warnings_are{ >+ LostItem( $item->itemnumber, "tests", undef, { skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when calling LostItem and transfer exists if skip_modzebra_update"; >+ >+ warnings_are{ >+ $item->delete(); >+ } [$engine,"Koha::Item"], "index_records is called for $engine when deleting an item (Item->delete)"; >+ warnings_are{ >+ $item2->delete({ skip_modzebra_update => 1 }); >+ } undef, "index_records is not called for $engine when adding an item (Item->store) if skip_modzebra_update passed"; >+ >+ warnings_are{ >+ DelBiblio( $biblio->biblionumber ); >+ } [$engine, "C4::Biblio"], "index_records is called for $engine when calling DelBiblio"; >+ warnings_are{ >+ DelBiblio( $biblio->biblionumber, { skip_record_index =>1 }); >+ } undef, "index_records is not called for $engine when calling DelBiblio if skip_record_index passed"; >+ >+ } >+ >+}; >+ >+$schema->storage->txn_rollback; >-- >2.11.0
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 25265
:
107832
|
107855
|
107867
|
109538
|
109556
|
110262
|
110263
|
110264
|
110380
|
110381
|
110382
|
110457
|
110458
|
110459
|
110560
|
110561
|
110562
|
110565
|
110594
|
110595
|
110596
|
110597
|
110615
|
110618
|
110729
|
110730
|
110731
|
110732
|
110733
|
110734
|
110736
|
110737
| 110882 |
110883
|
110937