]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/container.pl
container / container item create / retrieve / delete working
[Evergreen.git] / Open-ILS / src / support-scripts / test-scripts / container.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         $AUTH $STORAGE $SEARCH $CIRC $CAT $MATH $SETTINGS $ACTOR /;
10 use strict; use warnings;
11
12
13 my $config              = shift; 
14 my $username    = shift || 'admin';
15 my $password    = shift || 'open-ils';
16
17 my %types;
18 my $meth = 'open-ils.storage.direct.container';
19 $types{'biblio'}                        = "biblio_record_entry_bucket";
20 $types{'callnumber'}            = "call_number_bucket";
21 $types{'copy'}                          = "copy_bucket";
22 $types{'user'}                          = "user_bucket";
23
24 # XXX These will depend on the data you have available.
25 # we need a "fetch_any" method to resolve this
26 my %ttest;
27 $ttest{'biblio'}                        = 40791;
28 $ttest{'callnumber'}            = 1;
29 $ttest{'copy'}                          = 420795;
30 $ttest{'user'}                          = 3;
31
32 my $testcopy = 420795;
33 my $testrec = 40791;
34 my $testcn = 1;
35 my $testuser = 3;
36
37 my %containers;
38 my %items;
39
40 sub go {
41         osrf_connect($config);
42         oils_login($username, $password);
43         oils_fetch_session($authtoken);
44         containers_create();
45         items_create();
46         items_delete();
47         containers_delete();
48 }
49
50 go();
51
52 #----------------------------------------------------------------
53
54 sub containers_create {
55
56         for my $type ( keys %types ) {
57                 my $bucket = "Fieldmapper::container::" . $types{$type};
58                 $bucket = $bucket->new;
59                 $bucket->owner($user->id);
60                 $bucket->name("TestBucket");
61                 $bucket->btype("TestType");
62         
63                 my $resp = simplereq($ACTOR, 
64                         'open-ils.actor.container.create',
65                         $authtoken, $type, $bucket );
66         
67                 oils_event_die($resp);
68                 printl("Created new $type bucket with id $resp");
69                 $containers{$type} = $resp;
70         }
71 }
72
73
74 sub items_create {
75         for my $type ( keys %types ) {
76                 my $id = $containers{$type};
77
78                 my $item = "Fieldmapper::container::" . $types{$type} . "_item";
79                 $item = $item->new;
80
81                 $item->bucket($id);
82                 $item->target_copy($ttest{$type}) if $type eq 'copy';
83                 $item->target_call_number($ttest{$type}) if $type eq 'callnumber';
84                 $item->target_biblio_record_entry($ttest{$type}) if $type eq 'biblio';
85                 $item->target_user($ttest{$type}) if $type eq 'user';
86         
87                 my $resp = simplereq($ACTOR, 
88                         'open-ils.actor.container.item.create',
89                         $authtoken, $type, $item );
90         
91                 oils_event_die($resp);
92                 printl("Created new $type bucket item with id $resp");
93                 $items{$type} = $resp;
94         }
95 }
96
97
98 sub items_delete {
99         for my $type ( keys %types ) {
100                 my $id = $items{$type};
101
102                 my $resp = simplereq($ACTOR, 
103                         'open-ils.actor.container.item.delete',
104                         $authtoken, $type, $id );
105         
106                 oils_event_die($resp);
107                 printl("Deleted $type bucket item with id $id");
108         }
109 }
110
111
112 sub containers_delete {
113         for my $type (keys %containers) {
114                 my $id = $containers{$type};
115
116                 my $resp = simplereq( $ACTOR,
117                         'open-ils.actor.container.delete',
118                         $authtoken, $type, $id );
119
120                 oils_event_die($resp);
121                 printl("Deleted bucket $id");
122         }
123 }
124         
125