Bugzilla – Attachment 138881 Details for
Bug 27421
Porting tools/stage-marc-import.pl to BackgroundJob
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27421: Add tests
Bug-27421-Add-tests.patch (text/plain), 4.52 KB, created by
Jonathan Druart
on 2022-08-09 07:43:37 UTC
(
hide
)
Description:
Bug 27421: Add tests
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-08-09 07:43:37 UTC
Size:
4.52 KB
patch
obsolete
>From a2bdc22c355b9f6a2d8609e19dda9574d6f7af4a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 9 Aug 2022 09:30:43 +0200 >Subject: [PATCH] Bug 27421: Add tests > >--- > .../Koha/BackgroundJobs/StageMARCForImport.t | 132 ++++++++++++++++++ > 1 file changed, 132 insertions(+) > create mode 100644 t/db_dependent/Koha/BackgroundJobs/StageMARCForImport.t > >diff --git a/t/db_dependent/Koha/BackgroundJobs/StageMARCForImport.t b/t/db_dependent/Koha/BackgroundJobs/StageMARCForImport.t >new file mode 100644 >index 00000000000..7818807830c >--- /dev/null >+++ b/t/db_dependent/Koha/BackgroundJobs/StageMARCForImport.t >@@ -0,0 +1,132 @@ >+#!/usr/bin/perl >+ >+# Copyright 2022 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 => 3; >+use Test::MockModule; >+use JSON qw( encode_json decode_json ); >+ >+use Koha::Database; >+use Koha::BackgroundJobs; >+use Koha::BackgroundJob::StageMARCForImport; >+use Koha::BackgroundJob::MARCImportCommitBatch; >+use Koha::BackgroundJob::MARCImportRevertBatch; >+use Koha::Import::Records; >+use Koha::Exception; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+ >+my $builder = t::lib::TestBuilder->new; >+ >+$schema->storage->txn_begin; >+ >+my $biblio = $builder->build_sample_biblio; >+my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+my $import_batch_id; >+ >+subtest 'StageMARCForImport' => sub { >+ >+ plan tests => 4; >+ >+ my $job = Koha::BackgroundJob::StageMARCForImport->new( >+ { >+ status => 'new', >+ size => 1, >+ borrowernumber => $patron->borrowernumber, >+ type => 'stage_marc_for_import', >+ } >+ )->store; >+ $job = Koha::BackgroundJobs->find( $job->id ); >+ $job->process( >+ { >+ job_id => $job->id, >+ record_type => 'biblio', >+ encoding => 'UTF-8', >+ format => 'ISO2709', >+ filepath => 't/db_dependent/data/marc21/zebraexport/biblio/exported_records', >+ filename => 'some_records', >+ parse_items => 1, >+ } >+ ); >+ >+ my $report = decode_json($job->get_from_storage->data)->{report}; >+ is( $report->{num_items}, 138 ); >+ is( $report->{staged}, 178 ); >+ is( $report->{total}, 179 ); >+ is( $report->{import_errors}, 1 ); >+ $import_batch_id = $report->{import_batch_id}; >+ >+}; >+ >+subtest 'MARCImportCommitBatch' => sub { >+ >+ plan tests => 2; >+ >+ my $job = Koha::BackgroundJob::MARCImportCommitBatch->new( >+ { >+ status => 'new', >+ size => 1, >+ borrowernumber => $patron->borrowernumber, >+ type => 'marc_import_commit_batch' >+ } >+ )->store; >+ $job = Koha::BackgroundJobs->find( $job->id ); >+ $job->process( >+ { >+ job_id => $job->id, >+ import_batch_id => $import_batch_id, >+ frameworkcode => q{}, >+ } >+ ); >+ >+ my $report = decode_json( $job->get_from_storage->data )->{report}; >+ is( $report->{num_added}, 178 ); >+ is( $report->{num_items_added}, 138 ); >+ >+}; >+ >+subtest 'MARCImportRevertBatch' => sub { >+ >+ plan tests => 2; >+ >+ my $job = Koha::BackgroundJob::MARCImportRevertBatch->new( >+ { >+ status => 'new', >+ size => 1, >+ borrowernumber => $patron->borrowernumber, >+ type => 'marc_import_revert_batch' >+ } >+ )->store; >+ $job = Koha::BackgroundJobs->find( $job->id ); >+ $job->process( >+ { >+ job_id => $job->id, >+ import_batch_id => $import_batch_id, >+ } >+ ); >+ >+ my $report = decode_json( $job->get_from_storage->data )->{report}; >+ is( $report->{num_deleted}, 178 ); >+ is( $report->{num_items_deleted}, 138 ); >+ >+}; >+ >+$schema->storage->txn_rollback; >-- >2.25.1
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 27421
:
136127
|
136128
|
136129
|
136216
|
136217
|
136338
|
136339
|
138642
|
138643
|
138656
|
138657
|
138660
|
138881
|
139384
|
139385
|
139386
|
139387
|
139388
|
139448
|
139449
|
139450
|
139797
|
140205
|
140206
|
140207
|
140208
|
140223
|
140224
|
140225
|
140226
|
140227
|
140228
|
140229
|
140230
|
140231
|
140232
|
140233
|
140234
|
140759