diff options
author | Struan Donald <struan@exo.org.uk> | 2018-03-15 12:28:21 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2018-03-29 16:04:32 +0100 |
commit | 9e806177d239f20ce3b11bf220800b0623ebc075 (patch) | |
tree | 63a14f137c010cd6173e6c90ec6b47eb1a919b2f /t | |
parent | a540e87605871ffaa869cb987039d12c79f3b28c (diff) |
optionally convert from EPSG:27700 to WGS84 on report import
When pulling reports in over Open311 it's sometimes useful to be able to
accept reports with Easting/Northing rather than latitude/longitude.
This adds an option to GetServiceRequests to convert them as they
come in.
Diffstat (limited to 't')
-rw-r--r-- | t/Mock/MapIt.pm | 1 | ||||
-rw-r--r-- | t/open311/getservicerequests.t | 40 |
2 files changed, 40 insertions, 1 deletions
diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 8dd10c53d..1e94bb3e6 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -30,6 +30,7 @@ my @PLACES = ( [ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'OX20 1SZ', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], + [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], [ '?', 50.78301, -0.646929 ], [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ], diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index 878c178ef..6161ceac7 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -151,7 +151,6 @@ for my $test ( }; my $after_count = FixMyStreet::DB->resultset('Problem')->count; - warn $count; is $count, $after_count, "problems not created"; my $with_text = FixMyStreet::DB->resultset('Problem')->search( { @@ -258,6 +257,45 @@ for my $test ( }; } +for my $test ( + { + desc => 'convert easting/northing to lat/long', + subs => { lat => 168935, long => 540315 }, + expected => { lat => 51.402096, long => 0.015784 }, + }, +) { + subtest $test->{desc} => sub { + my $xml = prepare_xml( $test->{subs} ); + my $o = Open311->new( + jurisdiction => 'mysociety', + endpoint => 'http://example.com', + test_mode => 1, + test_get_returns => { 'requests.xml' => $xml} + ); + + my $update = Open311::GetServiceRequests->new( + system_user => $user, + convert_latlong => 1, + ); + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $update->create_problems( $o, $body ); + }; + + my $p = FixMyStreet::DB->resultset('Problem')->search( + { external_id => 123456 } + )->first; + + ok $p, 'problem created'; + is $p->latitude, $test->{expected}->{lat}, 'correct latitude'; + is $p->longitude, $test->{expected}->{long}, 'correct longitude'; + + $p->delete; + }; +} + sub prepare_xml { my $replacements = shift; |