Bugzilla – Attachment 113527 Details for
Bug 26963
Improve Koha::Item::pickup_locations performance
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26963: (QA follow-up) Migrate unit tests into pickup_location
Bug-26963-QA-follow-up-Migrate-unit-tests-into-pic.patch (text/plain), 12.46 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-11-11 18:26:24 UTC
(
hide
)
Description:
Bug 26963: (QA follow-up) Migrate unit tests into pickup_location
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-11-11 18:26:24 UTC
Size:
12.46 KB
patch
obsolete
>From 42e57a06750698e82da15472ba7a531f75d5438f Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 11 Nov 2020 16:06:21 +0000 >Subject: [PATCH] Bug 26963: (QA follow-up) Migrate unit tests into > pickup_location > >We wrote unit tests for _can_pickup_locations as part of this patchset, >but then I inlined the method whilst golfing. This patch moves those >tests into the existing pickup_locations test so we more thoroughly >cover the case where branch transfer limits are in play. > >NOTE: The tests all assume that all items have an effective_itemtype and >ccode. I'm pretty sure items all have a type at this point, but I'm less >sure we enforce collection codes? > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > t/db_dependent/Koha/Item.t | 224 ++++++++++++++++++------------------- > 1 file changed, 111 insertions(+), 113 deletions(-) > >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index 8cb1b399bd9..3e863b69b35 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 8; >+use Test::More tests => 7; > > use C4::Biblio; > use C4::Circulation; >@@ -156,7 +156,7 @@ subtest "as_marc_field() tests" => sub { > }; > > subtest 'pickup_locations' => sub { >- plan tests => 114; >+ plan tests => 119; > > $schema->storage->txn_begin; > >@@ -192,12 +192,14 @@ subtest 'pickup_locations' => sub { > my $group2_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); > my $group2_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); > >+ my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { itemtype => 'test' } } ); > my $item1 = $builder->build_sample_item( > { > homebranch => $library1->branchcode, > holdingbranch => $library2->branchcode, > barcode => '1', > itype => 'test', >+ ccode => 'Gollum' > } > )->store; > >@@ -214,65 +216,65 @@ subtest 'pickup_locations' => sub { > my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode, firstname => '4' } } ); > > my $results = { >- "1-1-1-any" => 3, >- "1-1-1-holdgroup" => 2, >- "1-1-1-patrongroup" => 2, >- "1-1-1-homebranch" => 1, >+ "1-1-1-any" => 3, >+ "1-1-1-holdgroup" => 2, >+ "1-1-1-patrongroup" => 2, >+ "1-1-1-homebranch" => 1, > "1-1-1-holdingbranch" => 1, >- "1-1-2-any" => 3, >- "1-1-2-holdgroup" => 2, >- "1-1-2-patrongroup" => 2, >- "1-1-2-homebranch" => 1, >+ "1-1-2-any" => 3, >+ "1-1-2-holdgroup" => 2, >+ "1-1-2-patrongroup" => 2, >+ "1-1-2-homebranch" => 1, > "1-1-2-holdingbranch" => 1, >- "1-1-3-any" => 3, >- "1-1-3-holdgroup" => 2, >- "1-1-3-patrongroup" => 2, >- "1-1-3-homebranch" => 1, >+ "1-1-3-any" => 3, >+ "1-1-3-holdgroup" => 2, >+ "1-1-3-patrongroup" => 2, >+ "1-1-3-homebranch" => 1, > "1-1-3-holdingbranch" => 1, >- "1-4-1-any" => 0, >- "1-4-1-holdgroup" => 0, >- "1-4-1-patrongroup" => 0, >- "1-4-1-homebranch" => 0, >+ "1-4-1-any" => 0, >+ "1-4-1-holdgroup" => 0, >+ "1-4-1-patrongroup" => 0, >+ "1-4-1-homebranch" => 0, > "1-4-1-holdingbranch" => 0, >- "1-4-2-any" => 3, >- "1-4-2-holdgroup" => 2, >- "1-4-2-patrongroup" => 1, >- "1-4-2-homebranch" => 1, >+ "1-4-2-any" => 3, >+ "1-4-2-holdgroup" => 2, >+ "1-4-2-patrongroup" => 1, >+ "1-4-2-homebranch" => 1, > "1-4-2-holdingbranch" => 1, >- "1-4-3-any" => 0, >- "1-4-3-holdgroup" => 0, >- "1-4-3-patrongroup" => 0, >- "1-4-3-homebranch" => 0, >+ "1-4-3-any" => 0, >+ "1-4-3-holdgroup" => 0, >+ "1-4-3-patrongroup" => 0, >+ "1-4-3-homebranch" => 0, > "1-4-3-holdingbranch" => 0, >- "3-1-1-any" => 0, >- "3-1-1-holdgroup" => 0, >- "3-1-1-patrongroup" => 0, >- "3-1-1-homebranch" => 0, >+ "3-1-1-any" => 0, >+ "3-1-1-holdgroup" => 0, >+ "3-1-1-patrongroup" => 0, >+ "3-1-1-homebranch" => 0, > "3-1-1-holdingbranch" => 0, >- "3-1-2-any" => 3, >- "3-1-2-holdgroup" => 1, >- "3-1-2-patrongroup" => 2, >- "3-1-2-homebranch" => 0, >+ "3-1-2-any" => 3, >+ "3-1-2-holdgroup" => 1, >+ "3-1-2-patrongroup" => 2, >+ "3-1-2-homebranch" => 0, > "3-1-2-holdingbranch" => 1, >- "3-1-3-any" => 0, >- "3-1-3-holdgroup" => 0, >- "3-1-3-patrongroup" => 0, >- "3-1-3-homebranch" => 0, >+ "3-1-3-any" => 0, >+ "3-1-3-holdgroup" => 0, >+ "3-1-3-patrongroup" => 0, >+ "3-1-3-homebranch" => 0, > "3-1-3-holdingbranch" => 0, >- "3-4-1-any" => 0, >- "3-4-1-holdgroup" => 0, >- "3-4-1-patrongroup" => 0, >- "3-4-1-homebranch" => 0, >+ "3-4-1-any" => 0, >+ "3-4-1-holdgroup" => 0, >+ "3-4-1-patrongroup" => 0, >+ "3-4-1-homebranch" => 0, > "3-4-1-holdingbranch" => 0, >- "3-4-2-any" => 3, >- "3-4-2-holdgroup" => 1, >- "3-4-2-patrongroup" => 1, >- "3-4-2-homebranch" => 0, >+ "3-4-2-any" => 3, >+ "3-4-2-holdgroup" => 1, >+ "3-4-2-patrongroup" => 1, >+ "3-4-2-homebranch" => 0, > "3-4-2-holdingbranch" => 1, >- "3-4-3-any" => 3, >- "3-4-3-holdgroup" => 1, >- "3-4-3-patrongroup" => 1, >- "3-4-3-homebranch" => 0, >+ "3-4-3-any" => 3, >+ "3-4-3-holdgroup" => 1, >+ "3-4-3-patrongroup" => 1, >+ "3-4-3-homebranch" => 0, > "3-4-3-holdingbranch" => 1 > }; > >@@ -318,7 +320,7 @@ subtest 'pickup_locations' => sub { > . $ha . '-' > . $hfp > } >- . ' but returns ' >+ . ' and returns ' > . scalar(@pl) > ); > >@@ -336,91 +338,87 @@ subtest 'pickup_locations' => sub { > } > } > >- $schema->storage->txn_rollback; >-}; >- >-subtest '_can_pickup_locations' => sub { >- plan tests =>8; >- >- $schema->storage->txn_begin; >- >- t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); >- >- my $library1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); >- my $library2 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); >- my $library3 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0, } } ); >- my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1, } } ); >- >- my $item = $builder->build_sample_item({ >- homebranch => $library1->branchcode, >- holdingbranch => $library1->branchcode, >- ccode => "Gollum" >- }); >- >- my @to = ( $library1, $library2, $library3, $library4 ); >- >- my $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >- is( scalar @$pickup_locations, 3, "With no transfer limits we get back the libraries that are pickup locations"); >- >+ # Now test that branchtransferlimits will further filter the pickup locations > t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); > t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); >- $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { >- toBranch => $library2->branchcode, >- fromBranch => $library1->branchcode, >- itemtype => $item->itype, >- ccode => undef, >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => undef, >+ itemtype => $item1->itype, >+ rules => { >+ holdallowed => 1, >+ hold_fulfillment_policy => 1, >+ returnbranch => 'any' >+ } > } >- }); >+ ); >+ $builder->build_object( >+ { >+ class => 'Koha::Item::Transfer::Limits', >+ value => { >+ toBranch => $library1->branchcode, >+ fromBranch => $library2->branchcode, >+ itemtype => $item1->itype, >+ ccode => undef, >+ } >+ } >+ ); > >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >+ my $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; > is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); > >- $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { >- toBranch => $library4->branchcode, >- fromBranch => $library1->branchcode, >- itemtype => $item->itype, >- ccode => undef, >+ $builder->build_object( >+ { >+ class => 'Koha::Item::Transfer::Limits', >+ value => { >+ toBranch => $library4->branchcode, >+ fromBranch => $library2->branchcode, >+ itemtype => $item1->itype, >+ ccode => undef, >+ } > } >- }); >+ ); > >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >+ $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; > is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); > > t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'ccode'); >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >+ $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; > is( scalar @$pickup_locations, 3, "With no transfer limits of type ccode we get back the libraries that are pickup locations"); > >- $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { >- toBranch => $library2->branchcode, >- fromBranch => $library1->branchcode, >- itemtype => undef, >- ccode => $item->ccode, >+ $builder->build_object( >+ { >+ class => 'Koha::Item::Transfer::Limits', >+ value => { >+ toBranch => $library2->branchcode, >+ fromBranch => $library2->branchcode, >+ itemtype => undef, >+ ccode => $item1->ccode, >+ } > } >- }); >+ ); > >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >+ $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; > is( scalar @$pickup_locations, 2, "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library"); > >- $builder->build_object( { class => 'Koha::Item::Transfer::Limits', value => { >- toBranch => $library4->branchcode, >- fromBranch => $library1->branchcode, >- itemtype => undef, >- ccode => $item->ccode, >+ $builder->build_object( >+ { >+ class => 'Koha::Item::Transfer::Limits', >+ value => { >+ toBranch => $library4->branchcode, >+ fromBranch => $library2->branchcode, >+ itemtype => undef, >+ ccode => $item1->ccode, >+ } > } >- }); >+ ); > >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >+ $pickup_locations = $item1->pickup_locations( { patron => $patron1 } )->as_list; > is( scalar @$pickup_locations, 1, "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries"); > >- >- $pickup_locations = $item->_can_pickup_locations({ to => \@to, from => $library2 }); >- is( scalar @$pickup_locations, 3, "With transfer limits enabled but not applying because of 'from' we get back the libraries that are pickup locations"); >- > t::lib::Mocks::mock_preference('UseBranchTransferLimits', 0); > >- $pickup_locations = $item->_can_pickup_locations({ to => \@to }); >- is( scalar @$pickup_locations, 3, "With transfer limits disabled we get back the libraries that are pickup locations"); >- >+ $schema->storage->txn_rollback; > }; > > subtest 'deletion' => sub { >-- >2.29.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 26963
:
113282
|
113283
|
113329
|
113330
|
113333
|
113339
|
113340
|
113419
|
113420
|
113422
|
113423
|
113424
|
113425
|
113451
|
113452
|
113453
|
113454
|
113455
|
113480
|
113481
|
113483
|
113498
|
113503
|
113504
|
113505
|
113506
|
113507
|
113508
|
113509
|
113510
|
113511
|
113512
|
113513
|
113514
|
113515
|
113516
|
113517
|
113518
|
113519
|
113520
|
113521
|
113523
|
113524
|
113525
|
113526
| 113527 |
113528
|
113529
|
113530
|
113531
|
113586
|
113729