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 | |
parent | cb49284dc0503b2a05ca2bb98b8a1320431c2616 (diff) |
Allow zurich tests to run without network.
-rw-r--r-- | t/Mock/MapItZurich.pm | 43 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 26 |
2 files changed, 58 insertions, 11 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; diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index e130ece87..4734dc837 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -5,9 +5,11 @@ use strict; use warnings; use DateTime; use Email::MIME; +use LWP::Protocol::PSGI; use Test::More; use Test::LongString; use Path::Tiny; +use t::Mock::MapItZurich; # Check that you have the required locale installed - the following # should return a line with de_CH.utf8 in. If not install that locale. @@ -72,7 +74,7 @@ $division->parent( $zurich->id ); $division->send_method( 'Zurich' ); $division->endpoint( 'division@example.org' ); $division->update; -$division->body_areas->find_or_create({ area_id => 274456 }); +$division->body_areas->find_or_create({ area_id => 423017 }); my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' ); $subdivision->parent( $division->id ); $subdivision->send_method( 'Zurich' ); @@ -701,10 +703,11 @@ subtest "only superuser can edit bodies" => sub { }; subtest "only superuser can see 'Add body' form" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); $user = $mech->log_in_ok( 'dm1@example.org' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [ 423017 ], }, sub { @@ -715,12 +718,12 @@ subtest "only superuser can see 'Add body' form" => sub { }; subtest "phone number is mandatory" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_ID_WHITELIST => [ 274456 ], - MAPIT_GENERATION => 2, + MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', }, sub { $user = $mech->log_in_ok( 'dm1@example.org' ); @@ -732,12 +735,12 @@ subtest "phone number is mandatory" => sub { }; subtest "phone number is not mandatory for reports from mobile apps" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], MAPIT_ID_WHITELIST => [ 423017 ], - MAPIT_GENERATION => 4, MAP_TYPE => 'Zurich,OSM', }, sub { $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , { @@ -759,6 +762,7 @@ subtest "phone number is not mandatory for reports from mobile apps" => sub { }; subtest "problems can't be assigned to deleted bodies" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); $user = $mech->log_in_ok( 'dm1@example.org' ); $user->from_body( $zurich->id ); $user->update; @@ -766,7 +770,7 @@ subtest "problems can't be assigned to deleted bodies" => sub { $report->update; FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', @@ -787,6 +791,7 @@ subtest "problems can't be assigned to deleted bodies" => sub { }; subtest "photo must be supplied for categories that require it" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::App->model('DB::Contact')->find_or_create({ body => $division, category => "Graffiti - photo required", @@ -800,10 +805,9 @@ subtest "photo must be supplied for categories that require it" => sub { }); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_ID_WHITELIST => [ 274456 ], - MAPIT_GENERATION => 2, + MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', }, sub { $mech->post_ok( '/report/new', { |