Bugzilla – Attachment 113121 Details for
Bug 14708
The patron set as the anonymous patron should not be deletable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14708: (QA follow-up) Add tests
Bug-14708-QA-follow-up-Add-tests.patch (text/plain), 3.80 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-11-05 14:56:58 UTC
(
hide
)
Description:
Bug 14708: (QA follow-up) Add tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-11-05 14:56:58 UTC
Size:
3.80 KB
patch
obsolete
>From 5ca69c05cdb14cffaa0665c11580413fb4ffd19f Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 5 Nov 2020 11:53:43 -0300 >Subject: [PATCH] Bug 14708: (QA follow-up) Add tests > >This patch adds tests for the change. It also simplifies the delete() >method structure a bit. It fixes the error 500 the tests were raising. > >To test: >1. Run: > $ kshell > k$ prove t/db_dependent/api/v1/patrons.t >=> FAIL: Tests fail! >2. Apply this patch >3. Repeat 1 >=> SUCCESS: Tests pass! The new behaviour (code 403) is tested! >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/REST/V1/Patrons.pm | 47 +++++++++++++-------------------- > t/db_dependent/api/v1/patrons.t | 8 +++++- > 2 files changed, 26 insertions(+), 29 deletions(-) > >diff --git a/Koha/REST/V1/Patrons.pm b/Koha/REST/V1/Patrons.pm >index c3916d6414a..5eba4bdee34 100644 >--- a/Koha/REST/V1/Patrons.pm >+++ b/Koha/REST/V1/Patrons.pm >@@ -304,40 +304,31 @@ Controller function that handles deleting a Koha::Patron object > sub delete { > my $c = shift->openapi->valid_input or return; > >- my $patron; >+ my $patron = Koha::Patrons->find( $c->validation->param('patron_id') ); >+ >+ unless ( $patron ) { >+ return $c->render( >+ status => 404, >+ openapi => { error => "Patron not found" } >+ ); >+ } > > return try { >- $patron = Koha::Patrons->find( $c->validation->param('patron_id') ); > >- # check if loans, reservations, debarrment, etc. before deletion! >- try { >- $patron->delete; >- return $c->render( >- status => 204, >- openapi => q{} >- ); >- } catch { >- if ( $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { >- return $c->render( >- status => 403, >- openapi => { error => "Anonymous patron cannot be deleted" } >- ); >- } >- else { >- $c->unhandled_exception($_); >- } >- }; >- } >- catch { >- unless ($patron) { >+ $patron->delete; >+ return $c->render( >+ status => 204, >+ openapi => q{} >+ ); >+ } catch { >+ if ( blessed $_ && $_->isa('Koha::Exceptions::Patron::FailedDeleteAnonymousPatron') ) { > return $c->render( >- status => 404, >- openapi => { error => "Patron not found" } >+ status => 403, >+ openapi => { error => "Anonymous patron cannot be deleted" } > ); > } >- else { >- $c->unhandled_exception($_); >- } >+ >+ $c->unhandled_exception($_); > }; > } > >diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t >index 8d99f5ea81a..40993191a79 100755 >--- a/t/db_dependent/api/v1/patrons.t >+++ b/t/db_dependent/api/v1/patrons.t >@@ -405,7 +405,7 @@ subtest 'delete() tests' => sub { > $schema->storage->txn_rollback; > > subtest 'librarian access test' => sub { >- plan tests => 5; >+ plan tests => 8; > > $schema->storage->txn_begin; > >@@ -425,6 +425,12 @@ subtest 'delete() tests' => sub { > > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); > >+ t::lib::Mocks::mock_preference('AnonymousPatron', $patron->borrowernumber); >+ $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) >+ ->status_is(403, 'Anonymous patron cannot be deleted') >+ ->json_is( { error => 'Anonymous patron cannot be deleted' } ); >+ >+ t::lib::Mocks::mock_preference('AnonymousPatron', 0); # back to default > $t->delete_ok("//$userid:$password@/api/v1/patrons/" . $patron->borrowernumber) > ->status_is(204, 'SWAGGER3.2.4') > ->content_is('', 'SWAGGER3.3.4'); >-- >2.29.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 14708
:
85766
|
85770
|
85783
|
85789
|
103026
|
103027
|
103028
|
103922
|
105024
|
105025
|
105026
|
105027
|
105028
|
105029
|
105184
|
105185
|
105186
|
105187
|
105188
|
105189
|
112830
|
112831
|
112922
| 113121