diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-09-15 17:34:12 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-09-15 17:34:12 +0100 |
commit | a2a1d29ebb3b6c5a9adbc73ff135aea05390e381 (patch) | |
tree | c8522b5f2a62648e39b90029706cd0938ece3e9d /t | |
parent | 96c584269d7b244ac93cd282470d9abffb99a6c0 (diff) |
Mock MapIt postcode call to fix broken tests.
SW1A 1AA has moved, who'd have thought.
Diffstat (limited to 't')
-rw-r--r-- | t/MapIt.pm | 17 | ||||
-rw-r--r-- | t/app/controller/around.t | 10 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 29 |
3 files changed, 39 insertions, 17 deletions
diff --git a/t/MapIt.pm b/t/MapIt.pm index ebef934e1..a10118013 100644 --- a/t/MapIt.pm +++ b/t/MapIt.pm @@ -24,12 +24,27 @@ sub dispatch_request { $self->json->encode($response) }; return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; }, + + sub (GET + /point/**) { + my ($self, $point) = @_; + my $response = { + "63999" => {"parent_area" => 2245, "generation_high" => 25, "all_names" => {}, "id" => 63999, "codes" => {"ons" => "00HYNS", "gss" => "E05008366", "unit_id" => "44025"}, "name" => "Kington", "country" => "E", "type_name" => "Unitary Authority electoral division (UTE)", "generation_low" => 12, "country_name" => "England", "type" => "UTE"}, + "65822" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 65822, "codes" => {"gss" => "E14000860", "unit_id" => "24903"}, "name" => "North Wiltshire", "country" => "E", "type_name" => "UK Parliament constituency", "generation_low" => 13, "country_name" => "England", "type" => "WMC"}, + "11814" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 11814, "codes" => {"ons" => "09", "gss" => "E15000009", "unit_id" => "41427"}, "name" => "South West", "country" => "E", "type_name" => "European region", "generation_low" => 1, "country_name" => "England", "type" => "EUR"}, + "2245" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 2245, "codes" => {"ons" => "00HY", "gss" => "E06000054", "unit_id" => "43925"}, "name" => "Wiltshire Council", "country" => "E", "type_name" => "Unitary Authority", "generation_low" => 11, "country_name" => "England", "type" => "UTA"} + }; + # We must make sure we output correctly for testing purposes, we might + # be within a different locale here... + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode($response) }; + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, } sub postcode { my ($self, $postcode) = @_; return { - wgs84_lat => 51.5, wgs84_lon => 2.1, postcode => $postcode, + wgs84_lat => 51.5, wgs84_lon => -2.1, postcode => $postcode, coordsyst => 'G', }; } diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 03bcebf96..a70116525 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -1,7 +1,9 @@ use strict; use warnings; use Test::More; +use LWP::Protocol::PSGI; +use t::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -71,8 +73,8 @@ foreach my $test ( foreach my $test ( { pc => 'SW1A 1AA', - latitude => '51.501009', - longitude => '-0.141588', + latitude => '51.5', + longitude => '-2.1', }, { pc => 'TQ 388 773', @@ -82,10 +84,12 @@ foreach my $test ( ) { subtest "check lat/lng for '$test->{pc}'" => sub { + LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); + $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "good location" ); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index ff6508149..16874ac3c 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -1,7 +1,9 @@ use strict; use warnings; use Test::More; +use LWP::Protocol::PSGI; +use t::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; use Web::Scraper; @@ -17,7 +19,7 @@ ok -e $sample_file, "sample file $sample_file exists"; FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } -my $body = $mech->create_body_ok(2504, 'Westminster City Council'); +my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); $mech->create_contact_ok( body_id => $body->id, category => 'Street lighting', @@ -90,6 +92,7 @@ subtest "Test creating bad partial entries" => sub { }; subtest "Submit a correct entry" => sub { + LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); $mech->get_ok('/import'); @@ -120,7 +123,7 @@ subtest "Submit a correct entry" => sub { # go to the token url FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok($token_url); }; @@ -134,10 +137,10 @@ subtest "Submit a correct entry" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( - { with_fields => { pc => 'SW1A 1AA' } }, + { with_fields => { pc => 'SN15 5NG' } }, "fill in postcode" ); }; @@ -159,15 +162,15 @@ subtest "Submit a correct entry" => sub { # Check photo present, and still there after map submission (testing bug #18) $mech->content_contains( '<img align="right" src="/photo/' ); - $mech->content_contains('latitude" value="51.501009"', 'Check latitude'); - $mech->content_contains('longitude" value="-0.141588"', 'Check longitude'); + $mech->content_contains('latitude" value="51.5"', 'Check latitude'); + $mech->content_contains('longitude" value="-2.1"', 'Check longitude'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { - button => 'tile_32742.21793', + button => 'tile_16192.10896', x => 10, y => 10, }, @@ -175,8 +178,8 @@ subtest "Submit a correct entry" => sub { ); }; $mech->content_contains( '<img align="right" src="/photo/' ); - $mech->content_contains('latitude" value="51.50519"', 'Check latitude'); - $mech->content_contains('longitude" value="-0.142608"', 'Check longitude'); + $mech->content_contains('latitude" value="51.508475"', 'Check latitude'); + $mech->content_contains('longitude" value="-2.108946"', 'Check longitude'); # check that fields haven't changed at all is_deeply $mech->visible_form_values, @@ -194,7 +197,7 @@ subtest "Submit a correct entry" => sub { # change the details FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { @@ -232,8 +235,8 @@ subtest "Submit a correct entry (with location)" => sub { { with_fields => { service => 'test-script', - lat => '51.5010096115539', # SW1A 1AA - lon => '-0.141587067110009', + lat => '51.5', + lon => '-2.1', name => 'Test User ll', email => 'test-ll@example.com', subject => 'Test report ll', |