Bugzilla – Attachment 161065 Details for
Bug 35277
Pseudonymization should be done in a background job
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35277: (follow-up) Fix tests
Bug-35277-follow-up-Fix-tests.patch (text/plain), 8.57 KB, created by
Nick Clemens (kidclamp)
on 2024-01-16 14:27:45 UTC
(
hide
)
Description:
Bug 35277: (follow-up) Fix tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-01-16 14:27:45 UTC
Size:
8.57 KB
patch
obsolete
>From c358601a24f0c1277d0e66a32eedfb2ce71267ff Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 16 Jan 2024 14:26:25 +0000 >Subject: [PATCH] Bug 35277: (follow-up) Fix tests > >This patch adjusts the tests to mock the Background to ensure it is called >and directly generate the pseudonymized transactions for testing >--- > t/db_dependent/Koha/Pseudonymization.t | 87 ++++++++++++++++---------- > 1 file changed, 55 insertions(+), 32 deletions(-) > >diff --git a/t/db_dependent/Koha/Pseudonymization.t b/t/db_dependent/Koha/Pseudonymization.t >index ee7dd5732c6..de0a103946d 100755 >--- a/t/db_dependent/Koha/Pseudonymization.t >+++ b/t/db_dependent/Koha/Pseudonymization.t >@@ -20,10 +20,11 @@ > use Modern::Perl; > > use Test::More tests => 3; >+use Test::Warn; > use Try::Tiny; > > use C4::Circulation qw( AddIssue AddReturn ); >-use C4::Stats qw( UpdateStats ); >+use C4::Stats qw( UpdateStats ); > > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); >@@ -44,15 +45,15 @@ subtest 'Config does not exist' => sub { > $schema->storage->txn_begin; > > t::lib::Mocks::mock_config( 'bcrypt_settings', '' ); >- t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >+ t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); > t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', 'branchcode,categorycode,sort1' ); > > my $library = $builder->build_object( { class => 'Koha::Libraries' } ); > my $item = $builder->build_sample_item; > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > >- try{ >- C4::Stats::UpdateStats( >+ try { >+ my $stat = Koha::Statistic->new( > { > type => 'issue', > branch => $library->branchcode, >@@ -63,10 +64,14 @@ subtest 'Config does not exist' => sub { > ccode => $item->ccode, > } > ); >+ my $pseudo = Koha::PseudonymizedTransaction->new_from_statistic($stat); > > } catch { >- ok($_->isa('Koha::Exceptions::Config::MissingEntry'), "Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'bcrypt_settings' is not defined in the config"); >- is( $_->message, "Missing 'bcrypt_settings' entry in config file"); >+ ok( >+ $_->isa('Koha::Exceptions::Config::MissingEntry'), >+ "Koha::Patron->store should raise a Koha::Exceptions::Config::MissingEntry if 'bcrypt_settings' is not defined in the config" >+ ); >+ is( $_->message, "Missing 'bcrypt_settings' entry in config file" ); > }; > > $schema->storage->txn_rollback; >@@ -74,38 +79,54 @@ subtest 'Config does not exist' => sub { > > subtest 'Koha::Anonymized::Transactions tests' => sub { > >- plan tests => 12; >+ plan tests => 15; > > $schema->storage->txn_begin; > > t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); > >+ my $pseudo_background = Test::MockModule->new('Koha::BackgroundJob::PseudonymizeStatistic'); >+ $pseudo_background->mock( enqueue => sub { warn "Called" } ); >+ > my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > > t::lib::Mocks::mock_preference( 'Pseudonymization', 0 ); > my $item = $builder->build_sample_item; >- t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); >- AddIssue( $patron, $item->barcode, dt_from_string ); >- AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); >- my $pseudonymized= Koha::PseudonymizedTransactions->search( >- { itemnumber => $item->itemnumber } )->next; >- is( $pseudonymized, undef, >- 'No pseudonymized transaction if Pseudonymization is off' ); >+ t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } ); >+ warnings_are { >+ AddIssue( $patron, $item->barcode, dt_from_string ); >+ } >+ undef, "No background job queued when pseudonymization disabled"; >+ warnings_are { >+ AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); >+ } >+ undef, "No background job queued when pseudonymization disabled"; > > t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >- t::lib::Mocks::mock_preference( 'PseudonymizationTransactionFields', 'datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode' >+ t::lib::Mocks::mock_preference( >+ 'PseudonymizationTransactionFields', >+ 'datetime,transaction_branchcode,transaction_type,itemnumber,itemtype,holdingbranch,homebranch,location,itemcallnumber,ccode' > ); > $item = $builder->build_sample_item; >- t::lib::Mocks::mock_userenv({ branchcode => $item->homebranch }); >- AddIssue( $patron, $item->barcode, dt_from_string ); >- AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); >- my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; >- $pseudonymized = Koha::PseudonymizedTransactions->search( { itemnumber => $item->itemnumber } )->next; >- like( $pseudonymized->hashed_borrowernumber, >- qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" ); >+ t::lib::Mocks::mock_userenv( { branchcode => $item->homebranch } ); >+ warnings_are { >+ AddIssue( $patron, $item->barcode, dt_from_string ); >+ } >+ ["Called"], "Background job enqueued when pseudonymization enabled"; >+ warnings_are { >+ AddReturn( $item->barcode, $item->homebranch, undef, dt_from_string ); >+ } >+ ["Called"], "Background job enqueued when pseudonymization enabled"; >+ >+ my $statistic = Koha::Statistics->search( { itemnumber => $item->itemnumber } )->next; >+ my $pseudonymized = Koha::PseudonymizedTransaction->new_from_statistic($statistic); >+ like( >+ $pseudonymized->hashed_borrowernumber, >+ qr{^\$2a\$08\$}, "The hashed_borrowernumber must be a bcrypt hash" >+ ); > is( $pseudonymized->datetime, $statistic->datetime, 'datetime attribute copied correctly' ); > is( $pseudonymized->transaction_branchcode, $statistic->branch, 'transaction_branchcode copied correctly' ); >- is( $pseudonymized->transaction_type, $statistic->type, 'transacttion_type copied correctly' ); >+ is( $pseudonymized->transaction_type, $statistic->type, 'transaction_type copied correctly' ); > is( $pseudonymized->itemnumber, $item->itemnumber, 'itemnumber copied correctly' ); > is( $pseudonymized->itemtype, $item->effective_itemtype, 'itemtype copied correctly' ); > is( $pseudonymized->holdingbranch, $item->holdingbranch, 'holdingbranch copied correctly' ); >@@ -125,10 +146,12 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { > > t::lib::Mocks::mock_config( 'bcrypt_settings', '$2a$08$9lmorEKnwQloheaCLFIfje' ); > t::lib::Mocks::mock_preference( 'Pseudonymization', 1 ); >- t::lib::Mocks::mock_preference( 'PseudonymizationPatronFields', >- 'branchcode,categorycode,sort1' ); >+ t::lib::Mocks::mock_preference( >+ 'PseudonymizationPatronFields', >+ 'branchcode,categorycode,sort1' >+ ); > >- my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); > my $patron_info = $patron->unblessed; > delete $patron_info->{borrowernumber}; > $patron->delete; >@@ -177,11 +200,10 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { > > $patron->extended_attributes($attribute_values); > >- > my $library = $builder->build_object( { class => 'Koha::Libraries' } ); > my $item = $builder->build_sample_item; > >- C4::Stats::UpdateStats( >+ my $statistic = Koha::Statistic->new( > { > type => 'issue', > branch => $library->branchcode, >@@ -193,11 +215,12 @@ subtest 'PseudonymizedBorrowerAttributes tests' => sub { > } > ); > >- my $p = Koha::PseudonymizedTransactions->search({itemnumber => $item->itemnumber})->next; >+ my $p = Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store; > my $attributes = >- Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') >- ->search( { transaction_id => $p->id }, { order_by => 'attribute' } ); >- is( $attributes->count, 2, >+ Koha::Database->new->schema->resultset('PseudonymizedBorrowerAttribute') >+ ->search( { transaction_id => $p->id }, { order_by => 'attribute' } ); >+ is( >+ $attributes->count, 2, > 'Only the 2 attributes that have a type with keep_for_pseudonymization set should be kept' > ); > my $attribute_1 = $attributes->next; >-- >2.30.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 35277
:
158596
|
158597
|
158606
|
158607
|
158608
|
158610
|
158611
|
158802
|
159440
|
160908
|
160909
|
160910
|
160911
|
160912
| 161065