Bugzilla – Attachment 81756 Details for
Bug 20996
Fix API response time on ILL request endpoint
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20996: Fix unit tests
Bug-20996-Fix-unit-tests.patch (text/plain), 8.03 KB, created by
Josef Moravec
on 2018-10-31 16:46:14 UTC
(
hide
)
Description:
Bug 20996: Fix unit tests
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2018-10-31 16:46:14 UTC
Size:
8.03 KB
patch
obsolete
>From 3d3e7f472fdce5b3d884a889633e5c30fd87f262 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Wed, 4 Jul 2018 13:13:33 +0100 >Subject: [PATCH] Bug 20996: Fix unit tests > >- Remove unit tests relating to TO_JSON >- Add tests for new explicit embedding >- Modify tests relating to now deprecated brw_cat > >Signed-off-by: Magnus Enger <magnus@libriotech.no> > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > t/db_dependent/Illrequests.t | 75 +++---------------------------------- > t/db_dependent/api/v1/illrequests.t | 19 +++++----- > 2 files changed, 14 insertions(+), 80 deletions(-) > >diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t >index 1411eac..a9f933a 100644 >--- a/t/db_dependent/Illrequests.t >+++ b/t/db_dependent/Illrequests.t >@@ -28,7 +28,7 @@ use Test::MockObject; > use Test::MockModule; > use Test::Exception; > >-use Test::More tests => 11; >+use Test::More tests => 10; > > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; >@@ -536,7 +536,7 @@ subtest 'Backend core methods' => sub { > > subtest 'Helpers' => sub { > >- plan tests => 9; >+ plan tests => 7; > > $schema->storage->txn_begin; > >@@ -564,35 +564,26 @@ subtest 'Helpers' => sub { > $config->set_series('getPrefixes', > { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, > { A => "ATEST", C => "CBAR", default => "DEFAULT" }); >- is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR", >- "getPrefix: brw_cat"); >- $config->set_series('getPrefixes', >- { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, >- { A => "ATEST", C => "CBAR", default => "DEFAULT" }); > is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", > "getPrefix: branch"); > $config->set_series('getPrefixes', > { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, > { A => "ATEST", C => "CBAR", default => "DEFAULT" }); >- is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT", >+ is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", > "getPrefix: default"); > $config->set_always('getPrefixes', {}); >- is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "", >+ is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", > "getPrefix: the empty prefix"); > > # id_prefix > $config->set_series('getPrefixes', > { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, >- { A => "ATEST", C => "CBAR", default => "DEFAULT" }); >- is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat"); >- $config->set_series('getPrefixes', >- { CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, > { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); > is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); > $config->set_series('getPrefixes', > { CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, > { AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); >- is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default"); >+ is($illrq_obj->id_prefix, "", "id_prefix: default"); > > # requires_moderation > $illrq_obj->status('NEW')->store; >@@ -804,59 +795,3 @@ subtest 'Checking Limits' => sub { > > $schema->storage->txn_rollback; > }; >- >-subtest 'TO_JSON() tests' => sub { >- >- plan tests => 10; >- >- my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); >- >- # Mock ->capabilities >- $illreqmodule->mock( 'capabilities', sub { return 'capable'; } ); >- >- # Mock ->metadata >- $illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } ); >- >- $schema->storage->txn_begin; >- >- my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >- my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >- my $illreq = $builder->build_object( >- { >- class => 'Koha::Illrequests', >- value => { >- branchcode => $library->branchcode, >- borrowernumber => $patron->borrowernumber >- } >- } >- ); >- my $illreq_json = $illreq->TO_JSON; >- is( $illreq_json->{patron}, >- undef, '%embed not passed, no \'patron\' attribute' ); >- is( $illreq_json->{metadata}, >- undef, '%embed not passed, no \'metadata\' attribute' ); >- is( $illreq_json->{capabilities}, >- undef, '%embed not passed, no \'capabilities\' attribute' ); >- is( $illreq_json->{library}, >- undef, '%embed not passed, no \'library\' attribute' ); >- >- $illreq_json = $illreq->TO_JSON( >- { patron => 1, metadata => 1, capabilities => 1, library => 1 } ); >- is( $illreq_json->{patron}->{firstname}, >- $patron->firstname, >- '%embed passed, \'patron\' attribute correct (firstname)' ); >- is( $illreq_json->{patron}->{surname}, >- $patron->surname, >- '%embed passed, \'patron\' attribute correct (surname)' ); >- is( $illreq_json->{patron}->{cardnumber}, >- $patron->cardnumber, >- '%embed passed, \'patron\' attribute correct (cardnumber)' ); >- is( $illreq_json->{metadata}, >- 'metawhat?', '%embed passed, \'metadata\' attribute correct' ); >- is( $illreq_json->{capabilities}, >- 'capable', '%embed passed, \'capabilities\' attribute correct' ); >- is( $illreq_json->{library}->{branchcode}, >- $library->branchcode, '%embed not passed, no \'library\' attribute' ); >- >- $schema->storage->txn_rollback; >-}; >diff --git a/t/db_dependent/api/v1/illrequests.t b/t/db_dependent/api/v1/illrequests.t >index b0850e9..b58d529 100644 >--- a/t/db_dependent/api/v1/illrequests.t >+++ b/t/db_dependent/api/v1/illrequests.t >@@ -38,7 +38,7 @@ my $t = Test::Mojo->new('Koha::REST::V1'); > > subtest 'list() tests' => sub { > >- plan tests => 15; >+ plan tests => 18; > > my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); > # Mock ->capabilities >@@ -67,6 +67,7 @@ subtest 'list() tests' => sub { > { > class => 'Koha::Illrequests', > value => { >+ backend => 'FreeForm', > branchcode => $library->branchcode, > borrowernumber => $patron->borrowernumber > } >@@ -77,20 +78,18 @@ subtest 'list() tests' => sub { > $tx = $t->ua->build_tx( GET => '/api/v1/illrequests' ); > $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); > $tx->req->env( { REMOTE_ADDR => $remote_address } ); >- $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->TO_JSON ] ); >+ $t->request_ok($tx)->status_is(200)->json_is( [ $illrequest->unblessed ] ); > > # One illrequest created, returned with augmented data > $tx = $t->ua->build_tx( GET => > '/api/v1/illrequests?embed=patron,library,capabilities,metadata' ); > $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); > $tx->req->env( { REMOTE_ADDR => $remote_address } ); >- $t->request_ok($tx)->status_is(200)->json_is( >- [ >- $illrequest->TO_JSON( >- { patron => 1, library => 1, capabilities => 1, metadata => 1 } >- ) >- ] >- ); >+ $t->request_ok($tx)->status_is(200) >+ ->json_has( '/0/patron', $patron->unblessed ) >+ ->json_has( '/0/capabilities', 'capable' ) >+ ->json_has( '/0/library', $library->unblessed ) >+ ->json_has( '/0/metadata', 'metawhat?' ); > > # Create another ILL request > my $illrequest2 = $builder->build_object( >@@ -108,7 +107,7 @@ subtest 'list() tests' => sub { > $tx->req->cookies( { name => 'CGISESSID', value => $session_id } ); > $tx->req->env( { REMOTE_ADDR => $remote_address } ); > $t->request_ok($tx)->status_is(200) >- ->json_is( [ $illrequest->TO_JSON, $illrequest2->TO_JSON ] ); >+ ->json_is( [ $illrequest->unblessed, $illrequest2->unblessed ] ); > > # Warn on unsupported query parameter > $tx = $t->ua->build_tx( GET => '/api/v1/illrequests?request_blah=blah' ); >-- >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 20996
:
76687
|
76688
|
76705
|
77100
|
79379
|
79576
|
79583
|
79584
|
79585
|
79586
|
79587
|
79588
|
79589
|
79590
|
79591
|
79592
|
81715
|
81716
|
81717
|
81718
|
81719
|
81720
|
81747
|
81748
|
81749
|
81750
|
81751
|
81752
|
81753
|
81755
| 81756 |
81757
|
81758
|
81759
|
81760
|
81761
|
81908
|
81909
|
81928
|
81967
|
81994
|
81996
|
81997
|
81998