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