Bugzilla – Attachment 74231 Details for
Bug 20568
Add API key management interface for patrons
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20568: Unit tests
Bug-20568-Unit-tests.patch (text/plain), 4.15 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-04-16 13:06:12 UTC
(
hide
)
Description:
Bug 20568: Unit tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-04-16 13:06:12 UTC
Size:
4.15 KB
patch
obsolete
>From e450b41bd8adfe3e0e3894c5f071f9c30302004c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sat, 14 Apr 2018 17:37:56 -0300 >Subject: [PATCH] Bug 20568: Unit tests > >This patch adds unit tests for the introduced classes: Koha::ApiKey(s). > >To test: >- Apply this patch >- Run > $ kshell > k$ prove t/db_dependent/Koha/ApiKeys.t >=> FAIL: Tests fail because the feature is not implemented. >--- > t/db_dependent/Koha/ApiKeys.t | 110 ++++++++++++++++++++++++++++++++++ > 1 file changed, 110 insertions(+) > create mode 100755 t/db_dependent/Koha/ApiKeys.t > >diff --git a/t/db_dependent/Koha/ApiKeys.t b/t/db_dependent/Koha/ApiKeys.t >new file mode 100755 >index 0000000000..b3bd2965a2 >--- /dev/null >+++ b/t/db_dependent/Koha/ApiKeys.t >@@ -0,0 +1,110 @@ >+#!/usr/bin/perl >+ >+# 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 => 2; >+use Test::Exception; >+ >+use t::lib::TestBuilder; >+ >+use Data::Printer colored => 1; >+ >+BEGIN { >+ use_ok('Koha::ApiKeys'); >+} >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'store() tests' => sub { >+ >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ my $print_error = $schema->storage->dbh->{PrintError}; >+ $schema->storage->dbh->{PrintError} = 0; >+ >+ Koha::ApiKeys->search->delete; >+ >+ my $patron_1 = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $description = 'Coral API key'; >+ my $the_api_key = 'An_API_Key'; >+ my $api_key = Koha::ApiKey->new({ >+ patron_id => $patron_1->id, >+ value => $the_api_key, >+ description => $description >+ })->store; >+ # re-read from DB >+ $api_key->discard_changes; >+ >+ is( ref($api_key), 'Koha::ApiKey' ); >+ is( $api_key->patron_id, $patron_1->id, 'FK is matched' ); >+ is( $api_key->value, $the_api_key, 'The passed API key is preserved' ); >+ is( $api_key->description, $description, 'Description is correctly stored' ); >+ is( $api_key->active, 1, 'Key is active by default' ); >+ >+ my $patron_to_delete = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $deleted_id = $patron_to_delete->id; >+ $patron_to_delete->delete; >+ >+ throws_ok >+ { Koha::ApiKey->new({ patron_id => $deleted_id })->store } >+ 'Koha::Exceptions::Object::FKConstraint', >+ 'Invalid patron ID raises exception'; >+ is( >+ $@->message, >+ 'Broken FK constraint', >+ 'Exception message is correct' >+ ); >+ is( >+ $@->broken_fk, >+ 'patron_id', >+ 'Exception field is correct' >+ ); >+ >+ my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); >+ >+ throws_ok >+ { Koha::ApiKey->new({ >+ patron_id => $patron_2->id, >+ value => $the_api_key, >+ description => $description >+ })->store } >+ 'Koha::Exceptions::Object::DuplicateID', >+ 'Duplicate API key raises exception'; >+ is( >+ $@->message, >+ 'Duplicate ID', >+ 'Exception message is correct' >+ ); >+ is( >+ $@->duplicate_id, >+ 'value', >+ 'Exception field is correct' >+ ); >+ $schema->storage->dbh->{PrintError} = $print_error; >+ >+ $api_key = Koha::ApiKey->new({ patron_id => $patron_2->id, description => $description })->store; >+ $api_key->discard_changes; >+ >+ ok( defined $api_key->value && $api_key->value ne '' && length( $api_key->value ) > 1, >+ 'API key randomly generated' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.17.0
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 20568
:
74179
|
74180
|
74229
|
74230
|
74231
|
74232
|
74233
|
74234
|
74235
|
74236
|
74248
|
74254
|
74255
|
74256
|
74257
|
74258
|
74259
|
74343
|
74344
|
74345
|
74346
|
74347
|
74348
|
74388
|
74389
|
74434
|
74454
|
74476
|
74477
|
74478
|
74479
|
74480
|
74481
|
74482
|
74486
|
74487
|
74488
|
74489
|
74490
|
74491
|
74492
|
74493
|
74494
|
74495
|
74496
|
74980
|
74981
|
75023
|
75186
|
75187
|
75188