summaryrefslogtreecommitdiff
path: root/bin/fetch_pages
blob: 5aeca56b379338776fecc1c7a2981d9d4c6ecea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl

use strict;
use WWW::Mechanize;
use Getopt::Std;
use File::chdir;
use URI;
use File::Slurp qw(write_file);

my %opt;
getopts('d:h:u:p:', \%opt);
die usage() unless ($opt{d} and $opt{u} and $opt{p});
my $host = $opt{h} || 'http://localhost/freeside';

my $mech = WWW::Mechanize->new( autocheck => 0 );
$mech->get("$host/index.html");
$mech->submit_form(
  with_fields => {
    credential_0 => $opt{u},
    credential_1 => $opt{p}
  }
);

my @tests = <>;

mkdir($opt{d}) unless -d $opt{d};
push @CWD, $opt{d};

while (my $path = shift @tests) {
  if ($path =~ /^#(.*)/) {
    print "$1 - skipped\n";
    next;
  }
  my $uri = URI->new("$host/$path");
  print $uri->path;
  my $response = $mech->get($uri);
  print " - " . $response->code . "\n";
  if ($response->is_success) {
    local $CWD;
    my @dirs = $uri->path_segments;
    my $file = pop @dirs;
    foreach my $dir (@dirs) {
      mkdir $dir unless -d $dir;
      push @CWD, $dir;
    }
    write_file($file, {binmode => ':utf8'}, $response->decoded_content);
  }
}

sub usage {
  "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n";
}

=head1 NAME

fetch_pages - a testing tool for UI changes

=head1 USAGE

fetch_pages -d before_change -u myuser -p mypass list_of_tests
git checkout newbranch
make install; apache2ctl restart
fetch_pages -d after_change -u myuser -p mypass list_of_tests
diff -ur before_change/ after_change/ |diffstat

=head1 ARGUMENTS

-d: the directory to put the files in. Required.

-u: the username to use with the Freeside web interface. Required.

-p: the password. Required.

-h: the URL prefix for the Freeside server. Defaults to
"http://localhost/freeside".

The list of tests can be in a file specified after all arguments, or passed
to stdin.

=cut