optimize Reports->Customers->List Customers, RT#20173
[freeside.git] / bin / fetch_pages
1 #!/usr/bin/perl
2
3 use strict;
4 use WWW::Mechanize;
5 use Getopt::Std;
6 use File::chdir;
7 use URI;
8 use File::Slurp qw(write_file);
9
10 my %opt;
11 getopts('d:h:u:p:', \%opt);
12 die usage() unless ($opt{d} and $opt{u} and $opt{p});
13 my $host = $opt{h} || 'http://localhost/freeside';
14
15 my $mech = WWW::Mechanize->new;
16 $mech->credentials($opt{u}, $opt{p}); # 3.x auth only
17
18 my @tests = <>;
19
20 mkdir($opt{d}) unless -d $opt{d};
21 push @CWD, $opt{d};
22
23 while (my $path = shift @tests) {
24   if ($path =~ /^#(.*)/) {
25     print "$1 - skipped\n";
26     next;
27   }
28   my $uri = URI->new("$host/$path");
29   print $uri->path;
30   my $response = $mech->get($uri);
31   print " - " . $response->code . "\n";
32   if ($response->is_success) {
33     local $CWD;
34     my @dirs = $uri->path_segments;
35     my $file = pop @dirs;
36     foreach my $dir (@dirs) {
37       mkdir $dir unless -d $dir;
38       push @CWD, $dir;
39     }
40     write_file($file, {binmode => ':utf8'}, $response->decoded_content);
41   }
42 }
43
44 sub usage {
45   "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n";
46 }
47
48 =head1 NAME
49
50 fetch_pages - a testing tool for UI changes
51
52 =head1 USAGE
53
54 fetch_pages -d before_change -u myuser -p mypass list_of_tests
55 git checkout newbranch
56 make install; apache2ctl restart
57 fetch_pages -d after_change -u myuser -p mypass list_of_tests
58 diff -ur before_change/ after_change/ |diffstat
59
60 =head1 ARGUMENTS
61
62 -d: the directory to put the files in. Required.
63
64 -u: the username to use with the Freeside web interface. Required.
65
66 -p: the password. Required.
67
68 -h: the URL prefix for the Freeside server. Defaults to
69 "http://localhost/freeside".
70
71 The list of tests can be in a file specified after all arguments, or passed
72 to stdin.
73
74 =cut