]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/regress.pl
ebl update to use the new gettext method
[bacula/bacula] / gui / bweb / script / regress.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
33    Switzerland, email:ftf@fsfeurope.org.
34
35 =head1 USAGE
36
37     Get it working with a regress environment:
38      * get regress module from SVN
39      * use postgresql or mysql in config
40      * make setup
41      * add catalog = all, !skipped, !saved into Messages Standard (scripts/bacula-dir.conf)
42      * add exit 0 to scripts/cleanup
43      * run bacula-backup-test
44      * charger bweb-(mysql|postgresql).sql
45      * ./bin/bacula start
46      * configure bweb to point to bconsole and the catalog
47
48 =head1 VERSION
49
50     $Id$
51
52 =cut
53
54 use Test::More qw(no_plan);
55 use WWW::Mechanize;
56
57 use Getopt::Long;
58
59 my ($login, $pass, $url, $verbose);
60 GetOptions ("login=s"  => \$login,
61             "passwd=s" => \$pass,
62             "url|u=s"  => \$url,
63             "verbose"  => \$verbose,
64             );
65
66 die "Usage: $0 --url http://.../cgi-bin/bweb/bweb.pl [-l user -p pass]"
67     unless ($url);
68
69 print "Making tests on $url\n";
70 my ($req, $res, $c, $cli, $job_url);
71
72 my $agent = new WWW::Mechanize(autocheck=>1);
73 if ($login) {
74     $agent->credentials($login, $pass);
75 }
76
77 ################################################################
78 # Check bweb libraries
79 ################################################################
80
81 # first, try to load all bweb libraries
82 require_ok('Bweb');
83 require_ok('Bconsole');
84 require_ok('CCircle');
85
86 # test first page and check for the last job 
87 $agent->get($url); ok($agent->success, "Get main page"); $c = $agent->content;
88 like($c, qr!</html>!, "Check EOP");
89 ok($c =~ m!(action=job_zoom;jobid=\d+)!, "Get the first JobId");
90 die "Can't get first jobid ($c)" unless $1;
91 $job_url=$1;
92
93 # test job_zoom page
94 # check for
95 #  - job log
96 #  - fileset
97 #  - media view
98 $agent->get("$url?$job_url");
99 ok($agent->success,"Get job zoom"); $c=$agent->content;
100 like($c, qr!</html>!, "Check EOP");
101 like($c, qr!Using Device!, "Check for job log");
102
103 ok($agent->form_name('fileset_view'), "Find form");
104 $agent->click(); $c=$agent->content;
105 ok($agent->success, "Get fileset"); 
106 like($c, qr!</html>!, "Check EOP");
107 ok($c =~ m!<pre>\s*(/[^>]+?)</pre>!s,"Check fileset");
108 print $1 if $verbose;
109 $agent->back(); ok($agent->success,"Return from fileset");
110
111 ok($agent->form_name("rerun"), "Find form");
112 $agent->click(); $c=$agent->content;
113 ok($agent->success, "ReRun job");
114 ok($agent->form_name("form1"), "Find form");
115 ok($c =~ m!<select name='job'>\s*<option value='(.+?)'!,"jobs");
116 ok($agent->field('job', $1), "set field job=1");
117 ok($c =~ m!<select name='client'>\s*<option value='(.+?)'!, "clients");
118 ok($agent->field('client', $1), "set field client=$1");
119 ok($c =~ m!<select name='storage'>\s*<option value='(.+?)'!, "storages");
120 ok($agent->field('storage', $1), "set field storage=$1");
121 ok($c =~ m!<select name='fileset'>\s*<option value='(.+?)'!, "filesets");
122 ok($agent->field('fileset', $1), "set field fileset=1");
123 ok($c =~ m!<select name='pool'>\s*<option value=''></option>\s*<option value='(.+?)'!, "pools");
124 $agent->field('pool', $1);
125 $agent->click_button(value => 'run_job_now');
126 ok($agent->success(), "submit");
127 sleep 2;
128 ok($agent->follow_link(text_regex=>qr/here/i), "follow link");
129 ok($agent->success(), "get job page"); $c=$agent->content;
130 like($c, qr/Using Device/, "Check job log");
131
132 # try to delete this job
133 $agent->get("$url?$job_url");
134 ok($agent->success,"Get job zoom");
135 ok($agent->form_name('delete'), "Find form");
136 $agent->click(); $c=$agent->content;
137 ok($agent->success, "Delete it"); 
138 like($c, qr!deleted!, "Check deleted message");
139
140 $agent->get("$url?$job_url");
141 ok($agent->success,"Get job zoom");
142 $c=$agent->content;
143 like($c, qr!An error has occurred!, "Check deleted job");
144
145 # list jobs
146 ok($agent->follow_link(text_regex=>qr/Defined Jobs/), "Go to Defined Jobs page");
147 $c=$agent->content;
148 like($c, qr/BackupCatalog/, "Check for BackupCatalog job");
149
150 ################################################################
151 # client tests
152 ################################################################
153
154 ok($agent->follow_link(text_regex=>qr/Clients/), "Go to Clients page");
155 $c=$agent->content;
156 ok($c =~ m!chkbox.value = '(.+?)';!, "get client name");
157 $cli = $1;
158
159 $agent->get("$url?action=client_status;client=$cli");
160 ok($agent->success(), "submit"); $c=$agent->content;
161 like($c, qr/Terminated Jobs/, "check for client status");
162
163 $agent->get("$url?action=job;client=$cli");
164 ok($agent->success(), "submit"); $c=$agent->content;
165 like($c, qr/'$cli'\).selected = true;/, "list jobs for this client");
166
167 ################################################################
168 # Test location basic functions
169 ################################################################
170
171 my $loc = "loc$$";
172 ok($agent->follow_link(text_regex=>qr/Location/), "Go to Location page");
173 ok($agent->form_number(2), "Find form");
174 $agent->click_button(value => 'location_add');
175 ok($agent->success(), "submit");
176 ok($agent->form_number(2), "Find form");
177 $agent->field("location", $loc);
178 ok($agent->field("cost", 20), "set field cost=20");
179 ok($agent->field("enabled", "yes"), "set field enabled=yes");
180 ok($agent->field("enabled", "no"), "try set field enabled=no");
181 ok($agent->field("enabled", "archived"), "try set field enabled=archived");
182 $agent->click_button(value => 'location_add');
183 ok($agent->success(), "submit"); $c=$agent->content;
184 like($c, qr/$loc/, "Check if location is ok");
185 like($c, qr/inflag2.png/, "Check if enabled is archived");
186
187 $agent->get("$url?location=$loc&action=location_edit");
188 ok($agent->success(), "Try to edit location"); $c=$agent->content;
189 like($c, qr/$loc/, "Check for location");
190 ok($agent->form_number(2), "Find form");
191 $agent->field("cost", 40);
192 $agent->field("enabled", "no");
193 $loc = "new$loc";
194 $agent->field("newlocation", $loc);
195 $agent->click_button(value => 'location_save');
196 ok($agent->success(), "submit to edit location"); $c=$agent->content;
197 like($c, qr/$loc/, "Check if location is ok");
198 like($c, qr/inflag0.png/, "Check if enabled is 'no'");
199 like($c, qr/40/, "Check for cost");
200
201 ################################################################
202 # Test media
203 ################################################################
204
205 ok($agent->follow_link(text_regex=>qr/All Media/), "Go to All Media page");
206 ok($agent->success(), "submit"); $c=$agent->content;
207 ok($c =~ m/chkbox.value = '(.+?)'/, "get first media");
208 my $vol = $1;
209
210 $agent->get("$url?media=$vol;action=update_media");
211 ok($agent->success(), "submit"); $c=$agent->content;
212 like($c, qr/$vol/, "Check if volume is ok");
213
214 ################################################################
215 # Test group basic functions
216 ################################################################
217
218 $agent->get("$url?action=client;notingroup=yes");
219 ok($agent->success(), "submit"); $c=$agent->content;
220 like($c, qr/$cli/, "check client=$cli is groupless");
221
222 # create a group
223 my $grp = "test$$";
224 ok($agent->follow_link(text_regex=>qr/Groups/), "Go to Groups page");
225 ok($agent->success(), "submit"); $c=$agent->content;
226 unlike($c, qr/error/i, "Check for group installation");
227 ok($agent->form_number(2), "Find form");
228 $agent->click_button(value => 'groups_edit');
229 ok($agent->success(), "submit action=groups_edit");
230 ok($agent->form_number(2), "Find form to create a group");
231 $agent->field("newgroup", $grp);
232 $agent->click_button(value => 'groups_save');
233 ok($agent->success(), "submit action=groups_save");
234 $c=$agent->content; 
235 like($c, qr/$grp/, "Check if group have been created");
236
237 # rename group (client is loss because it was set by javascript)
238 $agent->get("$url?client_group=$grp;action=groups_edit");
239 ok($agent->success(), "submit action=groups_edit"); $c=$agent->content;
240 like($c, qr/$grp/, "Check if group is present to rename it");
241 ok($agent->form_number(2), "Find form");
242 $grp = "newtest$$";
243 $agent->field("newgroup", $grp);
244 $agent->field("client", $cli);
245 $agent->click_button(value => 'groups_save');
246 ok($agent->success(), "submit"); $c=$agent->content;
247 like($c, qr/'$grp'/, "Check if newgroup is present");
248
249 # check if group is ok
250 $agent->get("$url?client_group=$grp;action=client");
251 ok($agent->success(), "submit"); $c=$agent->content;
252 like($c, qr/'$cli'/, "Check if client is present in newgrp");
253
254 $agent->get("$url?action=client;notingroup=yes");
255 ok($agent->success(), "check if client=$cli is already 'not in group'");
256 $c=$agent->content;
257 unlike($c, qr/$cli/, "check client=$cli");
258
259 $agent->get("$url?client_group=other$grp;action=groups_edit");
260 ok($agent->success(), "create an empty other$grp"); $c=$agent->content;
261 like($c, qr/'other$grp'/, "check if other$grp was created");
262
263 # view job by group
264 ok($agent->follow_link(text_regex=>qr/Jobs by group/), "Go to Job by group page");
265 ok($agent->success(), "Get it"); $c=$agent->content;
266 like($c, qr/"$grp"/, "check if $grp is here");
267
268 # view job overview
269 ok($agent->follow_link(text_regex=>qr/Jobs overview/), "Go to Job overview");
270 ok($agent->success(), "Get it"); $c=$agent->content;
271 like($c, qr/"$grp"/, "check if $grp is here");
272
273 # view next jobs
274 ok($agent->follow_link(text_regex=>qr/Next Jobs/), "Go to Next jobs");
275 ok($agent->success(), "Get it"); $c=$agent->content;
276 like($c, qr/'BackupCatalog'/, "check if BackupCatalog is here");
277
278 # Add media
279 ok($agent->follow_link(text_regex=>qr/Add Media/), "Go to Add Media");
280 ok($agent->success(), "Get it");
281 ok($agent->form_number(2), "Find form");
282 $agent->field('pool', 'Scratch');
283 $agent->field('storage', 'File');
284 $agent->field('nb', '3');
285 $agent->field('offset', '1');
286 $agent->field('media', "Vol$$");
287 $agent->click_button(value => 'add_media');
288 ok($agent->success(), "Create them"); $c=$agent->content;
289 like($c, qr/Vol${$}0001/, "Check if media are there");
290
291 # view pools
292 ok($agent->follow_link(text_regex=>qr/Pools/), "Go to Pool");
293 ok($agent->success(), "Get it"); $c=$agent->content;
294 like($c, qr/"Default"/, "check if Default pool is here");
295 like($c, qr/"Scratch"/, "check if Scratch pool is here");
296
297 ################################################################
298 # other checks and cleanup
299 ################################################################
300
301 # cleanup groups
302 $agent->get("$url?client_group=$grp;action=groups_del");
303 ok($agent->success(), "submit"); $c=$agent->content;
304 unlike($c, qr/'$grp'/, "Check if group was deleted");
305
306 $agent->get("$url?client_group=other$grp;action=groups_del");
307 ok($agent->success(), "submit"); $c=$agent->content;
308 unlike($c, qr/'other$grp'/, "Check if group was deleted");
309
310 # cleanup location
311 $agent->get("$url?location=$loc;action=location_del");
312 ok($agent->success(), "submit"); $c=$agent->content;
313 unlike($c, qr/$loc/, "Check if location was deleted");
314
315 exit 0;
316
317
318 __END__
319