diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-03-23 09:26:46 +0000 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-03-23 09:27:10 +0000 |
commit | 5fa83565612ca0631e8c57862d39dba26b927cb1 (patch) | |
tree | 35a2dbb35164eb67d89e372f0fff7791ff860fdc /t/Mock | |
parent | cb49284dc0503b2a05ca2bb98b8a1320431c2616 (diff) |
Allow zurich tests to run without network.
Diffstat (limited to 't/Mock')
-rw-r--r-- | t/Mock/MapItZurich.pm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/t/Mock/MapItZurich.pm b/t/Mock/MapItZurich.pm new file mode 100644 index 000000000..ece9a9b22 --- /dev/null +++ b/t/Mock/MapItZurich.pm @@ -0,0 +1,43 @@ +package t::Mock::MapItZurich; + +use JSON::MaybeXS; +use Web::Simple; + +use mySociety::Locale; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /areas/**) { + my ($self, $areas) = @_; + my $response = { + "423017" => {"parent_area" => undef, "generation_high" => 4, "all_names" => {}, "id" => 423017, "codes" => {}, "name" => "Zurich", "country" => "G", "type_name" => "OpenStreetMap Layer 8", "generation_low" => 4, "country_name" => "Global", "type" => "O08"} + }; + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, + + sub (GET + /point/**) { + my ($self, $point) = @_; + my $response = { + "423017" => {"parent_area" => undef, "generation_high" => 4, "all_names" => {}, "id" => 423017, "codes" => {}, "name" => "Zurich", "country" => "G", "type_name" => "OpenStreetMap Layer 8", "generation_low" => 4, "country_name" => "Global", "type" => "O08"} + }; + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, + + sub (GET + /area/*/example_postcode) { + my ($self, $area) = @_; + my $json = $self->json->encode({}); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +__PACKAGE__->run_if_script; |