]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/checkout.pl
f1a248e822f9a3d7342254bea6698a2afa0edc97
[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 'checkin' ) {
40                 do_checkin($patronid, $barcode);
41         } else {
42                 my($key,$precat) = do_permit($patronid, $barcode, $type =~ /noncat/ ); 
43                 printl("Item is pre-cataloged...") if $precat;
44                 do_checkout($key, $patronid, $barcode, 
45                         $precat, $type =~ /noncat/, $nc_type ) unless ($type =~ /permit/);
46         }
47         oils_logout();
48 }
49
50 go();
51
52 #----------------------------------------------------------------
53
54 sub do_permit {
55         my( $patronid, $barcode, $noncat ) = @_;
56
57         my $precat = 0;
58         my $args = { patron => $patronid, barcode => $barcode };
59         if($noncat) {
60                 $args->{noncat} = 1;
61                 $args->{noncat_type} = $nc_type;
62         }
63
64         $start = time();
65         my $resp = simplereq( 
66                 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
67         
68         if( oils_event_equals($resp, 'ITEM_NOT_CATALOGED') ) {
69                 $precat = 1;
70         } else { oils_event_die($resp); }
71
72         my $e = time() - $start;
73         my $key = $resp->{payload};
74         printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
75
76         return ( $key, $precat );
77 }
78
79 sub do_checkout {
80         my( $key, $patronid, $barcode, $precat, $noncat, $nc_type ) = @_;
81
82         my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
83
84         if($noncat) {
85                 $args->{noncat} = 1;
86                 $args->{noncat_type} = $nc_type;
87         }
88
89         if($precat) {
90                 $args->{precat} = 1;
91                 $args->{dummy_title} = "Dummy Title";
92                 $args->{dummy_author} = "Dummy Author";
93         }
94
95         my $start_checkout = time();
96         my $resp = osrf_request(
97                 'open-ils.circ', 
98                 'open-ils.circ.checkout', $authtoken, $args );
99         my $finish = time();
100
101         oils_event_die($resp);
102
103         my $d = $finish - $start_checkout;
104         my $dd = $finish - $start;
105
106         printl("Checkout OK:");
107         printl("\ttime = $d");
108         printl("\ttotal time = $dd");
109         printl("\ttitle = " . $resp->{payload}->{record}->title ) unless($noncat or $precat);
110         printl("\tdue_date = " . $resp->{payload}->{circ}->due_date ) unless $noncat;
111 }
112
113
114
115 sub do_renew {
116         my( $patronid, $barcode ) = @_;
117         my $args = { patron => $patronid, barcode => $barcode };
118         my $t = time();
119         my $resp = simplereq( 
120                 CIRC(), 'open-ils.circ.renew_', $authtoken, $args );
121         my $e = time() - $t;
122         oils_event_die($resp);
123         printl("Renewal succeeded\nTime: $t");
124 }
125
126 sub do_checkin {
127         my( $patronid, $barcode ) = @_;
128         my $args = { patron => $patronid, barcode => $barcode };
129         my $t = time();
130         my $resp = simplereq( 
131                 CIRC(), 'open-ils.circ.checkin', $authtoken, $args );
132         my $e = time() - $t;
133         oils_event_die($resp);
134         printl("Checkin succeeded\nTime: $t");
135
136 }