3 #----------------------------------------------------------------
4 # Code for testing the container API
5 #----------------------------------------------------------------
7 require '../oils_header.pl';
10 my $username = shift || 'admin';
11 my $password = shift || 'open-ils';
13 osrf_connect($config);
14 oils_login($username, $password);
15 oils_fetch_session($authtoken);
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
26 $ttest{'biblio'} = 40791;
27 $ttest{'callnumber'} = 1;
28 $ttest{'copy'} = 420795;
31 my $testcopy = 420795;
43 sub containers_create {
45 for my $type ( keys %types ) {
46 my $bucket = "Fieldmapper::container::" . $types{$type};
47 $bucket = $bucket->new;
48 $bucket->owner($user->id);
49 $bucket->name("TestBucket");
50 $bucket->btype("TestType");
52 my $resp = simplereq($ACTOR,
53 'open-ils.actor.container.bucket.create',
54 $authtoken, $type, $bucket );
56 oils_event_die($resp);
57 printl("Created new $type bucket with id $resp");
58 $containers{$type} = $resp;
64 for my $type ( keys %types ) {
65 my $id = $containers{$type};
67 my $item = "Fieldmapper::container::" . $types{$type} . "_item";
71 $item->target_copy($test{$type}) if $type eq 'copy';
72 $item->target_call_number($test{$type}) if $type eq 'callnumber';
73 $item->target_biblio_record_entry($test{$type}) if $type eq 'biblio';
74 $item->target_user($test{$type}) if $type eq 'user';
76 my $resp = simplereq($ACTOR,
77 'open-ils.actor.container.item.create',
78 $authtoken, $type, $item );
80 oils_event_die($resp);
81 printl("Created new $type bucket item with id $resp");
82 $items{$type} = $resp;
88 for my $type ( keys %types ) {
89 my $id = $containers{$type};
91 my $resp = simplereq($ACTOR,
92 'open-ils.actor.container.item.delete',
93 $authtoken, $type, $id );
95 oils_event_die($resp);
96 printl("Deleted $type bucket item with id $id");
101 sub containers_delete {
102 for my $type (keys %containers) {
103 my $id = $containers{$type};
105 my $resp = simplereq( $ACTOR,
106 'open-ils.actor.container.bucket.delete',
107 $authtoken, $type, $id );
109 oils_event_die($resp);
110 printl("Deleted bucket $id");