Skip to content

Commit

Permalink
Merge 64a1a8c into c626fa7
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos authored Feb 16, 2022
2 parents c626fa7 + 64a1a8c commit c78168f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Default make_css to `web/cobrands` rather than `web`.
- Ability to pass custom arguments (eg: SSL config) to server when running via Docker
- Allow bin/fetch start/end times to be fractional.
- Add an --exclude option to bin/fetch.
- Open311 improvements:
- Increase default timeout.

Expand Down
6 changes: 4 additions & 2 deletions bin/fetch
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ my ($opts, $usage) = describe_options(
['updates', 'fetch updates'],
['start|s:f', 'start time to use (hours before now), defaults to one (reports) or two (updates)' ],
['end|e:f', 'end time to use (hours before now), defaults to zero' ],
['body|b:s', 'body name to only fetch this body' ],
['body|b:s@', 'body name(s) to only fetch these bodies' ],
['exclude|e:s@', 'body name(s) to exclude from fetching' ],
['verbose|v', 'more verbose output'],
['help|h', "print usage message and exit" ],
);
$usage->die if $opts->help;

my %params = (
verbose => $opts->verbose,
body => $opts->body,
bodies => $opts->body || [],
bodies_exclude => $opts->exclude || [],
);

my $dt = DateTime->now();
Expand Down
10 changes: 7 additions & 3 deletions perllib/Open311/GetServiceRequests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ 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 bodies => ( is => 'ro', default => sub { [] } );
has bodies_exclude => ( is => 'ro', default => sub { [] } );
has fetch_all => ( is => 'rw', default => 0 );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
Expand All @@ -27,8 +28,11 @@ sub fetch {
}
);

if ( $self->body ) {
$bodies = $bodies->search( { name => $self->body } );
if ( @{$self->bodies} ) {
$bodies = $bodies->search( { name => $self->bodies } );
}
if ( @{$self->bodies_exclude} ) {
$bodies = $bodies->search( { name => { -not_in => $self->bodies_exclude } } );
}

while ( my $body = $bodies->next ) {
Expand Down
10 changes: 7 additions & 3 deletions perllib/Open311/UpdatesBase.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ has send_comments_flag => ( is => 'ro' );
has commit => ( is => 'ro', default => 1 );

has system_user => ( is => 'rw' );
has body => ( is => 'ro', default => sub { undef } );
has bodies => ( is => 'ro', default => sub { [] } );
has bodies_exclude => ( is => 'ro', default => sub { [] } );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
has suppress_alerts => ( is => 'rw', default => 0 );
Expand All @@ -35,8 +36,11 @@ sub fetch {
}
);

if ( $self->body ) {
$bodies = $bodies->search( { name => $self->body } );
if ( @{$self->bodies} ) {
$bodies = $bodies->search( { name => $self->bodies } );
}
if ( @{$self->bodies_exclude} ) {
$bodies = $bodies->search( { name => { -not_in => $self->bodies_exclude } } );
}

my $procs_min = FixMyStreet->config('FETCH_COMMENTS_PROCESSES_MIN') || 0;
Expand Down
47 changes: 45 additions & 2 deletions t/open311/getservicerequestupdates.t
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ subtest 'check that can limit fetching to a body' => sub {
Open311->_inject_response('/servicerequestupdates.xml', $requests_xml);
my $update = Open311::GetServiceRequestUpdates->new(
body => 'Oxfordshire',
bodies => ['Oxfordshire'],
system_user => $user,
);
Expand All @@ -819,7 +819,50 @@ subtest 'check that can limit fetching to a body' => sub {
is $problem->comments->count, 0, 'no comments after fetching updates';
$update = Open311::GetServiceRequestUpdates->new(
body => 'Bromley',
bodies => ['Bromley'],
system_user => $user,
);
$update->fetch( $o );
$problem->discard_changes;
is $problem->comments->count, 1, '1 comment after fetching updates';
};
subtest 'check that can exclude fetching from 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' );
Open311->_inject_response('/servicerequestupdates.xml', $requests_xml);
my $update = Open311::GetServiceRequestUpdates->new(
bodies_exclude => ['Bromley'],
system_user => $user,
);
$update->fetch( $o );
$problem->discard_changes;
is $problem->comments->count, 0, 'no comments after fetching updates';
$update = Open311::GetServiceRequestUpdates->new(
bodies_exclude => ['Oxfordshire'],
system_user => $user,
);
Expand Down

0 comments on commit c78168f

Please sign in to comment.