aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-10-30 16:24:41 +0000
committerStruan Donald <struan@exo.org.uk>2018-11-02 11:41:52 +0000
commit96c9b73552ceb6d35f879dc212ee0fcc1cdcd6da (patch)
treec05ede9d8c2b92743f489a44da43ee9fab1b3d90
parent321ad0d6742f6fa9cf53bfa4d88bf9cbabfc4b83 (diff)
allow comment fetching to be limited by body name
Allows creating scripts that fetch comments for a single body, e.g for batch updating or because they require special setup.
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm5
-rw-r--r--t/open311/getservicerequestupdates.t42
2 files changed, 47 insertions, 0 deletions
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 20212bc95..60b37736c 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -9,6 +9,7 @@ use DateTime::Format::W3CDTF;
has system_user => ( is => 'rw' );
has start_date => ( is => 'ro', default => sub { undef } );
has end_date => ( is => 'ro', default => sub { undef } );
+has body => ( is => 'ro', default => sub { undef } );
has suppress_alerts => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
@@ -29,6 +30,10 @@ sub fetch {
}
);
+ if ( $self->body ) {
+ $bodies = $bodies->search( { name => $self->body } );
+ }
+
while ( my $body = $bodies->next ) {
my %open311_conf = (
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 7ebab3b3f..b9e29c99e 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -725,6 +725,48 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 2, 'if comments are deleted then they are added';
};
+subtest 'check that can limit fetching to a body' => sub {
+ my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+ <service_requests_updates>
+ <request_update>
+ <update_id>638344</update_id>
+ <service_request_id>@{[ $problem->external_id ]}</service_request_id>
+ <status>open</status>
+ <description>This is a note</description>
+ <updated_datetime>UPDATED_DATETIME</updated_datetime>
+ </request_update>
+ </service_requests_updates>
+ };
+
+ $problem->comments->delete;
+
+ is $problem->comments->count, 0, 'one comment before fetching updates';
+
+ $requests_xml =~ s/UPDATED_DATETIME/$dt/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
+
+ my $update = Open311::GetServiceRequestUpdates->new(
+ body => 'Oxfordshire',
+ system_user => $user,
+ );
+
+ $update->fetch( $o );
+
+ $problem->discard_changes;
+ is $problem->comments->count, 0, 'no comments after fetching updates';
+
+ $update = Open311::GetServiceRequestUpdates->new(
+ body => 'Bromley',
+ system_user => $user,
+ );
+
+ $update->fetch( $o );
+
+ $problem->discard_changes;
+ is $problem->comments->count, 1, '1 comment after fetching updates';
+};
+
subtest 'check that external_status_code is stored correctly' => sub {
my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
<service_requests_updates>