]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/checkout.pl
more checkout code
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / checkout.pl
1 #!/usr/bin/perl
2
3 #----------------------------------------------------------------
4 # Code for testing the container API
5 #----------------------------------------------------------------
6
7 require '../oils_header.pl';
8 use vars qw/ $apputils $memcache $user $authtoken $authtime /;
9 use strict; use warnings;
10 use Time::HiRes qw/time/;
11
12 #----------------------------------------------------------------
13 err("\nusage: $0 <config> <oils_login_username> ".
14         " <oils_login_password> <patronid> <copy_barcode> [<type>, <noncat_type>]\n".
15         "Where <type> is one of:\n".
16         "\t'permit' to run the permit only\n".
17         "\t'noncat_permit' to run the permit script against a noncat item\n".
18         "\t'noncat' to check out a noncat item\n".
19         "\t(blank) to do a regular checkout\n" ) unless $ARGV[4];
20 #----------------------------------------------------------------
21
22 my $config              = shift; 
23 my $username    = shift;
24 my $password    = shift;
25 my $patronid    = shift;
26 my $barcode             = shift;
27 my $type                        = shift || "";
28 my $nc_type             = shift;
29
30 my $start;
31
32 sub go {
33         osrf_connect($config);
34         oils_login($username, $password);
35
36         if($type eq 'renew') {
37                 do_renew($patronid, $barcode);
38
39         } elsif( $type eq 'transit_receive' ) {
40                 do_transit_receive($barcode);
41
42         } elsif( $type eq 'checkin' ) {
43                 do_checkin($barcode);
44         } else {
45                 my($key,$precat) = do_permit($patronid, $barcode, $type =~ /noncat/ ); 
46                 printl("Item is pre-cataloged...") if $precat;
47                 do_checkout($key, $patronid, $barcode, 
48                         $precat, $type =~ /noncat/, $nc_type ) unless ($type =~ /permit/);
49         }
50         oils_logout();
51 }
52
53 go();
54
55 #----------------------------------------------------------------
56
57 sub do_permit {
58         my( $patronid, $barcode, $noncat ) = @_;
59
60         my $precat = 0;
61         my $args = { patron => $patronid, barcode => $barcode };
62         if($noncat) {
63                 $args->{noncat} = 1;
64                 $args->{noncat_type} = $nc_type;
65         }
66
67         $start = time();
68         my $resp = simplereq( 
69                 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
70         
71         if( oils_event_equals($resp, 'ITEM_NOT_CATALOGED') ) {
72                 $precat = 1;
73         } else { oils_event_die($resp); }
74
75         my $e = time() - $start;
76         my $key = $resp->{payload};
77         printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
78
79         return ( $key, $precat );
80 }
81
82 sub do_checkout {
83         my( $key, $patronid, $barcode, $precat, $noncat, $nc_type ) = @_;
84
85         my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
86
87         if($noncat) {
88                 $args->{noncat} = 1;
89                 $args->{noncat_type} = $nc_type;
90         }
91
92         if($precat) {
93                 $args->{precat} = 1;
94                 $args->{dummy_title} = "Dummy Title";
95                 $args->{dummy_author} = "Dummy Author";
96         }
97
98         my $start_checkout = time();
99         my $resp = osrf_request(
100                 'open-ils.circ', 
101                 'open-ils.circ.checkout', $authtoken, $args );
102         my $finish = time();
103
104         oils_event_die($resp);
105
106         my $d = $finish - $start_checkout;
107         my $dd = $finish - $start;
108
109         printl("Checkout OK:");
110         printl("\ttime = $d");
111         printl("\ttotal time = $dd");
112         printl("\ttitle = " . $resp->{payload}->{record}->title ) unless($noncat or $precat);
113         printl("\tdue_date = " . $resp->{payload}->{circ}->due_date ) unless $noncat;
114 }
115
116
117
118 sub do_renew {
119         my( $patronid, $barcode ) = @_;
120         my $args = { patron => $patronid, barcode => $barcode };
121         my $t = time();
122         my $resp = simplereq( 
123                 CIRC(), 'open-ils.circ.renew', $authtoken, $args );
124         my $e = time() - $t;
125         oils_event_die($resp);
126         printl("Renewal succeeded\nTime: $t");
127 }
128
129 sub do_checkin {
130         my $barcode  = shift;
131         my $args = { barcode => $barcode };
132         my $t = time();
133         my $resp = simplereq( 
134                 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
135         my $e = time() - $t;
136         oils_event_die($resp);
137         printl("Checkin succeeded\nTime: $t");
138
139 }
140
141 sub do_transit_receive {
142         my $barcode = shift;
143         my $args = { barcode => $barcode };
144         my $t = time();
145         my $resp = simplereq( 
146                 CIRC(), 'open-ils.circ.copy_transit.receive', $authtoken, $args );
147         my $e = time() - $t;
148         oils_event_die($resp);
149         printl("Transit receive succeeded\nTime: $t");
150 }