first round of a circ script tester, fixed some typos
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Jun 2006 13:25:16 +0000 (13:25 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 9 Jun 2006 13:25:16 +0000 (13:25 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@4562 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/javascript/backend/circ/circ_permit_copy.js
Open-ILS/src/javascript/backend/penalty/patron_penalty.js
Open-ILS/src/support-scripts/test-scripts/circ_rules.pl [new file with mode: 0644]

index 582cc82..95d3d6f 100644 (file)
@@ -8,8 +8,6 @@ var copy                                        = environment.copy;
 var patron                             = environment.patron;
 var patronProfile              = patron.profile.name.toLowerCase();
 var copyStatus                 = copy.status.name.toLowerCase();
-var patronItemsOut     = environment.patronItemsOut;
-var patronFines                = environment.patronFines;
 var isRenewal                  = environment.isRenewal;
 
 
@@ -17,9 +15,7 @@ log_debug('circ_permit_copy: permit circ on ' +
        ' Copy: '                                       + copy.id + 
        ', Patron:'                                     + patron.id +
        ', Patron Username:'            + patron.usrname +
-       ', Patron copies: '             + patronItemsOut +
        ', Patron Library: '            + patron.home_ou.name +
-       ', Patron fines: '              + patronFines +
        ', Copy status: '                       + copyStatus +
        ', Copy location: '             + copy.location.name +
        ', Is Renewal: '                        + ( (isRenewal) ? "yes" : "no" ) +
@@ -27,10 +23,10 @@ log_debug('circ_permit_copy: permit circ on ' +
 
 
 
-if( copy.circulate == '0' ) 
+if( ! isTrue(copy.circulate) ) 
        result.events.push('COPY_CIRC_NOT_ALLOWED');
 
-if( copy.ref != '0' ) 
+if( isTrue(copy.ref) ) 
        result.events.push('COPY_IS_REFERENCE');
 
 
index 3fa1a92..e7d990d 100644 (file)
@@ -54,7 +54,7 @@ if( profile ) {
 
        /* check the overdue limit */
        if( profile.overdueLimit > 0 && patronOverdueCount > profile.overdueLimit )
-               result.fatalEvents.puth('PATRON_EXCEEDS_OVERDUE_COUNT');
+               result.fatalEvents.push('PATRON_EXCEEDS_OVERDUE_COUNT');
 
 } else {
        log_warn("profile has no configured information: " + patronProfile);
diff --git a/Open-ILS/src/support-scripts/test-scripts/circ_rules.pl b/Open-ILS/src/support-scripts/test-scripts/circ_rules.pl
new file mode 100644 (file)
index 0000000..3069cd9
--- /dev/null
@@ -0,0 +1,164 @@
+#/usr/bin/perl
+use strict; use warnings;
+use lib q|../../../perlmods/|;
+use OpenILS::Utils::ScriptRunner;
+require '../oils_header.pl';
+use vars qw/ $user $authtoken $apputils /;
+
+
+# ---------------------------------------------------------------------
+# SCRIPT VARS
+# ----------------------------------------------------------------------
+my $patronid                                   = 4;
+my $copyid                                             = 8000107;
+my $patron_items_out                   = 11;
+my $patron_overdue_count       = 11;
+my $patron_fines                               = 20;
+
+# these are not currently tested in the scripts
+my $is_renewal                                 = 0;
+my $is_non_cat                                 = 0;
+my $is_hold                                            = 0;
+my $non_cat_type                               = 1;
+# ---------------------------------------------------------------------
+
+
+
+
+my $bsconfig = shift;
+my $script = shift;
+my $path;
+
+($path, $script) = ($script =~ m#(/.*/)(.*)#);
+
+osrf_connect($bsconfig);
+
+my $evt                                = 'environment';
+my $fatal_events       = 'result.fatalEvents';
+my $info_events        = 'result.infoEvents';
+my $events                     = 'result.events';
+
+my $runner = load_runner();
+$runner->add_path($path);
+
+
+
+# ---------------------------------------------------------------------
+# Run the script
+# ---------------------------------------------------------------------
+print "\nLoading script: $script\n";
+print "\n" . '-'x70 . "\n";
+
+$runner->load($script);
+$runner->run or die "Script died: $@";
+
+
+
+# ---------------------------------------------------------------------
+# Print out any events that occurred
+# ---------------------------------------------------------------------
+print "\n" . '-'x70 . "\n";
+
+show_events( 'events', $runner->retrieve($events));
+show_events( 'fatal_events', $runner->retrieve($fatal_events));
+show_events( 'info_events', $runner->retrieve($info_events));
+
+
+sub show_events {
+       my $t = shift;
+       my $e = shift;
+       my @e;
+
+       if($e and @e = split(/,/, $e)) {
+               print "$t : $_\n" for @e;
+
+       } else {
+               print "No $t occurred\n";
+       } 
+}
+
+print "\n";
+
+
+
+# ---------------------------------------------------------------------
+# Fetch data and build the script runner
+# ---------------------------------------------------------------------
+
+sub load_runner {
+
+       my( $patron, $copy, $org, $e );
+
+
+       ($patron, $e) = $apputils->fetch_user($patronid);
+       oils_event_die($e);
+
+       ($org, $e) = $apputils->fetch_org_unit($patron->home_ou);       
+       oils_event_die($e);
+
+       $patron->home_ou($org);
+
+       ($copy, $e) = $apputils->fetch_copy($copyid);
+       oils_event_die($e);
+
+       my $groups = $apputils->fetch_permission_group_tree();
+       $patron->profile( _get_patron_profile($patron, $groups));
+
+       my $cp_stats = $apputils->fetch_copy_statuses();
+       $copy->status( _get_copy_status($copy, $cp_stats) );
+
+       my $runner = OpenILS::Utils::ScriptRunner->new;
+       
+       $runner->insert( "$evt.patronOverdueCount", $patron_overdue_count );
+       $runner->insert( "$evt.patronItemsOut", $patron_items_out );
+       $runner->insert( "$evt.patronFines", $patron_fines );
+       $runner->insert( "$evt.isRenewal", $is_renewal );
+       $runner->insert( "$evt.isNonCat", $is_non_cat );
+       $runner->insert( "$evt.isHold", $is_hold );
+       $runner->insert( "$evt.nonCatType", $non_cat_type );
+       $runner->insert( "$evt.patron", $patron );
+       $runner->insert( "$evt.copy", $copy );
+       $runner->insert( $fatal_events, [] );
+       $runner->insert( $info_events, [] );
+       $runner->insert( $events, [] );
+
+       # ---------------------------------------------------------------------
+       # Override the default log functions for convenience
+       # ---------------------------------------------------------------------
+       $runner->insert(log_activity    => sub { print "@_\n"; return 1;} );
+       $runner->insert(log_error               => sub { print "@_\n"; return 1;} );
+       $runner->insert(log_warn                => sub { print "@_\n"; return 1;} );
+       $runner->insert(log_info                => sub { print "@_\n"; return 1;} );
+       $runner->insert(log_debug               => sub { print "@_\n"; return 1;} );
+       $runner->insert(log_internal    => sub { print "@_\n"; return 1;} );
+       
+       return $runner;
+}
+
+
+# ---------------------------------------------------------------------
+# Utility code for fleshing objects
+# ---------------------------------------------------------------------
+sub _get_patron_profile { 
+       my( $patron, $group_tree ) = @_;
+       return $group_tree if ($group_tree->id eq $patron->profile);
+       return undef unless ($group_tree->children);
+       for my $child (@{$group_tree->children}) {
+               my $ret = _get_patron_profile( $patron, $child );
+               return $ret if $ret;
+       }
+       return undef;
+}
+
+
+sub _get_copy_status {
+       my( $copy, $cstatus ) = @_;
+       my $s = undef;
+       for my $status (@$cstatus) {
+               $s = $status if( $status->id eq $copy->status )
+       }
+       return $s;
+}
+
+
+