Bugzilla – Attachment 160909 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: Unit tests
Bug-35277-Unit-tests.patch (text/plain), 4.34 KB, created by
Marcel de Rooy
on 2024-01-12 10:03:57 UTC
(
hide
)
Description:
Bug 35277: Unit tests
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2024-01-12 10:03:57 UTC
Size:
4.34 KB
patch
obsolete
>From 51bfe035b14789f58b23ba3a87b01f75468c1365 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 7 Nov 2023 16:55:44 +0000 >Subject: [PATCH] Bug 35277: Unit tests >Content-Type: text/plain; charset=utf-8 > >prove -v t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t > >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > .../BackgroundJob/PseudonymizeStatistic.t | 98 +++++++++++++++++++ > 1 file changed, 98 insertions(+) > create mode 100755 t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t > >diff --git a/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t b/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t >new file mode 100755 >index 0000000000..a5e1662ba6 >--- /dev/null >+++ b/t/db_dependent/Koha/BackgroundJob/PseudonymizeStatistic.t >@@ -0,0 +1,98 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::Exception; >+ >+use Koha::Database; >+use Koha::BackgroundJobs; >+use Koha::BackgroundJob::PseudonymizeStatistic; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+use Carp::Always; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'enqueue() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item(); >+ >+ throws_ok { >+ Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue() >+ } >+ 'Koha::Exceptions::MissingParameter', >+ "Exception thrown if 'statistic' param is missing"; >+ >+ my $statistic = $builder->build_object( >+ { >+ class => 'Koha::Statistics', >+ value => { type => 'issue', borrowernumber => $patron->id, itemnumber => $item->id } >+ } >+ ); >+ >+ my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic->unblessed } ); >+ >+ my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >+ >+ is( $job->size, 1, 'Size is correct' ); >+ is( $job->status, 'new', 'Initial status set correctly' ); >+ is( $job->queue, 'default', 'PseudonymizeStatistic should use the default queue' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'process() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ 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' ); >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item(); >+ my $statistic = $builder->build_object( >+ { >+ class => 'Koha::Statistics', >+ value => { type => 'issue', borrowernumber => $patron->id, itemnumber => $item->id } >+ } >+ ); >+ >+ my $job_id = Koha::BackgroundJob::PseudonymizeStatistic->new->enqueue( { statistic => $statistic->unblessed } ); >+ my $pseudonymized_transactions_before = Koha::PseudonymizedTransactions->search()->count(); >+ my $job = Koha::BackgroundJobs->find($job_id)->_derived_class; >+ $job->process( { statistic => $statistic->unblessed } ); >+ my $pseudonymized_transactions_after = Koha::PseudonymizedTransactions->search()->count(); >+ is( $pseudonymized_transactions_after, $pseudonymized_transactions_before + 1, "Pseudonymized transaction added" ); >+ >+ $job->discard_changes; >+ is( $job->data, '{"data":""}', "Job data cleared after pseudonymization" ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >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