]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/container.pl
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[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 %containers;
33 my %items;
34
35 sub go {
36         osrf_connect($config);
37         oils_login($username, $password);
38         oils_fetch_session($authtoken);
39         containers_create();
40         items_create();
41         items_delete();
42         containers_delete();
43 }
44
45 go();
46
47 #----------------------------------------------------------------
48
49 sub containers_create {
50
51         for my $type ( keys %types ) {
52                 my $bucket = "Fieldmapper::container::" . $types{$type};
53                 $bucket = $bucket->new;
54                 $bucket->owner($user->id);
55                 $bucket->name("TestBucket123");
56                 $bucket->btype("TestType123");
57
58         printl("creating bucket " .$bucket->owner." : " . $bucket->name . " : " . $bucket->btype);
59         
60                 my $resp = simplereq($ACTOR, 
61                         'open-ils.actor.container.create',
62                         $authtoken, $type, $bucket );
63         
64                 oils_event_die($resp);
65                 printl("Created new $type bucket with id $resp");
66                 $containers{$type} = $resp;
67
68                 $bucket->id($resp);
69                 $bucket->pub(1);
70
71                 $resp = simplereq($ACTOR, 
72                         'open-ils.actor.container.update', $authtoken, $type, $bucket );
73                 oils_event_die($resp);
74                 printl("Updated container type $type");
75         }
76 }
77
78
79 sub items_create {
80         for my $type ( keys %types ) {
81                 my $id = $containers{$type};
82
83                 my $item = "Fieldmapper::container::" . $types{$type} . "_item";
84                 $item = $item->new;
85
86                 $item->bucket($id);
87                 $item->target_copy($ttest{$type}) if $type eq 'copy';
88                 $item->target_call_number($ttest{$type}) if $type eq 'callnumber';
89                 $item->target_biblio_record_entry($ttest{$type}) if $type eq 'biblio';
90                 $item->target_user($ttest{$type}) if $type eq 'user';
91         
92                 my $resp = simplereq($ACTOR, 
93                         'open-ils.actor.container.item.create',
94                         $authtoken, $type, $item );
95         
96                 oils_event_die($resp);
97                 printl("Created new $type bucket item with id $resp");
98                 $items{$type} = $resp;
99         }
100 }
101
102
103 sub items_delete {
104         for my $type ( keys %types ) {
105                 my $id = $items{$type};
106
107                 my $resp = simplereq($ACTOR, 
108                         'open-ils.actor.container.item.delete',
109                         $authtoken, $type, $id );
110         
111                 oils_event_die($resp);
112                 printl("Deleted $type bucket item with id $id");
113         }
114 }
115
116
117
118 sub containers_delete {
119         for my $type (keys %containers) {
120                 my $id = $containers{$type};
121
122                 my $resp = simplereq( $ACTOR,
123                         'open-ils.actor.container.delete',
124                         $authtoken, $type, $id );
125
126                 oils_event_die($resp);
127                 printl("Deleted bucket $id");
128         }
129 }
130         
131