]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/checkout.pl
2407d9c48212e2177e514ceec18df585a7c64590
[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         my $key = do_permit($patronid, $barcode, $type =~ /noncat/ ); 
36         do_checkout($key, $patronid, $barcode, $type =~ /noncat/, $nc_type ) unless ($type =~ /permit/);
37         oils_logout();
38 }
39
40 go();
41
42 #----------------------------------------------------------------
43
44 sub do_permit {
45         my( $patronid, $barcode, $noncat ) = @_;
46
47         my $args = { patron => $patronid, barcode => $barcode };
48         if($noncat) {
49                 $args->{noncat} = 1;
50                 $args->{noncat_type} = $nc_type;
51         }
52
53         $start = time();
54         my $resp = simplereq( 
55                 CIRC(), 'open-ils.circ.checkout.permit', $authtoken, $args );
56         
57         oils_event_die($resp);
58         my $e = time() - $start;
59         my $key = $resp->{payload};
60         printl("Permit OK: \n\ttime =\t$e\n\tkey =\t$key" );
61         return $key;
62 }
63
64 sub do_checkout {
65         my( $key, $patronid, $barcode, $noncat, $nc_type ) = @_;
66
67         my $args = { permit_key => $key, patron => $patronid, barcode => $barcode };
68         if($noncat) {
69                 $args->{noncat} = 1;
70                 $args->{noncat_type} = $nc_type;
71         }
72
73         my $start_checkout = time();
74         my $resp = osrf_request(
75                 'open-ils.circ', 
76                 'open-ils.circ.checkout', $authtoken, $args );
77         my $finish = time();
78
79         oils_event_die($resp);
80
81         my $d = $finish - $start_checkout;
82         my $dd = $finish - $start;
83
84         printl("Checkout OK:");
85         if(!$noncat) {
86                 printl("\ttime = $d");
87                 printl("\ttotal time = $dd");
88                 printl("\ttitle = " . $resp->{payload}->{record}->title );
89                 printl("\tdue_date = " . $resp->{payload}->{circ}->due_date );
90         }
91 }
92
93
94
95