From 913237b92bcd9278cd3608ad4d6d1048bda1d1d0 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sun, 8 Jul 2018 14:19:10 -0400 Subject: [PATCH 1/1] LP 1780660: Add more workstation functions to OpenILS::Utils::TestUtils. Add methods find_or_register_workstation($name, $lib) and find_workstation($name, $lib) to OpenILS::Utils::TestUtils. These can be used when writing tests or other scripts to find or create workstations. The following Perl live tests were updated to use the new methods rather than their hand-rolled versions: * 14-lp1499123_csp_ignore_proximity.t * 18-lp1592891_sip_standing_penalties.t * 19-lp1306666-abort-transit-copy-status.t * 25-lp1694058-multiple-hold-placement.t Testing this is very simple: 1. Install Evergreen from this branch. 2. Load the Concerto dataset. 3. Start Evergreen services with osrf_control. 4. cd to the perlmods source directory. 5. Do 'make livecheck' and see that all tests pass, particularly the 4 mentioned above. Signed-off-by: Jason Stephenson Signed-off-by: Mike Rylander --- .../perlmods/lib/OpenILS/Utils/TestUtils.pm | 23 ++++++++++++++++++ .../14-lp1499123_csp_ignore_proximity.t | 17 +------------ .../18-lp1592891_sip_standing_penalties.t | 17 +------------ .../19-lp1306666-abort-transit-copy-status.t | 21 ++-------------- .../25-lp1694058-multiple-hold-placement.t | 24 +------------------ 5 files changed, 28 insertions(+), 74 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/TestUtils.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/TestUtils.pm index 443857c89d..6d6679012a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/TestUtils.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/TestUtils.pm @@ -8,6 +8,20 @@ use strict; use warnings; my $apputils = 'OpenILS::Application::AppUtils'; +sub find_workstation { + my ($self,$name,$lib) = (shift,shift,shift); + my $resp = $apputils->simplereq( + 'open-ils.actor', + 'open-ils.actor.workstation.list', + $self->authtoken, + $lib + ); + if ($resp->{$lib}) { + return scalar(grep {$_->name() eq $name} @{$resp->{$lib}}); + } + return 0; +} + sub register_workstation { my ($self,$name,$lib) = (shift,shift,shift); my $resp = $apputils->simplereq( @@ -17,6 +31,15 @@ sub register_workstation { return $resp; } +sub find_or_register_workstation { + my ($self,$name,$lib) = (shift,shift,shift); + my $workstation = $self->find_workstation($name, $lib); + if (!$workstation) { + $workstation = $self->register_workstation($name, $lib); + } + return $workstation; +} + sub do_checkout { my ($self,$args) = (shift,shift); my $resp = $apputils->simplereq( diff --git a/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t b/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t index 2b993bcfeb..709fcb02e0 100644 --- a/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t +++ b/Open-ILS/src/perlmods/live_t/14-lp1499123_csp_ignore_proximity.t @@ -14,21 +14,6 @@ our $apputils = 'OpenILS::Application::AppUtils'; use constant WORKSTATION_NAME => 'BR1-test-lp1499123_csp_ignore_proximity.t'; use constant WORKSTATION_LIB => 4; -# Because this may run multiple times, without a DB reload, we search -# for the workstation before registering it. -sub find_workstation { - my $r = $apputils->simplereq( - 'open-ils.actor', - 'open-ils.actor.workstation.list', - $script->authtoken, - WORKSTATION_LIB - ); - if ($r->{&WORKSTATION_LIB}) { - return scalar(grep {$_->name() eq WORKSTATION_NAME} @{$r->{&WORKSTATION_LIB}}); - } - return 0; -} - sub retrieve_staff_chr { my $e = shift; my $staff_chr = $e->retrieve_config_standing_penalty(25); @@ -158,7 +143,7 @@ $script->authenticate({ ok($script->authtoken, 'Initial Login'); SKIP: { - my $ws = find_workstation(); + my $ws = $script->find_workstation(WORKSTATION_NAME, WORKSTATION_LIB); skip 'Workstation exists', 1 if ($ws); $ws = $script->register_workstation(WORKSTATION_NAME, WORKSTATION_LIB) unless ($ws); ok(! ref $ws, 'Registered a new workstation'); diff --git a/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t b/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t index bf695bce55..ca8754eb19 100644 --- a/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t +++ b/Open-ILS/src/perlmods/live_t/18-lp1592891_sip_standing_penalties.t @@ -18,21 +18,6 @@ our $apputils = 'OpenILS::Application::AppUtils'; use constant WORKSTATION_NAME => 'BR1-test-lp1592891_sip_standing_penalties.t'; use constant WORKSTATION_LIB => 4; -# Because this may run multiple times, without a DB reload, we search -# for the workstation before registering it. -sub find_workstation { - my $r = $apputils->simplereq( - 'open-ils.actor', - 'open-ils.actor.workstation.list', - $script->authtoken, - WORKSTATION_LIB - ); - if ($r->{&WORKSTATION_LIB}) { - return scalar(grep {$_->name() eq WORKSTATION_NAME} @{$r->{&WORKSTATION_LIB}}); - } - return 0; -} - sub retrieve_penalty { my $e = shift; my $penalty = shift; @@ -124,7 +109,7 @@ $script->authenticate({ ok($script->authtoken, 'Initial Login'); SKIP: { - my $ws = find_workstation(); + my $ws = $script->find_workstation(WORKSTATION_NAME, WORKSTATION_LIB); skip 'Workstation exists', 1 if ($ws); $ws = $script->register_workstation(WORKSTATION_NAME, WORKSTATION_LIB) unless ($ws); ok(! ref $ws, 'Registered a new workstation'); diff --git a/Open-ILS/src/perlmods/live_t/19-lp1306666-abort-transit-copy-status.t b/Open-ILS/src/perlmods/live_t/19-lp1306666-abort-transit-copy-status.t index 699716cae2..470ca2bf4c 100644 --- a/Open-ILS/src/perlmods/live_t/19-lp1306666-abort-transit-copy-status.t +++ b/Open-ILS/src/perlmods/live_t/19-lp1306666-abort-transit-copy-status.t @@ -18,23 +18,6 @@ use constant { CBARCODE => 'CONC4000036' }; -# Because this may run multiple times, without a DB reload, we search -# for the workstation before registering it. Takes an authtoken, the -# id of the workstation lib, and the name of the workstation. -sub find_workstation { - my ($authtoken, $lib, $workstation) = @_; - my $r = $apputils->simplereq( - 'open-ils.actor', - 'open-ils.actor.workstation.list', - $authtoken, - $lib - ); - if ($r->{$lib}) { - return scalar(grep {$_->name() eq $workstation} @{$r->{$lib}}); - } - return 0; -} - # Store authtokens my @authtoken = (); @@ -46,7 +29,7 @@ $authtoken[0] = $script->authenticate({ }); # Register workstation at BR1. -unless (find_workstation($authtoken[0], BR1_ID, BR1_WORKSTATION)) { +unless ($script->find_workstation(BR1_WORKSTATION, BR1_ID)) { $script->register_workstation(BR1_WORKSTATION, BR1_ID); } @@ -69,7 +52,7 @@ $authtoken[1] = $script->authenticate({ }); # Register workstation at BR3. -unless (find_workstation($authtoken[1], BR3_ID, BR3_WORKSTATION)) { +unless ($script->find_workstation(BR3_WORKSTATION, BR3_ID)) { $script->register_workstation(BR3_WORKSTATION, BR3_ID); } diff --git a/Open-ILS/src/perlmods/live_t/25-lp1694058-multiple-hold-placement.t b/Open-ILS/src/perlmods/live_t/25-lp1694058-multiple-hold-placement.t index 942aab2c8a..5e74c9cf37 100644 --- a/Open-ILS/src/perlmods/live_t/25-lp1694058-multiple-hold-placement.t +++ b/Open-ILS/src/perlmods/live_t/25-lp1694058-multiple-hold-placement.t @@ -20,28 +20,6 @@ use constant { COPY_ID => 2503, }; -# Because this may run multiple times, without a DB reload, we search -# for the workstation before registering it. Takes an authtoken, the -# id of the workstation lib, and the name of the workstation. -sub find_or_register_workstation { - my ($authtoken, $lib, $workstation) = @_; - my $ws; - my $r = $U->simplereq( - 'open-ils.actor', - 'open-ils.actor.workstation.list', - $authtoken, - $lib - ); - if ($r && $r->{$lib}) { - $ws = grep {$_->name() eq $workstation} @{$r->{$lib}}; - } - unless ($ws) { - $ws = $script->register_workstation($workstation, $lib); - } - return $ws; -} - - # Keep track of hold ids, so we can cancel them later. my @holds = (); @@ -57,7 +35,7 @@ ok( ); # Register workstation. -my $ws = find_or_register_workstation($authtoken, BR1_ID, BR1_WORKSTATION); +my $ws = $script->find_or_register_workstation(BR1_WORKSTATION, BR1_ID); ok( ! ref $ws, 'Found or registered workstation' -- 2.43.2