aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/test-mailin38
-rwxr-xr-xbin/test-run223
2 files changed, 261 insertions, 0 deletions
diff --git a/bin/test-mailin b/bin/test-mailin
new file mode 100755
index 000000000..33f8ab80c
--- /dev/null
+++ b/bin/test-mailin
@@ -0,0 +1,38 @@
+#!/usr/bin/perl -w -I../../perllib
+#
+# test-mailin:
+# Receives incoming mail for the test harness, and stores it in the database
+# for the test harness to access.
+#
+# Hook this up with something like this in /etc/aliases...
+# pbharness: "| /home/francis/devel/mysociety/pb/bin/test-mailin"
+# ... or some other appropriate way.
+#
+# Copyright (c) 2005 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+
+# Horrible boilerplate to set up appropriate library paths.
+use FindBin;
+use lib "$FindBin::Bin/../perllib";
+use lib "$FindBin::Bin/../../perllib";
+chdir $FindBin::Bin;
+
+use File::Slurp;
+
+use mySociety::SystemMisc qw(print_log);
+mySociety::SystemMisc::log_to_stderr(0);
+
+use mySociety::Config;
+mySociety::Config::set_file('../conf/general');
+use mySociety::WebTestHarness;
+
+print_log('notice', "started");
+our $wth = new mySociety::WebTestHarness();
+$wth->database_connect('BCI_');
+print_log('notice', "reading mail from STDIN");
+my $slurped = read_file(\*STDIN);
+print_log('notice', "calling email_incoming");
+$wth->email_incoming($slurped);
+print_log('notice', "done");
+
diff --git a/bin/test-run b/bin/test-run
new file mode 100755
index 000000000..a91d34d0e
--- /dev/null
+++ b/bin/test-run
@@ -0,0 +1,223 @@
+#!/usr/bin/perl -w -I../../perllib
+#
+# test-run:
+# Test harness for FixMyStreet. Makes sure we haven't broken the code.
+#
+# Requires:
+# * ../conf/general file set up for FixMyStreet, and matching the below requirements
+# * apache configured to serve ../web on OPTION_BASE_URL
+# * a database with name ending "_testharness"; this script will drop and remake the
+# database, so make sure it is never used for anything important
+# * email addresses (email_n below) configured to pipe to ./test-mailin with fast
+# local delivery
+#
+# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
+# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
+
+# TODO
+# Admin
+# RSS
+# Whatever I've missed!
+
+my $rcsid = ''; $rcsid .= '$Id: test-run,v 1.1 2009-07-15 20:13:51 matthew Exp $';
+
+use strict;
+require 5.8.0;
+
+use FindBin;
+use Getopt::Long;
+use mySociety::Config;
+mySociety::Config::set_file('../conf/general');
+use mySociety::DBHandle qw(dbh);
+use mySociety::WebTestHarness;
+
+my %actions = (
+ 'report' => 'report a problem',
+ 'update' => 'leave an update on a report',
+ 'questionnaire' => 'receive and answer a questionnaire or two',
+ 'alert' => 'sign up for a local alert, and an update alert, check they arrive',
+ 'static' => 'check static pages',
+);
+
+sub help {
+ print <<END;
+
+Usage: test-run [OPTION] [ACTION]...
+
+Actions are a list of tests, run if present in this order:
+END
+ foreach (keys %actions) {
+ print " $_ - $actions{$_}\n";
+ }
+ print <<END;
+If you specify no actions, it will run all of them.
+
+Options are:
+ --verbose=n Choose 0 (no progress), 1 (basic actions), 2 (full debug)
+ --pause Pause after displaying URLs read from emails
+
+END
+}
+
+# Parse command line
+our $verbose = 0; # currently 3 levels: 0, 1 and 2
+our $pause = 0;
+our $multispawn = 1; # now crontab just runs on one machines anyway, gave up
+our $help;
+if (!GetOptions(
+ 'verbose=i' => \$verbose,
+ 'pause' => \$pause,
+ 'help' => \$help
+ )) {
+ help();
+ exit(1);
+}
+if ($help) {
+ help();
+ exit(0);
+}
+our %action;
+foreach (@ARGV) {
+ if ($actions{$_}) {
+ $action{$_} = 1;
+ } else {
+ help();
+ print "Action '$_' not known\n";
+ exit(0);
+ }
+}
+if (scalar(@ARGV) == 0) {
+ %action = map { $_ => 1 } keys %actions;
+ $action{all} = 1;
+}
+
+# Set up options
+our $base_url = mySociety::Config::get('BASE_URL');
+our $httpd_error_log = mySociety::Config::get('HTTPD_ERROR_LOG');
+our $email_domain = mySociety::Config::get('EMAIL_DOMAIN');
+our $contact_email = mySociety::Config::get('CONTACT_EMAIL');
+our $test_email_prefix = mySociety::Config::get('TEST_EMAIL_PREFIX');
+sub email_n { my $n = shift; return "$test_email_prefix+$n\@$email_domain"; }
+sub name_n { my $n = shift; return ($n % 100 == 0) ? "Rachel Reporter $n" : "Peter Person $n"; }
+
+#############################################################################
+# Main code
+
+# Configure test harness class
+date_print("Set up web test harness...");
+our $wth = new mySociety::WebTestHarness();
+$base_url =~ m#^http://(.+)/?$#;
+
+$wth->database_connect('BCI_');
+$wth->database_drop_reload('../db/schema.sql');
+$wth->database_load_schema('../db/alert_types.sql');
+$wth->database_cycle_sequences(200);
+# XXX As services are deployed now for Ratty, comment this out
+my $eveld_bin = "$FindBin::Bin/../../services/EvEl/bin/eveld";
+$eveld_bin = undef if ! -e $eveld_bin; # when running on servers rely on EvEl daemon, rather than calling EvEl binary directly as on Francis'' laptop XXX need more explicit way of distinguishing this case, than just checking evel isn't checked out in the same tree
+$wth->email_setup({ eveld_bin => $eveld_bin,
+ eveld_multispawn => $multispawn,
+ log_mailbox => "log_mailbox" });
+$wth->browser_set_validator("/usr/bin/validate");
+
+# Setup error log watching
+$wth->log_watcher_setup($httpd_error_log);
+$wth->log_watcher_self_test($base_url . "/test.php?error=1", "deliberate_error_to_test_error_handling");
+
+# Run the reports
+foreach (keys %action) {
+ date_print($actions{$_});
+ do_report() if $_ eq 'report';
+ do_update() if $_ eq 'update';
+ do_questionnaire() if $_ eq 'questionnaire';
+ do_alert() if $_ eq 'alert';
+ do_static() if $_ eq 'static';
+}
+
+# Check for any unhandled mails or errors
+call_send_emails();
+$wth->email_check_none_left(1);
+$wth->log_watcher_check();
+if ($action{'all'}) {
+ print "Everything completed successfully\n";
+} else {
+ print "Tests completed successfully\n";
+}
+
+#############################################################################
+# Functions to make and sign pledges, and so on
+
+# Print log line with date
+sub date_print {
+ $_ = shift;
+ print scalar localtime() . " $_\n";
+}
+
+# Print what we're doing
+sub comment {
+ my $comment = shift;
+ date_print(" $comment") if $verbose > 0;
+}
+sub verbose {
+ my $comment = shift;
+ date_print(" $comment") if $verbose > 1;
+}
+
+# display_url URL
+# Print the URL if in verbose mode. If --pause set, also print it and
+# wait for RETURN to be pressed.
+sub display_url {
+ my ($circumstance, $url) = @_;
+ $wth->email_check_url($url);
+ date_print("$circumstance: " . $url . "\n") if $verbose > 1 || $pause;
+ if ($pause) {
+ print "Press RETURN to continue";
+ readline(*STDIN);
+ }
+}
+
+# Change the date that all parts of PledgeBank think is today. Call with no
+# parameters to reset it to the actual today.
+sub set_pb_date {
+ my $new_date = shift;
+ if (defined($new_date)) {
+ dbh()->do('delete from debugdate');
+ dbh()->do('insert into debugdate (override_today) values (?)', {}, $new_date);
+ } else {
+ dbh()->do('delete from debugdate');
+ }
+ dbh()->commit();
+}
+
+# Database functions
+sub do_something_databasey {
+ my ($param) = @_;
+ dbh()->do('update something set foo = 1 where bar = ?', {}, $param);
+ dbh()->commit();
+}
+
+# Call all the email sending scripts
+sub call_send_emails {
+ $wth->multi_spawn($multispawn, "./send-reports " . ($verbose > 1 ? qw(--verbose) : ''), $verbose);
+ $wth->multi_spawn($multispawn, "./send-alerts", $verbose);
+ $wth->multi_spawn($multispawn, "./send-questionnaires " . ($verbose > 1 ? qw(--verbose) : ''), $verbose);
+}
+
+#############################################################################
+
+sub do_report {
+ $wth->browser_get($base_url);
+}
+
+sub do_update {
+}
+
+#browser_get(URL)
+#browser_follow_link(text_regex => qr//)
+#browser_check_contents(qr// | '')
+#browser_check_no_contents("successful");
+#browser_submit_form(form_name => '', fields => '', button => '')
+#browser_content();
+#email_get_containing( '%To: "' . name_n(3) . '" <' . email_n(3) . '>%From: "' . name_n(0) . '"%You signed this pledge after this message%Love and kisses%');
+#email_check_none_left();
+