3 #----------------------------------------------------------------
4 # Code for testing the container API
5 #----------------------------------------------------------------
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;
14 my $username = shift || 'admin';
15 my $password = shift || 'open-ils';
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";
24 # XXX These will depend on the data you have available.
25 # we need a "fetch_any" method to resolve this
27 $ttest{'biblio'} = 40791;
28 $ttest{'callnumber'} = 1;
29 $ttest{'copy'} = 420795;
36 osrf_connect($config);
37 oils_login($username, $password);
38 oils_fetch_session($authtoken);
47 #----------------------------------------------------------------
49 sub containers_create {
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("TestBucket");
56 $bucket->btype("TestType");
58 my $resp = simplereq($ACTOR,
59 'open-ils.actor.container.create',
60 $authtoken, $type, $bucket );
62 oils_event_die($resp);
63 printl("Created new $type bucket with id $resp");
64 $containers{$type} = $resp;
69 $resp = simplereq($ACTOR,
70 'open-ils.actor.container.update', $authtoken, $type, $bucket );
71 oils_event_die($resp);
72 printl("Updated container type $type");
78 for my $type ( keys %types ) {
79 my $id = $containers{$type};
81 my $item = "Fieldmapper::container::" . $types{$type} . "_item";
85 $item->target_copy($ttest{$type}) if $type eq 'copy';
86 $item->target_call_number($ttest{$type}) if $type eq 'callnumber';
87 $item->target_biblio_record_entry($ttest{$type}) if $type eq 'biblio';
88 $item->target_user($ttest{$type}) if $type eq 'user';
90 my $resp = simplereq($ACTOR,
91 'open-ils.actor.container.item.create',
92 $authtoken, $type, $item );
94 oils_event_die($resp);
95 printl("Created new $type bucket item with id $resp");
96 $items{$type} = $resp;
102 for my $type ( keys %types ) {
103 my $id = $items{$type};
105 my $resp = simplereq($ACTOR,
106 'open-ils.actor.container.item.delete',
107 $authtoken, $type, $id );
109 oils_event_die($resp);
110 printl("Deleted $type bucket item with id $id");
116 sub containers_delete {
117 for my $type (keys %containers) {
118 my $id = $containers{$type};
120 my $resp = simplereq( $ACTOR,
121 'open-ils.actor.container.delete',
122 $authtoken, $type, $id );
124 oils_event_die($resp);
125 printl("Deleted bucket $id");