]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/support-scripts/test-scripts/container.pl
added some events, utility code, container handling and testint code
[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
9 my $config              = shift; 
10 my $username    = shift || 'admin';
11 my $password    = shift || 'open-ils';
12
13 osrf_connect($config);
14 oils_login($username, $password);
15 oils_fetch_session($authtoken);
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 $ttest{'biblio'}                        = 40791;
27 $ttest{'callnumber'}            = 1;
28 $ttest{'copy'}                          = 420795;
29 $ttest{'user'}                          = 3;
30
31 my $testcopy = 420795;
32 my $testrec = 40791;
33 my $testcn = 1;
34 my $testuser = 3;
35
36 my %containers;
37 my %items;
38
39 containers_create();
40 #items_create();
41 containers_delete();
42
43 sub containers_create {
44
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");
51         
52                 my $resp = simplereq($ACTOR, 
53                         'open-ils.actor.container.bucket.create',
54                         $authtoken, $type, $bucket );
55         
56                 oils_event_die($resp);
57                 printl("Created new $type bucket with id $resp");
58                 $containers{$type} = $resp;
59         }
60 }
61
62
63 sub items_create {
64         for my $type ( keys %types ) {
65                 my $id = $containers{$type};
66
67                 my $item = "Fieldmapper::container::" . $types{$type} . "_item";
68                 $item = $item->new;
69
70                 $item->bucket($id);
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';
75         
76                 my $resp = simplereq($ACTOR, 
77                         'open-ils.actor.container.item.create',
78                         $authtoken, $type, $item );
79         
80                 oils_event_die($resp);
81                 printl("Created new $type bucket item with id $resp");
82                 $items{$type} = $resp;
83         }
84 }
85
86
87 sub items_delete {
88         for my $type ( keys %types ) {
89                 my $id = $containers{$type};
90
91                 my $resp = simplereq($ACTOR, 
92                         'open-ils.actor.container.item.delete',
93                         $authtoken, $type, $id );
94         
95                 oils_event_die($resp);
96                 printl("Deleted $type bucket item with id $id");
97         }
98 }
99
100
101 sub containers_delete {
102         for my $type (keys %containers) {
103                 my $id = $containers{$type};
104
105                 my $resp = simplereq( $ACTOR,
106                         'open-ils.actor.container.bucket.delete',
107                         $authtoken, $type, $id );
108
109                 oils_event_die($resp);
110                 printl("Deleted bucket $id");
111         }
112 }
113         
114