Bugzilla – Attachment 170565 Details for
Bug 36831
Add support for .txt files to the KBART import tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36831: Add unit test
Bug-36831-Add-unit-test.patch (text/plain), 8.70 KB, created by
Matt Blenkinsop
on 2024-08-21 12:52:35 UTC
(
hide
)
Description:
Bug 36831: Add unit test
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-08-21 12:52:35 UTC
Size:
8.70 KB
patch
obsolete
>From d09d60457dfed07742e5b07bb818c4c7976a988e Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Wed, 3 Jul 2024 09:53:26 +0000 >Subject: [PATCH] Bug 36831: Add unit test > >prove t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t >--- > .../Koha/BackgroundJob/ImportKBARTFile.t | 66 +++++++++++-------- > 1 file changed, 40 insertions(+), 26 deletions(-) > >diff --git a/t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t b/t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t >index e0abbb283a3..c018a9414ba 100755 >--- a/t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t >+++ b/t/db_dependent/Koha/BackgroundJob/ImportKBARTFile.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::MockModule; > use Test::Warn; > >@@ -39,7 +39,6 @@ subtest 'enqueue' => sub { > > $schema->storage->txn_begin; > >- # FIXME: Should be an exception > my $job_id = Koha::BackgroundJob::ImportKBARTFile->new->enqueue(); > is( $job_id, undef, 'Nothing enqueued if missing file param' ); > >@@ -50,15 +49,13 @@ subtest 'calculate_chunked_params_size' => sub { > > plan tests => 2; > >- my $max_number_of_lines = >- Koha::BackgroundJob::ImportKBARTFile::calculate_chunked_params_size( 500000, 100000, 50000 ); >+ my $max_number_of_lines = Koha::ERM::EHoldings::Title::calculate_chunked_params_size( 500000, 100000, 50000 ); > is( $max_number_of_lines, 7500, 'Number of lines calculated correctly' ); >- my $max_number_of_lines2 = >- Koha::BackgroundJob::ImportKBARTFile::calculate_chunked_params_size( 400000, 100000, 60000 ); >+ my $max_number_of_lines2 = Koha::ERM::EHoldings::Title::calculate_chunked_params_size( 400000, 100000, 60000 ); > is( $max_number_of_lines2, 11250, 'Number of lines calculated correctly' ); > }; > >-subtest 'format_title' => sub { >+subtest '_format_title' => sub { > > plan tests => 4; > >@@ -67,7 +64,7 @@ subtest 'format_title' => sub { > coverage_notes => 'Test notes' > }; > >- my $formatted_title = Koha::BackgroundJob::ImportKBARTFile::format_title($title); >+ my $formatted_title = Koha::BackgroundJob::ImportKBARTFile::_format_title($title); > > is( $formatted_title->{external_id}, 1, 'external_id formatted correctly' ); > is( $formatted_title->{notes}, 'Test notes', 'notes formatted correctly' ); >@@ -77,7 +74,7 @@ subtest 'format_title' => sub { > > subtest 'read_file' => sub { > >- plan tests => 7; >+ plan tests => 6; > > my $file = { > filename => 'Test_file.csv', >@@ -88,7 +85,7 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ) > }; > >- my ( $column_headers, $lines, $error ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); >+ my ( $column_headers, $lines, $error ) = Koha::ERM::EHoldings::Title::read_file($file); > > is( @{$column_headers}, 25, '25 column headers found' ); > is( @{$column_headers}[0], 'publication_title', 'First header correctly extracted' ); >@@ -112,7 +109,24 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ], > 'Line correctly identified' > ); >+}; >+ >+subtest '_detect_delimiter_and_quote' => sub { >+ >+ plan tests => 3; >+ >+ my $file = { >+ filename => 'Test_file.txt', >+ file_content => encode_base64( >+ 'publication_title,print_identifier,online_identifier,date_first_issue_online,num_first_vol_online,num_first_issue_online,date_last_issue_online,num_last_vol_online,num_last_issue_online,title_url,first_author,title_id,embargo_info,coverage_depth,coverage_notes,publisher_name,publication_type,date_monograph_published_print,date_monograph_published_online,monograph_volume,monograph_edition,first_editor,parent_publication_title_id,preceding_publication_title_id,access_type >+Nature Plants,,2055-0278,2015-01,1,1,,,,https://www.nature.com/nplants,,4aaa7,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P >+Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bbb0,,fulltext,Hybrid (Open Choice),Nature Publishing Group UK,serial,,,,,,,,P' >+ ) >+ }; > >+ my ( $delimiter, $quote_char ) = Koha::ERM::EHoldings::Title::_detect_delimiter_and_quote($file); >+ is( $delimiter, ',', 'Comma delimiter identified' ); >+ is( $quote_char, '"', 'Quote character identified' ); > my $file2 = { > filename => 'Test_file2.csv', > file_content => encode_base64( >@@ -122,12 +136,12 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ) > }; > warning_is { >- Koha::BackgroundJob::ImportKBARTFile::read_file($file2); >+ Koha::ERM::EHoldings::Title::read_file($file2); > } > '2023, EIQ - QUO character not allowed, 157', 'Error message correctly reported'; > }; > >-subtest 'create_title_hash_from_line_data' => sub { >+subtest '_create_title_hash_from_line_data' => sub { > > plan tests => 2; > >@@ -140,14 +154,14 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ) > }; > >- my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); >+ my ( $column_headers, $lines ) = Koha::ERM::EHoldings::Title::read_file($file); > my @invalid_columns; > >- my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( >+ my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( > @{$lines}[0], $column_headers, > \@invalid_columns > ); >- my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( >+ my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( > @{$lines}[1], $column_headers, > \@invalid_columns > ); >@@ -211,7 +225,7 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > is_deeply( $title_from_line2, $line2_match, 'Title hash created correctly' ); > }; > >-subtest 'create_title_hash_from_line_data with invalid columns using csv' => sub { >+subtest '_create_title_hash_from_line_data with invalid columns using csv' => sub { > > plan tests => 2; > >@@ -224,14 +238,14 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ) > }; > >- my ( $column_headers, $lines ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); >+ my ( $column_headers, $lines ) = Koha::ERM::EHoldings::Title::read_file($file); > my @invalid_columns = ('invalid_column'); > >- my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( >+ my $title_from_line1 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( > @{$lines}[0], $column_headers, > \@invalid_columns > ); >- my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::create_title_hash_from_line_data( >+ my $title_from_line2 = Koha::BackgroundJob::ImportKBARTFile::_create_title_hash_from_line_data( > @{$lines}[1], $column_headers, > \@invalid_columns > ); >@@ -317,7 +331,7 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ) > }; > >- my ( $column_headers, $rows, $error ) = Koha::BackgroundJob::ImportKBARTFile::read_file($file); >+ my ( $column_headers, $rows, $error ) = Koha::ERM::EHoldings::Title::read_file($file); > my $data = { > column_headers => $column_headers, > rows => $rows, >@@ -373,7 +387,7 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > > my $module = Test::MockModule->new('Koha::BackgroundJob::ImportKBARTFile'); > $module->mock( >- 'create_title_hash_from_line_data', >+ '_create_title_hash_from_line_data', > sub { > my ( $row, $column_headers ) = @_; > >@@ -413,10 +427,10 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > $job3->messages, > [ > { >- 'type' => 'error', >- 'code' => 'no_title_found', >- 'title_id' => '12345', >- 'title' => '(Unknown)' >+ 'type' => 'error', >+ 'code' => 'no_title_found', >+ 'title_id' => '12345', >+ 'title' => '(Unknown)' > }, > { > 'code' => 'title_already_exists', >@@ -429,7 +443,7 @@ Nature Astronomy,,2397-3366,2017-01,1,1,,,,https://www.nature.com/natastron,,4bb > ); > > $module->mock( >- 'create_title_hash_from_line_data', >+ '_create_title_hash_from_line_data', > sub { > my ( $row, $column_headers ) = @_; > >-- >2.39.3 (Apple Git-146)
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 36831
:
166958
|
166959
|
166960
|
166961
|
166989
|
166990
|
166991
|
168431
|
168432
|
168433
|
168434
|
170549
|
170550
|
170551
|
170552
|
170562
|
170563
|
170564
| 170565