Bugzilla – Attachment 52329 Details for
Bug 12598
New misc/import_borrowers.pl command line tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12598 - Started regression tests. Fix missing C4::Members::Attributes package
Bug-12598---Started-regression-tests-Fix-missing-C.patch (text/plain), 8.18 KB, created by
Kyle M Hall (khall)
on 2016-06-13 16:14:42 UTC
(
hide
)
Description:
Bug 12598 - Started regression tests. Fix missing C4::Members::Attributes package
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-06-13 16:14:42 UTC
Size:
8.18 KB
patch
obsolete
>From 96d253ed3cb31301098e8743bfbb21fc484f14c2 Mon Sep 17 00:00:00 2001 >From: Florent Mara <florent.mara@gmail.com> >Date: Tue, 12 Apr 2016 14:50:30 +1200 >Subject: [PATCH] Bug 12598 - Started regression tests. Fix missing > C4::Members::Attributes package > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/Patrons/Import.pm | 32 +++++++-- > t/db_dependent/Koha/Patrons/Import.t | 122 +++++++++++++++++++++++++++++++++++ > 2 files changed, 150 insertions(+), 4 deletions(-) > create mode 100644 t/db_dependent/Koha/Patrons/Import.t > >diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm >index 6094eac..83b1882 100644 >--- a/Koha/Patrons/Import.pm >+++ b/Koha/Patrons/Import.pm >@@ -22,8 +22,34 @@ use Text::CSV; > > use C4::Members; > use C4::Branch; >+use C4::Members::Attributes qw(:all); >+ > use Koha::DateUtils; > >+=head1 NAME >+ >+Koha::Patrons::Import - Perl Module containing import_patrons method exported from import_borrowers script. >+ >+=head1 SYNOPSIS >+ >+use Koha::Patrons::Import; >+ >+=head1 DESCRIPTION >+ >+This module contains one method for importing patrons in bulk. >+ >+=head1 FUNCTIONS >+ >+=head2 import_patrons >+ >+ my $return = Koha::Patrons::Import::import_patrons($params); >+ >+Applies various checks and imports patrons in bulk from a csv file. >+ >+Further pod documentation needed here. >+ >+=cut >+ > sub import_patrons { > my ($params) = @_; > >@@ -33,8 +59,7 @@ sub import_patrons { > my $ext_preserve = $params->{preserve_extended_attributes}; > my $overwrite_cardnumber = $params->{overwrite_cardnumber}; > >- carp("No file handle passed in!") && return unless $handle; >- >+ unless( $handle ) { carp("No file handle passed in!"); return; } > my $extended = C4::Context->preference('ExtendedPatronAttributes'); > my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); > >@@ -159,8 +184,7 @@ sub import_patrons { > $attr_str =~ s/\xe2\x80\x9c/"/g; # fixup double quotes in case we are passed smart quotes > $attr_str =~ s/\xe2\x80\x9d/"/g; > push @feedback, { feedback => 1, name => 'attribute string', value => $attr_str }; >- delete $borrower{patron_attributes} >- ; # not really a field in borrowers, so we don't want to pass it to ModMember. >+ delete $borrower{patron_attributes}; # not really a field in borrowers, so we don't want to pass it to ModMember. > $patron_attributes = extended_attributes_code_value_arrayref($attr_str); > } > >diff --git a/t/db_dependent/Koha/Patrons/Import.t b/t/db_dependent/Koha/Patrons/Import.t >new file mode 100644 >index 0000000..cf19cd7 >--- /dev/null >+++ b/t/db_dependent/Koha/Patrons/Import.t >@@ -0,0 +1,122 @@ >+#!/usr/bin/perl >+ >+# Copyright 2015 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; >+use Test::MockModule; >+ >+use Koha::Database; >+ >+use File::Temp qw(tempfile tempdir); >+my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1); >+ >+use t::lib::TestBuilder; >+my $builder = t::lib::TestBuilder->new; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+# ########## Tests start here ############################# >+# Given ... we can use the module >+BEGIN { use_ok('Koha::Patrons::Import'); } >+ >+# Given ... we can reach the method(s) >+my @methods = ('import_patrons'); >+can_ok('Koha::Patrons::Import', @methods); >+ >+# Tests for Koha::Patrons::Import::import_patrons() >+# Given ... nothing much. When ... Then ... >+my $result = Koha::Patrons::Import::import_patrons(undef); >+is($result, undef, 'Got the expected undef from import_patrons with nothing much'); >+ >+# Given ... some params but no file handle. >+my $params_0 = { some_stuff => 'random stuff', }; >+ >+# When ... Then ... >+my $result_0 = Koha::Patrons::Import::import_patrons($params_0); >+is($result_0, undef, 'Got the expected undef from import_patrons with no file handle'); >+ >+# Given ... a file handle to file with headers only. >+my $csv_headers = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password'; >+my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,16/10/1965,CPL,PT,28/12/2014,01/07/2015,jjenkins0,DPQILy'; >+ >+my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line); >+open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!"; >+my $params_1 = { file => $handle_1, }; >+ >+# When ... >+my $result_1 = Koha::Patrons::Import::import_patrons($params_1); >+ >+# Then ... >+is($result_1->{imported}, 1, 'Got the expected 1 imported result from import_patrons with no matchpoint defined'); >+is($result_1->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons with no matchpoint defined'); >+ >+# Given ... a valid file handle, a bad matchpoint resulting in invalid card number >+my $filename_2 = make_csv($temp_dir, $csv_headers, $csv_one_line); >+open(my $handle_2, "<", $filename_2) or die "cannot open < $filename_2: $!"; >+my $params_2 = { file => $handle_2, matchpoint => 'SHOW_BCODE', }; >+ >+# When ... >+my $result_2 = Koha::Patrons::Import::import_patrons($params_2); >+ >+# Then ... >+is($result_2->{imported}, 0, 'Got the expected 0 imported result from import_patrons with no matchpoint defined'); >+is($result_2->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with no matchpoint defined'); >+is($result_2->{errors}->[0]->{invalid_cardnumber}, 1, 'Got the expected invalid card number from import patrons with invalid card number'); >+ >+# Given ... valid file handle, good matchpoint but same input as prior test. >+my $filename_3 = make_csv($temp_dir, $csv_headers, $csv_one_line); >+open(my $handle_3, "<", $filename_3) or die "cannot open < $filename_3: $!"; >+my $params_3 = { file => $handle_3, matchpoint => 'cardnumber', }; >+ >+# When ... >+my $result_3 = Koha::Patrons::Import::import_patrons($params_3); >+ >+# Then ... >+is($result_3->{imported}, 0, 'Got the expected 0 imported result from import_patrons with duplicate userid'); >+is($result_3->{invalid}, 1, 'Got the expected 1 invalid result from import_patrons with duplicate userid'); >+is($result_3->{errors}->[0]->{duplicate_userid}, 1, 'Got the expected duplicate userid error from import patrons with duplicate userid'); >+ >+# Given ... a new input and mocked C4::Context >+my $context = new Test::MockModule('C4::Context'); >+$context->mock('preference', sub { my ($mod, $meth) = @_; if ( $meth eq 'ExtendedPatronAttributes' ) { return 1; } }); >+ >+my $new_input_line = '1001,Donna,Sullivan,Mrs,Henry,DS,59,Court,Burrows,Reading,Salt Lake City,Pennsylvania,19605,United States,hsullivan1@purevolume.com,3-(864)009-3006,7-(291)885-8423,1-(879)095-5038,19/09/1970,LPL,PT,04/03/2015,01/07/2015,hsullivan1,8j6P6Dmap'; >+my $filename_4 = make_csv($temp_dir, $csv_headers, $new_input_line); >+open(my $handle_4, "<", $filename_4) or die "cannot open < $filename_4: $!"; >+my $params_4 = { file => $handle_4, matchpoint => 'cardnumber', }; >+ >+# When ... Then ... >+my $result_4 = Koha::Patrons::Import::import_patrons($params_4); >+is($result_4->{imported}, 1, 'Got the expected 1 imported result from import_patrons with extended user'); >+ >+# ###### Test utility ########### >+sub make_csv { >+ my ($temp_dir, @lines) = @_; >+ >+ my ($fh, $filename) = tempfile( DIR => $temp_dir) or die $!; >+ print $fh $_."\r\n" foreach @lines; >+ close $fh or die $!; >+ >+ return $filename; >+} >+ >+done_testing(); >+ >+1; >\ No newline at end of file >-- >2.1.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 12598
:
29807
|
29808
|
29809
|
29939
|
30755
|
30780
|
35557
|
35558
|
35559
|
35560
|
35848
|
35849
|
35850
|
35851
|
35964
|
36684
|
36685
|
36687
|
36688
|
36690
|
36692
|
36693
|
36694
|
36695
|
36696
|
39124
|
39125
|
39126
|
39127
|
39128
|
41790
|
41791
|
41792
|
41793
|
41794
|
44065
|
44066
|
44067
|
44068
|
44069
|
48753
|
48754
|
48755
|
48756
|
48757
|
50693
|
50694
|
50695
|
50696
|
50697
|
50698
|
50699
|
50700
|
50704
|
51122
|
51357
|
51358
|
51359
|
51360
|
51361
|
51362
|
51363
|
51364
|
51365
|
51366
|
51367
|
51368
|
51369
|
51370
|
51371
|
51372
|
52323
|
52324
|
52325
|
52326
|
52327
|
52328
|
52329
|
52330
|
52331
|
52332
|
52333
|
52540
|
64437
|
64438
|
64855
|
65214
|
65215
|
65216
|
65217
|
65218
|
65819
|
65820
|
65821
|
65822
|
65823
|
65824
|
66353
|
66354
|
66355
|
66356
|
66357
|
66358
|
66359
|
66575
|
66576
|
66577
|
66578
|
66579
|
66580
|
66581
|
66582
|
67276
|
67277
|
70265
|
70266
|
71755
|
71756
|
71757
|
71758
|
71759
|
71760
|
71761
|
71762
|
71763
|
71764
|
71765
|
71766