]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/checkout.pl
4176a91770cd2e58d370cc30e603812b17963f86
[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         do_permit($patronid, $barcode, $type =~ /noncat/ ); 
36         do_checkout($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         printl("Permit succeeded : duration $e" );
60 }
61
62 sub do_checkout {
63         my( $patronid, $barcode, $noncat, $nc_type ) = @_;
64
65         my $args = { patron => $patronid, barcode => $barcode };
66         if($noncat) {
67                 $args->{noncat} = 1;
68                 $args->{noncat_type} = $nc_type;
69         }
70
71         my $start_checkout = time();
72         my $resp = osrf_request(
73                 'open-ils.circ', 
74                 'open-ils.circ.checkout', $authtoken, $args );
75         my $finish = time();
76
77         oils_event_die($resp);
78
79         my $d = $finish - $start_checkout;
80         my $dd = $finish - $start;
81
82         printl("Checkout took $d"); 
83         printl("Total process took $dd");
84         printl("Title: " . $resp->{payload}->{record}->title );
85         printl("Copy: " . $resp->{payload}->{copy}->barcode );
86
87         printl("");
88         #debug($resp);
89
90 }
91
92
93
94