Bugzilla – Attachment 82152 Details for
Bug 19893
Alternative optimized indexing for Elasticsearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19893: Increase test coverage
Bug-19893-Increase-test-coverage.patch (text/plain), 7.71 KB, created by
Ere Maijala
on 2018-11-09 10:06:44 UTC
(
hide
)
Description:
Bug 19893: Increase test coverage
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2018-11-09 10:06:44 UTC
Size:
7.71 KB
patch
obsolete
>From 0254fa325489df20b799431d2966803c3aa16624 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Mon, 5 Nov 2018 15:00:21 +0100 >Subject: [PATCH] Bug 19893: Increase test coverage > >Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi> >--- > Koha/SearchEngine/Elasticsearch/Search.pm | 3 +- > t/Koha/SearchEngine/Elasticsearch.t | 84 +++++++++++++++++++++++++++++-- > 2 files changed, 82 insertions(+), 5 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index 718eb06..6917f19 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -47,6 +47,7 @@ use Koha::ItemTypes; > use Koha::AuthorisedValues; > use Koha::SearchEngine::QueryBuilder; > use Koha::SearchEngine::Search; >+use Koha::Exceptions::Elasticsearch; > use MARC::Record; > use Catmandu::Store::ElasticSearch; > use MARC::File::XML; >@@ -376,7 +377,7 @@ sub decode_record_from_result { > return MARC::Record->new_from_xml($result->{marc_data}, 'UTF-8', uc C4::Context->preference('marcflavour')); > } > else { >- die("Missing marc_format field in Elasticsearch result"); >+ Koha::Exceptions::Elasticsearch->throw("Missing marc_format field in Elasticsearch result"); > } > } > >diff --git a/t/Koha/SearchEngine/Elasticsearch.t b/t/Koha/SearchEngine/Elasticsearch.t >index 993cb1b..201614b 100644 >--- a/t/Koha/SearchEngine/Elasticsearch.t >+++ b/t/Koha/SearchEngine/Elasticsearch.t >@@ -25,8 +25,10 @@ use t::lib::Mocks; > use Test::MockModule; > > use MARC::Record; >+use Try::Tiny; > > use Koha::SearchEngine::Elasticsearch; >+use Koha::SearchEngine::Elasticsearch::Search; > > subtest '_read_configuration() tests' => sub { > >@@ -115,12 +117,21 @@ subtest 'get_elasticsearch_mappings() tests' => sub { > > subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { > >- plan tests => 32; >+ plan tests => 45; > > t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); > > my @mappings = ( > { >+ name => 'control_number', >+ type => 'string', >+ facet => 0, >+ suggestible => 0, >+ sort => undef, >+ marc_type => 'marc21', >+ marc_field => '001', >+ }, >+ { > name => 'author', > type => 'string', > facet => 1, >@@ -166,6 +177,15 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > marc_field => '220', > }, > { >+ name => 'title_wildcard', >+ type => 'string', >+ facet => 0, >+ suggestible => 0, >+ sort => undef, >+ marc_type => 'marc21', >+ marc_field => '245', >+ }, >+ { > name => 'sum_item_price', > type => 'sum', > facet => 0, >@@ -220,11 +240,12 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > } > }); > >- my $see = Koha::SearchEngine::Elasticsearch->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); >+ my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); > > my $marc_record_1 = MARC::Record->new(); > $marc_record_1->leader(' cam 22 a 4500'); > $marc_record_1->append_fields( >+ MARC::Field->new('001', '123'), > MARC::Field->new('100', '', '', a => 'Author 1'), > MARC::Field->new('110', '', '', a => 'Corp Author'), > MARC::Field->new('210', '', '', a => 'Title 1'), >@@ -255,6 +276,8 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > > is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple'); > >+ is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly'); >+ > is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values'); > is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); > >@@ -264,6 +287,9 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > is(scalar @{$docs->[0][1]->{title__sort}}, 3, 'First document title__sort field should have three values'); > is_deeply($docs->[0][1]->{title__sort}, ['Title:', 'first record', 'Title: first record'], 'First document title__sort field should be set correctly'); > >+ is(scalar @{$docs->[0][1]->{title_wildcard}}, 2, 'First document title_wildcard field should have two values'); >+ is_deeply($docs->[0][1]->{title_wildcard}, ['Title:', 'first record'], 'First document title_wildcard field should be set correctly'); >+ > is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values'); > is_deeply( > $docs->[0][1]->{author__suggestion}, >@@ -312,11 +338,14 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > ); > > ok(defined $docs->[0][1]->{marc_data}, 'First document marc_data field should be set'); >- > ok(defined $docs->[0][1]->{marc_format}, 'First document marc_format field should be set'); >- > is($docs->[0][1]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly'); > >+ my $decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); >+ >+ ok($decoded_marc_record->isa('MARC::Record'), "base64ISO2709 record successfully decoded from result"); >+ is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded base64ISO2709 record has same data as original record"); >+ > is(scalar @{$docs->[0][1]->{type_of_record}}, 1, 'First document type_of_record field should have one value'); > is_deeply( > $docs->[0][1]->{type_of_record}, >@@ -376,4 +405,51 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' > > is($docs->[0][1]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); > >+ $decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); >+ >+ ok($decoded_marc_record->isa('MARC::Record'), "MARCXML record successfully decoded from result"); >+ is($decoded_marc_record->as_xml_record(), $large_marc_record->as_xml_record(), "Decoded MARCXML record has same data as original record"); >+ >+ push @mappings, { >+ name => 'title', >+ type => 'string', >+ facet => 0, >+ suggestible => 1, >+ sort => 1, >+ marc_type => 'marc21', >+ marc_field => '245((ab)ab', >+ }; >+ >+ my $exception = try { >+ $see->marc_records_to_documents($records); >+ } >+ catch { >+ return $_; >+ }; >+ >+ ok(defined $exception, "Exception has been thrown when processing mapping with unmatched opening parenthesis"); >+ ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class"); >+ ok($exception->message =~ /Unmatched opening parenthesis/, "Exception has the correct message"); >+ >+ pop @mappings; >+ push @mappings, { >+ name => 'title', >+ type => 'string', >+ facet => 0, >+ suggestible => 1, >+ sort => 1, >+ marc_type => 'marc21', >+ marc_field => '245(ab))ab', >+ }; >+ >+ $exception = try { >+ $see->marc_records_to_documents($records); >+ } >+ catch { >+ return $_; >+ }; >+ >+ ok(defined $exception, "Exception has been thrown when processing mapping with unmatched closing parenthesis"); >+ ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class"); >+ ok($exception->message =~ /Unmatched closing parenthesis/, "Exception has the correct message"); > }; >-- >2.7.4
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 19893
:
70199
|
70200
|
70201
|
70202
|
70230
|
70325
|
73153
|
75109
|
75271
|
75272
|
75353
|
75428
|
75455
|
75588
|
75658
|
75660
|
76612
|
76613
|
76614
|
76629
|
78091
|
78092
|
78093
|
78094
|
78524
|
78561
|
78587
|
78588
|
78589
|
78590
|
78591
|
78592
|
78593
|
78594
|
78690
|
78691
|
78692
|
78693
|
78694
|
78695
|
78696
|
80969
|
80970
|
80971
|
80983
|
81014
|
81015
|
81284
|
81822
|
81901
|
81903
|
81955
|
81957
|
81958
|
81959
|
81960
|
81961
|
81962
|
81963
|
81964
|
81965
|
81966
|
82143
|
82144
|
82145
|
82146
|
82147
|
82148
|
82149
|
82150
|
82151
|
82152
|
82256
|
82257
|
82258
|
82259
|
82260
|
82261
|
82262
|
82263
|
82264
|
82265
|
82266
|
82267