Bugzilla – Attachment 163344 Details for
Bug 34611
Add a script for pseudonymizing existing data
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34611: Unit tests
Bug-34611-Unit-tests.patch (text/plain), 5.47 KB, created by
Nick Clemens (kidclamp)
on 2024-03-18 16:13:36 UTC
(
hide
)
Description:
Bug 34611: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-03-18 16:13:36 UTC
Size:
5.47 KB
patch
obsolete
>From 11d00a575045498460f4a31290b335c737c16dfc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 24 Oct 2023 15:17:33 -0300 >Subject: [PATCH] Bug 34611: Unit tests > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: AFHDubCoLib <andrewfh@dubcolib.org> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > .../Koha/PseudonymizedTransaction.t | 131 ++++++++++++++++++ > 1 file changed, 131 insertions(+) > create mode 100755 t/db_dependent/Koha/PseudonymizedTransaction.t > >diff --git a/t/db_dependent/Koha/PseudonymizedTransaction.t b/t/db_dependent/Koha/PseudonymizedTransaction.t >new file mode 100755 >index 00000000000..7a92a14a77b >--- /dev/null >+++ b/t/db_dependent/Koha/PseudonymizedTransaction.t >@@ -0,0 +1,131 @@ >+#!/usr/bin/perl >+ >+# Copyright 2023 Koha Development team >+# >+# 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::DateUtils qw( dt_from_string ); >+use Koha::Patrons; >+use Koha::PseudonymizedTransactions; >+ >+use Crypt::Eksblowfish::Bcrypt qw( bcrypt ); >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $bcrypt_settings = '$2a$10$f.3Kc8Ofrvad4nI2muehEOACmgw6MgwJLxfhyFYmCwRlAHOYQrhCu'; >+ >+subtest 'get_hash() tests' => sub { >+ >+ plan tests => 2; >+ >+ t::lib::Mocks::mock_config( 'bcrypt_settings', '' ); >+ >+ my $string = "foo"; >+ >+ throws_ok { Koha::PseudonymizedTransaction->get_hash($string) } >+ 'Koha::Exceptions::Config::MissingEntry'; >+ >+ t::lib::Mocks::mock_config( 'bcrypt_settings', $bcrypt_settings ); >+ is( >+ Koha::PseudonymizedTransaction->get_hash($string), bcrypt( $string, $bcrypt_settings ), >+ "get_hash() returns the output of the bcrypt method using the bcrypt_settings' config entry" >+ ); >+}; >+ >+subtest 'new_from_statistic() tests' => sub { >+ >+ plan tests => 15; >+ >+ $schema->storage->txn_begin; >+ >+ t::lib::Mocks::mock_config( 'bcrypt_settings', $bcrypt_settings ); >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item; >+ >+ my @fields = qw( >+ ccode >+ datetime >+ holdingbranch >+ homebranch >+ itemcallnumber >+ itemnumber >+ itemtype >+ location >+ transaction_branchcode >+ transaction_type >+ ); >+ >+ t::lib::Mocks::mock_preference( >+ 'PseudonymizationTransactionFields', >+ join( ',', @fields ) >+ ); >+ >+ my $statistic = $builder->build_object( >+ { >+ class => 'Koha::Statistics', >+ value => { >+ borrowernumber => $patron->id, >+ branch => $library->id, >+ ccode => $item->ccode, >+ itemnumber => $item->id, >+ itemtype => $item->itype, >+ location => $item->location, >+ } >+ } >+ ); >+ >+ my $pseudonymized = Koha::PseudonymizedTransaction->new_from_statistic($statistic); >+ >+ is( >+ $pseudonymized->hashed_borrowernumber, >+ Koha::PseudonymizedTransaction->get_hash( $patron->id ), "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->itemnumber, $item->itemnumber, 'itemnumber copied correctly' ); >+ is( $pseudonymized->itemtype, $item->itype, 'itype copied correctly' ); >+ is( $pseudonymized->holdingbranch, $item->holdingbranch, 'holdingbranch copied correctly' ); >+ is( $pseudonymized->homebranch, $item->homebranch, 'homebranch copied correctly' ); >+ is( $pseudonymized->location, $item->location, 'location copied correctly' ); >+ is( $pseudonymized->itemcallnumber, $item->itemcallnumber, 'itemcallnumber copied correctly' ); >+ is( $pseudonymized->ccode, $item->ccode, 'ccode copied correctly' ); >+ is( $pseudonymized->branchcode, $patron->branchcode, 'branchcode set correctly' ); >+ is( $pseudonymized->categorycode, $patron->categorycode, 'categorycode set correctly' ); >+ ok( $pseudonymized->has_cardnumber, 'has_cardnumber set correctly' ); >+ >+ $patron->cardnumber(undef)->store; >+ >+ ok( >+ !Koha::PseudonymizedTransaction->new_from_statistic($statistic)->has_cardnumber, >+ 'has_cardnumber set to false' >+ ); >+ >+ $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 34611
:
154808
|
154809
|
157753
|
157754
|
157755
|
157763
|
157764
|
157765
|
157869
|
157870
|
157871
|
157872
|
157877
|
157878
|
157879
|
157880
|
159909
|
159910
|
159911
|
159912
| 163344 |
163345
|
163346
|
163347
|
163756
|
163757