aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-05-13 10:49:26 +0100
committerMatthew Somerville <matthew@mysociety.org>2015-05-13 10:49:26 +0100
commit4e23c3aa7da5782be66295ac123bd63355d45a51 (patch)
treeda8c92c0b37939d87b26c61a0969df8045f7bb17
parent2dd5facb9272bd16025b182386c4026858880334 (diff)
Use mocked Nominatim to deal with bad connections.
-rw-r--r--t/Nominatim.pm37
-rw-r--r--t/app/controller/alert.t10
2 files changed, 45 insertions, 2 deletions
diff --git a/t/Nominatim.pm b/t/Nominatim.pm
new file mode 100644
index 000000000..2041b4677
--- /dev/null
+++ b/t/Nominatim.pm
@@ -0,0 +1,37 @@
+package t::Nominatim;
+
+use JSON;
+use Web::Simple;
+
+has json => (
+ is => 'lazy',
+ default => sub {
+ JSON->new->pretty->allow_blessed->convert_blessed;
+ },
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /search + ?q=) {
+ my ($self, $q) = @_;
+ my $response = $self->query($q);
+ my $json = $self->json->encode($response);
+ return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ];
+ },
+}
+
+sub query {
+ my ($self, $q) = @_;
+ if ($q eq 'high street') {
+ return [
+ {"osm_type"=>"way","osm_id"=>"4684282","lat"=>"55.9504009","lon"=>"-3.1858425","display_name"=>"High Street, Old Town, City of Edinburgh, Scotland, EH1 1SP, United Kingdom","class"=>"highway","type"=>"tertiary","importance"=>0.55892577838734},
+ {"osm_type"=>"node","osm_id"=>"27424410","lat"=>"55.8596449","lon"=>"-4.240377","display_name"=>"High Street, Collegelands, Merchant City, Glasgow, Glasgow City, Scotland, G, United Kingdom","class"=>"railway","type"=>"station","importance"=>0.53074299592768}
+ ];
+ }
+ return [];
+}
+
+
+
+__PACKAGE__->run_if_script;
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index 9189f5e97..5bf2af428 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -1,10 +1,13 @@
use strict;
use warnings;
use Test::More;
+use LWP::Protocol::PSGI;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
+use t::Nominatim;
+
# check that we can get the page
$mech->get_ok('/alert');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
@@ -38,8 +41,11 @@ FixMyStreet::override_config {
$mech->content_contains('council:2651:City_of_Edinburgh');
$mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre');
- $mech->get_ok('/alert/list?pc=High Street');
- $mech->content_contains('We found more than one match for that location');
+ subtest "Test Nominatim lookup" => sub {
+ LWP::Protocol::PSGI->register(t::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org');
+ $mech->get_ok('/alert/list?pc=High Street');
+ $mech->content_contains('We found more than one match for that location');
+ };
$mech->get_ok('/alert/list?pc=');
$mech->content_contains('To find out what local alerts we have for you');