diff options
Diffstat (limited to 't/Mock')
-rw-r--r-- | t/Mock/MapIt.pm | 26 | ||||
-rw-r--r-- | t/Mock/Nominatim.pm | 13 | ||||
-rw-r--r-- | t/Mock/Twilio.pm | 32 |
3 files changed, 62 insertions, 9 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 926d94b1e..8dd10c53d 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -81,10 +81,6 @@ sub dispatch_request { $self->output({2226 => {parent_area => undef, id => 2226, name => "Gloucestershire County Council", type => "CTY"}}); } elsif ($areas eq 'Cheltenham') { $self->output({2326 => {parent_area => undef, id => 2326, name => "Cheltenham Borough Council", type => "DIS"}}); - } elsif ($areas eq 'Lansdown and Park') { - $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}}); - } elsif ($areas eq 'Lansdown') { - $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}}); } elsif ($areas eq 'UTA') { $self->output({2650 => {parent_area => undef, id => 2650, name => "Aberdeen Council", type => "UTA"}}); } @@ -92,12 +88,30 @@ sub dispatch_request { sub (GET + /area/*) { my ($self, $area) = @_; - my $response = { "id" => $area, "name" => "Area $area", "type" => "UTA" }; - return $self->output($response); + my $response; + if ($area eq '999') { + $response = { code => 404, error => "No Area matches the given query." }; + return [ 404, [ 'Content-Type' => 'application/json' ], [ $self->json->encode($response) ] ]; + } else { + $response = { "id" => $area, "name" => "Area $area", "type" => "UTA" }; + return $self->output($response); + } }, sub (GET + /area/*/children) { my ($self, $area) = @_; + if ($area eq '2514') { + return $self->output({ + 8794 => {parent_area => 2514, id => 8794, name => "Aston", type => "MTW"}, + 8773 => {parent_area => 2514, id => 8773, name => "Bournville", type => "MTW"}, + }); + } + if ($area eq '2326') { + return $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}}); + } + if ($area eq '2226') { + return $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}}); + } my $response = { "60705" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 60705, "codes" => { "ons" => "00HY226", "gss" => "E04011842", "unit_id" => "17101" }, "name" => "Trowbridge", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" }, "62883" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 62883, "codes" => { "ons" => "00HY026", "gss" => "E04011642", "unit_id" => "17205" }, "name" => "Bradford-on-Avon", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" }, diff --git a/t/Mock/Nominatim.pm b/t/Mock/Nominatim.pm index 5c8c549d1..1f4e248d2 100644 --- a/t/Mock/Nominatim.pm +++ b/t/Mock/Nominatim.pm @@ -6,17 +6,24 @@ use Web::Simple; has json => ( is => 'lazy', default => sub { - JSON->new->pretty->allow_blessed->convert_blessed; + JSON->new->utf8->pretty->allow_blessed->convert_blessed; }, ); sub dispatch_request { my $self = shift; + sub (GET + /reverse + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/xml' ], [ '<result></result>' ] ]; + }, + sub (GET + /search + ?q=) { my ($self, $q) = @_; my $response = $self->query($q); - my $json = $self->json->encode($response); + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode($response); + }; return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; }, } @@ -25,7 +32,7 @@ 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"=>"way","osm_id"=>"4684282","lat"=>"55.9504009","lon"=>"-3.1858425","display_name"=>"High Street, Old Town, City of Ed\x{ed}nburgh, 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} ]; } diff --git a/t/Mock/Twilio.pm b/t/Mock/Twilio.pm new file mode 100644 index 000000000..125daa55f --- /dev/null +++ b/t/Mock/Twilio.pm @@ -0,0 +1,32 @@ +package t::Mock::Twilio; + +use Web::Simple; + +has texts => ( + is => 'ro', + default => sub { [] }, +); + +sub get_text_code { + my $self = shift; + my $text = shift @{$self->texts}; + return unless $text; + my ($code) = $text->{Body} =~ /(\d+)/; + return $code; +} + +sub dispatch_request { + my $self = shift; + + sub (POST + /2010-04-01/Accounts/*/Messages.json + %*) { + my ($self, $sid, $data) = @_; + if ($data->{To} eq '+18165550101') { + return [ 400, [ 'Content-Type' => 'application/json' ], + [ '{"code":"21408", "message": "Unable to send"}' ] ]; + } + push @{$self->texts}, $data; + return [ 200, [ 'Content-Type' => 'application/json' ], [ '{}' ] ]; + }, +} + +__PACKAGE__->run_if_script; |