From 7e4606306a62eac2ace15322d361b7ad36bcbecf Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 6 Sep 2012 16:03:01 +0100 Subject: send out open311 fms standard updates unless in extended mode --- t/open311.t | 70 +++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 16 deletions(-) (limited to 't') diff --git a/t/open311.t b/t/open311.t index 835d8d8cb..35b91faec 100644 --- a/t/open311.t +++ b/t/open311.t @@ -203,6 +203,26 @@ subtest 'basic request update post parameters' => sub { my $c = CGI::Simple->new( $results->{ req }->content ); + is $c->param('description'), 'this is a comment', 'email correct'; + is $c->param('email'), 'test@example.com', 'email correct'; + is $c->param('status'), 'OPEN', 'status correct'; + is $c->param('service_request_id'), 81, 'request id correct'; + is $c->param('updated_datetime'), DateTime::Format::W3CDTF->format_datetime($dt), 'correct date'; + is $c->param('title'), 'Mr', 'correct title'; + is $c->param('last_name'), 'User', 'correct first name'; + is $c->param('first_name'), 'Test', 'correct second name'; + is $c->param('media_url'), undef, 'no media url'; +}; + +subtest 'extended request update post parameters' => sub { + my $results = make_update_req( $comment, '248', 1 ); + + is $results->{ res }, 248, 'got update id'; + + my $req = $o->test_req_used; + + my $c = CGI::Simple->new( $results->{ req }->content ); + is $c->param('description'), 'this is a comment', 'email correct'; is $c->param('email'), 'test@example.com', 'email correct'; is $c->param('status'), 'OPEN', 'status correct'; @@ -236,42 +256,57 @@ foreach my $test ( { desc => 'comment with fixed state sends status of CLOSED', state => 'fixed', - anon => 0, status => 'CLOSED', }, { desc => 'comment with fixed - user state sends status of CLOSED', state => 'fixed - user', - anon => 0, status => 'CLOSED', }, { desc => 'comment with fixed - council state sends status of CLOSED', state => 'fixed - council', - anon => 0, status => 'CLOSED', }, { desc => 'comment with closed state sends status of CLOSED', state => 'closed', - anon => 0, status => 'CLOSED', }, { desc => 'comment with investigating state sends status of OPEN', state => 'investigating', - anon => 0, status => 'OPEN', }, { desc => 'comment with planned state sends status of OPEN', state => 'planned', - anon => 0, status => 'OPEN', }, { desc => 'comment with in progress state sends status of OPEN', state => 'in progress', + status => 'OPEN', + }, + { + state => 'confirmed', + status => 'OPEN', + }, +) { + subtest $test->{desc} => sub { + $comment->problem->state( $test->{state} ); + + my $results = make_update_req( $comment, '248' ); + + my $c = CGI::Simple->new( $results->{ req }->content ); + is $c->param('status'), $test->{status}, 'correct status'; + }; +} + +for my $test ( + { + desc => 'public comment sets public_anonymity_required to false', + state => 'confirmed', anon => 0, status => 'OPEN', }, @@ -286,10 +321,9 @@ foreach my $test ( $comment->problem->state( $test->{state} ); $comment->anonymous( $test->{anon} ); - my $results = make_update_req( $comment, '248' ); + my $results = make_update_req( $comment, '248', 1 ); my $c = CGI::Simple->new( $results->{ req }->content ); - is $c->param('status'), $test->{status}, 'correct status'; is $c->param('public_anonymity_required'), $test->{anon} ? 'TRUE' : 'FALSE', 'correct anonymity'; }; } @@ -504,15 +538,19 @@ done_testing(); sub make_update_req { my $comment = shift; my $xml = shift; + my $extended = shift; - return make_req( - { - object => $comment, - xml => $xml, - method => 'post_service_request_update', - path => 'update.xml', - } - ); + my $params = { + object => $comment, + xml => $xml, + method => 'post_service_request_update', + path => 'update.xml', + }; + + if ( $extended ) { + $params->{ open311_conf } = { use_extended_updates => 1 }; + } + return make_req( $params ); } sub make_service_req { -- cgit v1.2.3 From 12560a1fccd21bab8826ca6a89531f91c4def47f Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 7 Sep 2012 15:14:12 +0100 Subject: update getservice request tests for open311-fms version --- t/open311/getservicerequestupdates.t | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 7ec8d5ae0..17176a738 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -26,7 +26,6 @@ my $requests_xml = qq{ 638344 1 -1 open This is a note UPDATED_DATETIME @@ -42,25 +41,25 @@ for my $test ( { desc => 'basic parsing - element missing', updated_datetime => '', - res => { update_id => 638344, service_request_id => 1, service_request_id_ext => 1, + res => { update_id => 638344, service_request_id => 1, status => 'open', description => 'This is a note' }, }, { desc => 'basic parsing - empty element', updated_datetime => '', - res => { update_id => 638344, service_request_id => 1, service_request_id_ext => 1, + res => { update_id => 638344, service_request_id => 1, status => 'open', description => 'This is a note', updated_datetime => {} } , }, { desc => 'basic parsing - element with no content', updated_datetime => '', - res => { update_id => 638344, service_request_id => 1, service_request_id_ext => 1, + res => { update_id => 638344, service_request_id => 1, status => 'open', description => 'This is a note', updated_datetime => {} } , }, { desc => 'basic parsing - element with content', updated_datetime => sprintf( '%s', $dt ), - res => { update_id => 638344, service_request_id => 1, service_request_id_ext => 1, + res => { update_id => 638344, service_request_id => 1, status => 'open', description => 'This is a note', updated_datetime => $dt } , }, ) { @@ -76,6 +75,33 @@ for my $test ( }; } +subtest 'check extended request parsed correctly' => sub { + my $extended_requests_xml = qq{ + + + 638344 + 120384 + 1 + open + This is a note + UPDATED_DATETIME + + + }; + + my $updated_datetime = sprintf( '%s', $dt ); + my $expected_res = { update_id => 638344, service_request_id => 1, service_request_id_ext => 120384, + status => 'open', description => 'This is a note', updated_datetime => $dt }; + + $extended_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/; + + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $extended_requests_xml } ); + + my $res = $o->get_service_request_updates; + is_deeply $res->[0], $expected_res, 'result looks correct'; + +}; + my $problem_rs = FixMyStreet::App->model('DB::Problem'); my $problem = $problem_rs->new( { @@ -345,7 +371,6 @@ subtest 'check that existing comments are not duplicated' => sub { 638344 @{[ $problem->external_id ]} - @{[ $problem->id ]} open This is a note UPDATED_DATETIME @@ -353,7 +378,6 @@ subtest 'check that existing comments are not duplicated' => sub { 638354 @{[ $problem->external_id ]} - @{[ $problem->id ]} open This is a different note UPDATED_DATETIME2 @@ -421,7 +445,6 @@ foreach my $test ( { 638344 @{[ $problem->external_id ]} - @{[ $problem->id ]} closed This is a note UPDATED_DATETIME @@ -429,7 +452,6 @@ foreach my $test ( { 638354 @{[ $problem->external_id ]} - @{[ $problem->id ]} open This is a different note UPDATED_DATETIME2 @@ -475,7 +497,6 @@ foreach my $test ( { 638344 @{[ $problem->external_id ]} - @{[ $problem->id ]} closed This is a note UPDATED_DATETIME -- cgit v1.2.3 From 6044240b3ee49b20e3f40409786c179c9f0cfd09 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 8 Oct 2012 11:23:30 +0100 Subject: bring service request updates in line with our spec --- t/open311.t | 2 +- t/open311/getservicerequestupdates.t | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 't') diff --git a/t/open311.t b/t/open311.t index 35b91faec..15a3f2646 100644 --- a/t/open311.t +++ b/t/open311.t @@ -544,7 +544,7 @@ sub make_update_req { object => $comment, xml => $xml, method => 'post_service_request_update', - path => 'update.xml', + path => 'servicerequestupdates.xml', }; if ( $extended ) { diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 17176a738..aba811e58 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -67,7 +67,7 @@ for my $test ( my $local_requests_xml = $requests_xml; $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); my $res = $o->get_service_request_updates; is_deeply $res->[0], $test->{ res }, 'result looks correct'; @@ -95,7 +95,7 @@ subtest 'check extended request parsed correctly' => sub { $extended_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $extended_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $extended_requests_xml } ); my $res = $o->get_service_request_updates; is_deeply $res->[0], $expected_res, 'result looks correct'; @@ -197,7 +197,7 @@ for my $test ( $local_requests_xml =~ s#\d+#@{[$problem->id]}#; $local_requests_xml =~ s#\w+#closed# if $test->{close_comment}; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); $problem->comments->delete; $problem->lastupdate( DateTime->now()->subtract( days => 1 ) ); @@ -239,7 +239,7 @@ foreach my $test ( $local_requests_xml =~ s#\d+#@{[$problem->external_id]}#; $local_requests_xml =~ s#\d+#@{[$problem->id]}#; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); $problem->comments->delete; @@ -309,7 +309,7 @@ for my $test ( $local_requests_xml =~ s#\d+#$test->{request_id}#; $local_requests_xml =~ s#\d+#$test->{request_id_ext}#; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); my $council_details = { areaid => $test->{area_id} }; @@ -323,7 +323,7 @@ for my $test ( subtest 'using start and end date' => sub { my $local_requests_xml = $requests_xml; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $local_requests_xml } ); + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); my $start_dt = DateTime->now(); $start_dt->subtract( days => 1 ); @@ -406,7 +406,7 @@ subtest 'check that existing comments are not duplicated' => sub { $requests_xml =~ s/UPDATED_DATETIME2/$dt/; $requests_xml =~ s/UPDATED_DATETIME/@{[ $comment->confirmed ]}/; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $requests_xml } ); + 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( system_user => $user, @@ -467,7 +467,7 @@ foreach my $test ( { $requests_xml =~ s/UPDATED_DATETIME/$test->{dt1}/; $requests_xml =~ s/UPDATED_DATETIME2/$test->{dt2}/; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $requests_xml } ); + 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( system_user => $user, @@ -518,7 +518,7 @@ foreach my $test ( { $requests_xml =~ s/UPDATED_DATETIME/$dt/; - my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'update.xml' => $requests_xml } ); + 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( system_user => $user, -- cgit v1.2.3 From 0bbfcbe766cffafc6fa7367edbb62ca274d0fdb9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Oct 2012 13:11:21 +0100 Subject: handle updates to meta data as well as meta data when a contact is created --- t/open311/populate-service-list.t | 165 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) (limited to 't') diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index fbd729f3a..5910a8f13 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -269,6 +269,171 @@ subtest 'check meta data population' => sub { is_deeply $contact->extra, $extra, 'meta data saved'; }; +for my $test ( + { + desc => 'check meta data added to existing contact', + has_meta => 1, + orig_meta => undef, + end_meta => [ { + variable => 'true', + code => 'type', + datatype => 'string', + required => 'true', + datatype_description => 'Type of bin', + order => 1, + description => 'Type of bin' + + } ], + meta_xml => ' + + 100 + + + true + type + string + true + Type of bin + 1 + Type of bin + + + + ', + }, + { + desc => 'check meta data updated', + has_meta => 1, + orig_meta => [ { + variable => 'true', + code => 'type', + datatype => 'string', + required => 'true', + datatype_description => 'Type of bin', + order => 1, + description => 'Type of bin' + + } ], + end_meta => [ { + variable => 'true', + code => 'type', + datatype => 'string', + required => 'true', + datatype_description => 'Colour of bin', + order => 1, + description => 'Colour of bin' + + } ], + meta_xml => ' + + 100 + + + true + type + string + true + Colour of bin + 1 + Colour of bin + + + + ', + }, + { + desc => 'check meta data removed', + has_meta => 0, + end_meta => undef, + orig_meta => [ { + variable => 'true', + code => 'type', + datatype => 'string', + required => 'true', + datatype_description => 'Type of bin', + order => 1, + description => 'Type of bin' + + } ], + meta_xml => ' + + 100 + + + true + type + string + true + Type of bin + 1 + Type of bin + + + + ', + }, +) { + subtest $test->{desc} => sub { + my $processor = Open311::PopulateServiceList->new( council_list => [] ); + + my $services_xml = ' + + + 100 + Cans left out 24x7 + Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited. + false + realtime + lorem, ipsum, dolor + sanitation + + + '; + + if ( $test->{has_meta} ) { + $services_xml =~ s/metadata>false/metadata>true/ms; + } + + my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + { + area_id => 1, + email => '100', + category => 'Cans left out 24x7', + confirmed => 1, + deleted => 0, + editor => $0, + whenedited => \'ms_current_timestamp()', + note => 'test contact', + } + ); + + $contact->update( { extra => $test->{orig_meta} } ); + + my $o = Open311->new( + jurisdiction => 'mysociety', + endpoint => 'http://example.com', + test_mode => 1, + test_get_returns => { 'services.xml' => $services_xml, 'services/100.xml' => $test->{meta_xml} } + ); + + my $service_list = get_xml_simple_object( $services_xml ); + $service_list = { service => [ $service_list->{ service } ] }; + + my $council = FixMyStreet::App->model('DB::Open311conf')->new( { + area_id => 1 + } ); + + $processor->_current_open311( $o ); + $processor->_current_council( $council ); + + $processor->process_services( $service_list ); + + $contact->discard_changes; + + is_deeply $contact->extra, $test->{end_meta}, 'meta data saved'; + }; +} + subtest 'check attribute ordering' => sub { my $processor = Open311::PopulateServiceList->new( council_list => [] ); -- cgit v1.2.3 From b16213a1bc7d615d1ce09051a9f4573b190c1b09 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 22 Oct 2012 15:45:11 +0100 Subject: change the way we get open311 singlelist data so we can order it correctly for display --- t/app/controller/report_new_open311.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 863571ad0..55c5a92e8 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -29,7 +29,7 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { email => '100', extra => [ { description => 'Lamppost number', code => 'number', required => 'True' }, { description => 'Lamppost type', code => 'type', required => 'False', values => - { value => { Yellow => { key => 'modern' }, 'Gas' => { key => 'old' } } } + { value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] } } ], } ); -- cgit v1.2.3