]> git.sur5r.net Git - bacula/bacula/blob - gui/bweb/script/regress.pl
ebl Fix a bug in LocationLog, it works now
[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);
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
92 # test job_zoom page
93 # check for
94 #  - job log
95 #  - fileset
96 #  - media view
97 $agent->get("$url?$1"); ok($agent->success,"Get job zoom"); $c=$agent->content;
98 like($c, qr!</html>!, "Check EOP");
99 like($c, qr!Using Device!, "Check for job log");
100
101 ok($agent->form_name('fileset_view'), "Find form");
102 $agent->click(); $c=$agent->content;
103 ok($agent->success, "Get fileset"); 
104 like($c, qr!</html>!, "Check EOP");
105 ok($c =~ m!<pre>\s*(/[^>]+?)</pre>!s,"Check fileset");
106 print $1 if $verbose;
107 $agent->back(); ok($agent->success,"Return from fileset");
108
109 ok($agent->form_name("rerun"), "Find form");
110 $agent->click(); $c=$agent->content;
111 ok($agent->success, "ReRun job");
112 ok($agent->form_name("form1"), "Find form");
113 ok($c =~ m!<select name='job'>\s*<option value='(.+?)'!,"jobs");
114 ok($agent->field('job', $1), "set field job=1");
115 ok($c =~ m!<select name='client'>\s*<option value='(.+?)'!, "clients");
116 ok($agent->field('client', $1), "set field client=$1");
117 ok($c =~ m!<select name='storage'>\s*<option value='(.+?)'!, "storages");
118 ok($agent->field('storage', $1), "set field storage=$1");
119 ok($c =~ m!<select name='fileset'>\s*<option value='(.+?)'!, "filesets");
120 ok($agent->field('fileset', $1), "set field fileset=1");
121 ok($c =~ m!<select name='pool'>\s*<option value=''></option>\s*<option value='(.+?)'!, "pools");
122 $agent->field('pool', $1);
123 $agent->click_button(value => 'run_job_now');
124 ok($agent->success(), "submit");
125 sleep 2;
126 ok($agent->follow_link(text_regex=>qr/here/i), "follow link");
127 ok($agent->success(), "get job page"); $c=$agent->content;
128 like($c, qr/Using Device/, "Check job log");
129
130 ################################################################
131 # client tests
132 ################################################################
133
134 ok($agent->follow_link(text_regex=>qr/Clients/), "Go to Clients page");
135 $c=$agent->content;
136 ok($c =~ m!chkbox.value = '(.+?)';!, "get client name");
137 $cli = $1;
138
139 $agent->get("$url?action=client_status;client=$cli");
140 ok($agent->success(), "submit"); $c=$agent->content;
141 like($c, qr/Terminated Jobs/, "check for client status");
142
143 $agent->get("$url?action=job;client=$cli");
144 ok($agent->success(), "submit"); $c=$agent->content;
145 like($c, qr/'$cli'\).selected = true;/, "list jobs for this client");
146
147 ################################################################
148 # Test location basic functions
149 ################################################################
150
151 my $loc = "loc$$";
152 ok($agent->follow_link(text_regex=>qr/Location/), "Go to Location page");
153 ok($agent->form_number(2), "Find form");
154 $agent->click_button(value => 'location_add');
155 ok($agent->success(), "submit");
156 ok($agent->form_number(2), "Find form");
157 $agent->field("location", $loc);
158 ok($agent->field("cost", 20), "set field cost=20");
159 ok($agent->field("enabled", "yes"), "set field enabled=yes");
160 ok($agent->field("enabled", "archived"), "try set field enabled=archived");
161 ok($agent->field("enabled", "no"), "try set field enabled=no");
162 $agent->click_button(value => 'location_add');
163 ok($agent->success(), "submit"); $c=$agent->content;
164 like($c, qr/$loc/, "Check if location is ok");
165 like($c, qr/inflag1.png/, "Check if enabled is ok");
166
167 $agent->get("$url?location=$loc&action=location_edit");
168 ok($agent->success(), "Try to edit location"); $c=$agent->content;
169 like($c, qr/$loc/, "Check for location");
170 ok($agent->form_number(2), "Find form");
171 $agent->field("cost", 40);
172 $agent->field("enabled", "no");
173 $loc = "new$loc";
174 $agent->field("newlocation", $loc);
175 $agent->click_button(value => 'location_save');
176 ok($agent->success(), "submit to edit location"); $c=$agent->content;
177 like($c, qr/$loc/, "Check if location is ok");
178 like($c, qr/inflag0.png/, "Check if enabled is 'no'");
179 like($c, qr/40/, "Check for cost");
180
181 ################################################################
182 # Test media
183 ################################################################
184
185 ok($agent->follow_link(text_regex=>qr/All Media/), "Go to All Media page");
186 ok($agent->success(), "submit"); $c=$agent->content;
187 ok($c =~ m/chkbox.value = '(.+?)'/, "get first media");
188 my $vol = $1;
189
190 $agent->get("$url?media=$vol;action=update_media");
191 ok($agent->success(), "submit"); $c=$agent->content;
192 like($c, qr/$vol/, "Check if volume is ok");
193
194 ################################################################
195 # Test group basic functions
196 ################################################################
197
198 $agent->get("$url?action=client;notingroup=yes");
199 ok($agent->success(), "submit"); $c=$agent->content;
200 like($c, qr/$cli/, "check client=$cli is groupless");
201
202 # create a group
203 my $grp = "test$$";
204 ok($agent->follow_link(text_regex=>qr/Groups/), "Go to Groups page");
205 ok($agent->success(), "submit"); $c=$agent->content;
206 unlike($c, qr/error/i, "Check for group installation");
207 ok($agent->form_number(2), "Find form");
208 $agent->click_button(value => 'groups_edit');
209 ok($agent->success(), "submit action=groups_edit");
210 ok($agent->form_number(2), "Find form to create a group");
211 $agent->field("newgroup", $grp);
212 $agent->click_button(value => 'groups_save');
213 ok($agent->success(), "submit action=groups_save");
214 $c=$agent->content; 
215 like($c, qr/$grp/, "Check if group have been created");
216
217 # rename group (client is loss because it was set by javascript)
218 $agent->get("$url?client_group=$grp;action=groups_edit");
219 ok($agent->success(), "submit action=groups_edit"); $c=$agent->content;
220 like($c, qr/$grp/, "Check if group is present to rename it");
221 ok($agent->form_number(2), "Find form");
222 $grp = "newtest$$";
223 $agent->field("newgroup", $grp);
224 $agent->field("client", $cli);
225 $agent->click_button(value => 'groups_save');
226 ok($agent->success(), "submit"); $c=$agent->content;
227 like($c, qr/'$grp'/, "Check if newgroup is present");
228
229 # check if group is ok
230 $agent->get("$url?client_group=$grp;action=client");
231 ok($agent->success(), "submit"); $c=$agent->content;
232 like($c, qr/'$cli'/, "Check if client is present in newgrp");
233
234 $agent->get("$url?action=client;notingroup=yes");
235 ok($agent->success(), "check if client=$cli is already 'not in group'");
236 $c=$agent->content;
237 unlike($c, qr/$cli/, "check client=$cli");
238
239 $agent->get("$url?client_group=other$grp;action=groups_edit");
240 ok($agent->success(), "create an empty other$grp"); $c=$agent->content;
241 like($c, qr/'other$grp'/, "check if other$grp was created");
242
243 ################################################################
244 # other checks and cleanup
245 ################################################################
246
247 # cleanup groups
248 $agent->get("$url?client_group=$grp;action=groups_del");
249 ok($agent->success(), "submit"); $c=$agent->content;
250 unlike($c, qr/'$grp'/, "Check if group was deleted");
251
252 $agent->get("$url?client_group=other$grp;action=groups_del");
253 ok($agent->success(), "submit"); $c=$agent->content;
254 unlike($c, qr/'other$grp'/, "Check if group was deleted");
255
256 # cleanup location
257 $agent->get("$url?location=$loc;action=location_del");
258 ok($agent->success(), "submit"); $c=$agent->content;
259 unlike($c, qr/$loc/, "Check if location was deleted");
260
261 exit 0;
262
263
264 __END__
265
266
267 # view media
268 my @vol = ($cont =~ m!<input type='hidden' name='media' value='([^>]+)'>!sg);
269 @vol = map { ('media', $_) } @vol;
270 ok(scalar(@vol), "Check for job media using retry fields");
271 $cont2 = get_content("View media " .  join('=', @vol),
272                      action => 'media', @vol);
273 ok($cont2 =~ m!</html>!, "Check end of page");
274
275
276 ok($cont =~ m!<input type='hidden' name='client' value='[^>]+'>!,
277    "Check for job client using retry fields");
278
279 # test delete job page
280 #$cont = get_content("Job delete", action => 'delete', jobid => $1);
281 #ok($cont =~ m!</html>!, "Check end of page");