diff options
author | Dave Arter <davea@mysociety.org> | 2019-04-12 16:04:49 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2019-06-04 14:54:50 +0100 |
commit | 6da4f2a979a87e82360ce024a9630f7194684718 (patch) | |
tree | d725662d5e72db7473cf1e8a9373a5feaf7a6bcf | |
parent | 0d67c672ca10538695eadd48c406e2707ea9c5c6 (diff) |
[Hounslow] Don't fetch non_public reports at all from Open311
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Hounslow.pm | 5 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequests.pm | 5 | ||||
-rw-r--r-- | t/Mock/MapIt.pm | 1 | ||||
-rw-r--r-- | t/open311/getservicerequests.t | 69 |
4 files changed, 79 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm index fdcfd4fd5..f6da8f2dd 100644 --- a/perllib/FixMyStreet/Cobrand/Hounslow.pm +++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm @@ -95,6 +95,11 @@ sub open311_munge_update_params { } } +sub open311_skip_report_fetch { + my ($self, $problem) = @_; + + return 1 if $problem->non_public; +} sub lookup_site_code_config { { buffer => 50, # metres diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm index 09a51319e..a9ec88a70 100644 --- a/perllib/Open311/GetServiceRequests.pm +++ b/perllib/Open311/GetServiceRequests.pm @@ -146,7 +146,8 @@ sub create_problems { next; } - if ( my $cobrand = $body->get_cobrand_handler ) { + my $cobrand = $body->get_cobrand_handler; + if ( $cobrand ) { my $filtered = $cobrand->call_hook('filter_report_description', $request->{description}); $request->{description} = $filtered if defined $filtered; } @@ -185,6 +186,8 @@ sub create_problems { } ); + next if $cobrand && $cobrand->call_hook(open311_skip_report_fetch => $problem); + $open311->add_media($request->{media_url}, $problem) if $request->{media_url}; diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 7429d9731..c255c916a 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -39,6 +39,7 @@ my @PLACES = ( [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], [ 'NN1 1NS', 52.236251, 0.892052, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ], [ 'NN1 2NS', 52.238301, 0.889992, 2234, 'Northamptonshire County Council', 'CTY', 2397, 'Northampton Borough Council', 'DIS' ], + [ 'TW7 5JN', 51.482286, -0.328163, 2483, 'Hounslow Borough Council', 'LBO' ], [ '?', 50.78301, -0.646929 ], [ 'TA1 1QP', 51.023569, -3.099055, 2239, 'Somerset County Council', 'CTY', 2429, 'Taunton Deane Borough Council', 'DIS' ], [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], diff --git a/t/open311/getservicerequests.t b/t/open311/getservicerequests.t index 01613cb58..c44be5099 100644 --- a/t/open311/getservicerequests.t +++ b/t/open311/getservicerequests.t @@ -17,6 +17,9 @@ my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Sidew my $body2 = $mech->create_body_ok(2217, 'Buckinghamshire'); my $contact2 = $mech->create_contact_ok( body_id => $body2->id, category => 'Sidewalk and Curb Issues', email => 'sidewalks' ); +my $hounslow = $mech->create_body_ok(2483, 'Hounslow'); +my $hounslowcontact = $mech->create_contact_ok( body_id => $hounslow->id, category => 'Sidewalk and Curb Issues', email => 'sidewalks' ); + my $dtf = DateTime::Format::W3CDTF->new; my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> @@ -469,6 +472,72 @@ for my $test ( }; } +my $hounslow_non_public_xml = qq[<?xml version="1.0" encoding="utf-8"?> +<service_requests> +<request> +<service_request_id>123456</service_request_id> +<status>open</status> +<status_notes></status_notes> +<service_name>Sidewalk and Curb Issues</service_name> +<service_code>sidewalks</service_code> +<description>this is a problem</description> +<agency_responsible></agency_responsible> +<service_notice></service_notice> +<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime> +<updated_datetime>2010-04-14T06:37:38-08:00</updated_datetime> +<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime> +<lat>51.482286</lat> +<long>-0.328163</long> +<non_public>1</non_public> +</request> +</service_requests> +]; + +for my $test ( + { + desc => 'Hounslow non_public reports not created', + non_public => 1, + count => 0, + }, + { + desc => 'Hounslow public reports are created', + non_public => 0, + count => 1, + }, +) { + subtest $test->{desc} => sub { + (my $xml = $hounslow_non_public_xml) =~ s/non_public>1/non_public>$test->{non_public}/; + + 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, + start_date => $start_date, + end_date => $end_date + ); + + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/', + ALLOWED_COBRANDS => [ 'hounslow' ], + }, sub { + $update->create_problems( $o, $hounslow ); + }; + + my $q = FixMyStreet::DB->resultset('Problem')->search( + { external_id => 123456 } + ); + + is $q->count, $test->{count}, 'problem count is correct'; + + $q->first->delete if $test->{count}; + }; +} + subtest "non_public contacts result in non_public reports" => sub { $contact->update({ |