aboutsummaryrefslogtreecommitdiffstats
path: root/examples/tg15/dhcp/conf-v4/ap-distro4.conf
blob: 63c3184a3c10d99cb86e24f93d7360a4fff64aba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
zone ap-distro4.tg15.gathering.org {
	primary 127.0.0.1;
	key DHCP_UPDATER;
}
subnet 151.216.179.0 netmask 255.255.255.192 {
	option subnet-mask 255.255.255.192;
	option routers 151.216.179.1;
	option domain-name "ap-distro4.tg15.gathering.org";
	ddns-domainname "ap-distro4.tg15.gathering.org";
	range 151.216.179.4 151.216.179.62;
}
a> 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

use FixMyStreet;
use FixMyStreet::App;
use FixMyStreet::TestMech;
use mySociety::Locale;
use Sub::Override;

mySociety::Locale::gettext_domain('FixMyStreet');

my $problem_rs = FixMyStreet::App->model('DB::Problem');

my $problem = $problem_rs->new(
    {
        postcode     => 'EH99 1SP',
        latitude     => '51.5016605453401',
        longitude    => '-0.142497580865087',
        areas        => 1,
        title        => '',
        detail       => '',
        used_map     => 1,
        user_id      => 1,
        name         => '',
        state        => 'confirmed',
        service      => '',
        cobrand      => 'default',
        cobrand_data => '',
    }
);

is $problem->confirmed,  undef, 'inflating null confirmed ok';
is $problem->whensent,   undef, 'inflating null confirmed ok';
is $problem->lastupdate, undef, 'inflating null confirmed ok';
is $problem->created,  undef, 'inflating null confirmed ok';

for my $test ( 
    {
        desc => 'more or less empty problem',
        changed => {},
        errors => {
            title => 'Please enter a subject',
            detail => 'Please enter some details',
            bodies => 'No council selected',
            name => 'Please enter your name',
        }
    },
    {
        desc => 'name too short',
        changed => {
            name => 'xx',
        },
        errors => {
            title => 'Please enter a subject',
            detail => 'Please enter some details',
            bodies => 'No council selected',
            name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
        }
    },
    {
        desc => 'name is anonymous',
        changed => {
            name => 'anonymous',
        },
        errors => {
            title => 'Please enter a subject',
            detail => 'Please enter some details',
            bodies => 'No council selected',
            name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
        }
    },
    {
        desc => 'correct name',
        changed => {
            name => 'A User',
        },
        errors => {
            title => 'Please enter a subject',
            detail => 'Please enter some details',
            bodies => 'No council selected',
        }
    },
    {
        desc => 'correct title',
        changed => {
            title => 'A Title',
        },
        errors => {
            detail => 'Please enter some details',
            bodies => 'No council selected',
        }
    },
    {
        desc => 'correct detail',
        changed => {
            detail => 'Some information about the problem',
        },
        errors => {
            bodies => 'No council selected',
        }
    },
    {
        desc => 'incorrectly formatted body',
        changed => {
            bodies_str => 'my body',
        },
        errors => {
            bodies => 'No council selected',
        }
    },
    {
        desc => 'correctly formatted body',
        changed => {
            bodies_str => '1001',
        },
        errors => {
        }
    },
    {
        desc => 'bad category',
        changed => {
            category => '-- Pick a category --',
        },
        errors => {
            category => 'Please choose a category',
        }
    },
    {
        desc => 'bad category',
        changed => {
            category => '-- Pick a property type --',
        },
        errors => {
            category => 'Please choose a property type',
        }
    },
    {
        desc => 'correct category',
        changed => {
            category => 'Horse!',
        },
        errors => {
        }
    },
) {
    $problem->$_( $test->{changed}->{$_} ) for keys %{$test->{changed}};

    subtest $test->{desc} => sub {
        is_deeply $problem->check_for_errors, $test->{errors}, 'check for errors';
    };
}

my $user = FixMyStreet::App->model('DB::User')->find_or_create(
    {
        email => 'system_user@example.com'
    }
);

$problem->user( $user );
$problem->created( DateTime->now()->subtract( days => 1 ) );
$problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
$problem->anonymous(1);
$problem->insert;

my $tz_local = DateTime::TimeZone->new( name => 'local' );

for my $test (
    {
        desc => 'request older than problem ignored',
        lastupdate => '',
        request => {
            updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local )->subtract( days => 2 ) ),
        },
        council => {
            name => 'Edinburgh City Council',
        },
        created => 0,
    },
    {
        desc => 'request newer than problem created',
        lastupdate => '',
        request => {
            updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
            status => 'open',
            status_notes => 'this is an update from the council',
        },
        council => {
            name => 'Edinburgh City Council',
        },
        created => 1,
        state => 'confirmed',
        mark_fixed => 0,
        mark_open => 0,
    },
    {
        desc => 'update with state of closed fixes problem',
        lastupdate => '',
        request => {
            updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
            status => 'closed',
            status_notes => 'the council have fixed this',
        },
        council => {
            name => 'Edinburgh City Council',
        },
        created => 1,
        state => 'fixed',
        mark_fixed => 1,
        mark_open => 0,
    },
    {
        desc => 'update with state of open leaves problem as fixed',
        lastupdate => '',
        request => {
            updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local ) ),
            status => 'open',
            status_notes => 'the council do not think this is fixed',
        },
        council => {
            name => 'Edinburgh City Council',
        },
        created => 1,
        start_state => 'fixed',
        state => 'fixed',
        mark_fixed => 0,
        mark_open => 0,
    },
) {
    subtest $test->{desc} => sub {
        # makes testing easier;
        $problem->comments->delete;
        $problem->created( DateTime->now()->subtract( days => 1 ) );
        $problem->lastupdate( DateTime->now()->subtract( days => 1 ) );
        $problem->state( $test->{start_state} || 'confirmed' );
        $problem->update;
        my $w3c = DateTime::Format::W3CDTF->new();

        my $ret = $problem->update_from_open311_service_request( $test->{request}, $test->{council}, $user );
        is $ret, $test->{created}, 'return value';

        return unless $test->{created};

        $problem->discard_changes;
        is $problem->lastupdate, $w3c->parse_datetime($test->{request}->{updated_datetime}), 'lastupdate time';

        my $update = $problem->comments->first;

        ok $update, 'updated created';

        is $problem->state, $test->{state}, 'problem state';

        is $update->text, $test->{request}->{status_notes}, 'update text';
        is $update->mark_open, $test->{mark_open}, 'update mark_open flag';
        is $update->mark_fixed, $test->{mark_fixed}, 'update mark_fixed flag';
    };
}

for my $test ( 
    {
        state => 'partial',
        is_visible  => 0,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'hidden',
        is_visible => 0,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'unconfirmed',
        is_visible => 0,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'confirmed',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 1,
        is_closed   => 0,
    },
    {
        state => 'investigating',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 1,
        is_closed   => 0,
    },
    {
        state => 'planned',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 1,
        is_closed   => 0,
    },
    {
        state => 'action scheduled',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 1,
        is_closed   => 0,
    },
    {
        state => 'in progress',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 1,
        is_closed   => 0,
    },
    {
        state => 'duplicate',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 1,
    },
    {
        state => 'not responsible',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 1,
    },
    {
        state => 'unable to fix',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 1,
    },
    {
        state => 'fixed',
        is_visible => 1,
        is_fixed    => 1,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'fixed - council',
        is_visible => 1,
        is_fixed    => 1,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'fixed - user',
        is_visible => 1,
        is_fixed    => 1,
        is_open     => 0,
        is_closed   => 0,
    },
    {
        state => 'closed',
        is_visible => 1,
        is_fixed    => 0,
        is_open     => 0,
        is_closed   => 1,
    },
) {
    subtest $test->{state} . ' is fixed/open/closed/visible' => sub {
        $problem->state( $test->{state} );
        is $problem->is_visible, $test->{is_visible}, 'is_visible';
        is $problem->is_fixed, $test->{is_fixed}, 'is_fixed';
        is $problem->is_closed, $test->{is_closed}, 'is_closed';
        is $problem->is_open, $test->{is_open}, 'is_open';
    };
}

my $mech = FixMyStreet::TestMech->new();

my %contact_params = (
    confirmed => 1,
    deleted => 0,
    editor => 'Test',
    whenedited => \'ms_current_timestamp()',
    note => 'Created for test',
);

for my $body (
    { id => 2651, name => 'City of Edinburgh Council' },
    { id => 2226, name => 'Gloucestershire County Council' },
    { id => 2326, name => 'Cheltenham Borough Council' },
    { id => 2434, name => 'Lichfield District Council' },
    { id => 2240, name => 'Staffordshire County Council' },
    { id => 14279, name => 'Ballymoney Borough Council' },
    { id => 2636, name => 'Isle of Wight Council' },
    { id => 2649, name => 'Fife Council' },
) {
    $mech->create_body_ok($body->{id}, $body->{name});
}

# Let's make some contacts to send things to!
FixMyStreet::App->model('DB::Contact')->search( {
    email => { 'like', '%example.com' },
} )->delete;
my @contacts;
for my $contact ( {
    body_id => 2651, # Edinburgh
    category => 'potholes',
    email => 'test@example.org',
}, {
    body_id => 2226, # Gloucestershire
    category => 'potholes',
    email => '2226@example.org',
}, {
    body_id => 2326, # Cheltenham
    category => 'potholes',
    email => '2326@example.org',
}, {
    body_id => 2434, # Lichfield
    category => 'potholes',
    email => 'trees@example.com',
}, {
    body_id => 2240, # Staffordshire
    category => 'potholes',
    email => 'highways@example.com',
}, {
    body_id => 14279, # Ballymoney
    category => 'Street lighting',
    email => 'roads.western@drdni.example.org',
}, {
    body_id => 14279, # Ballymoney
    category => 'Graffiti',
    email => 'highways@example.com',
}, {
    confirmed => 0,
    body_id => 2636, # Isle of Wight
    category => 'potholes',
    email => '2636@example.com',
} ) {
    my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, %$contact } );
    ok $new_contact, "created test contact";
    push @contacts, $new_contact;
}

my %common = (
    email => 'system_user@example.com',
    name => 'Andrew Smith',
);
foreach my $test ( {
        %common,
        desc          => 'sends an email',
        unset_whendef => 1,
        email_count   => 1,
        dear          => qr'Dear City of Edinburgh Council',
        to            => qr'City of Edinburgh Council',
        body          => 2651,
    }, {
        %common,
        desc          => 'no email sent if no unsent problems',
        unset_whendef => 0,
        email_count   => 0,
        body          => 2651,
    }, {
        %common,
        desc          => 'email to two tier council',
        unset_whendef => 1,
        email_count   => 1,
        to            => qr'Gloucestershire County Council.*Cheltenham Borough Council',
        dear          => qr'Dear Gloucestershire County Council and Cheltenham Borough',
        body          => '2226,2326',
        multiple      => 1,
    }, {
        %common,
        desc          => 'email to two tier council with one missing details',
        unset_whendef => 1,
        email_count   => 1,
        to            => qr'Gloucestershire County Council" <2226@example',
        dear          => qr'Dear Gloucestershire County Council,',
        body          => '2226|2649',
        missing       => qr'problem might be the responsibility of Fife.*Council'ms,
    }, {
        %common,
        desc          => 'email to two tier council that only shows district, district',
        unset_whendef => 1,
        email_count   => 1,
        to            => qr'Lichfield District Council',
        dear          => qr'Dear Lichfield District Council,',
        body          => '2434',
        cobrand       => 'lichfielddc',
        url           => 'lichfielddc.',
    }, {
        %common,
        desc          => 'email to two tier council that only shows district, county',
        unset_whendef => 1,
        email_count   => 1,
        to            => qr'Staffordshire County Council" <highways@example',
        dear          => qr'Dear Staffordshire County Council,',
        body          => '2240',
        cobrand       => 'lichfielddc',
        url           => '',
    }, {
        %common,
        desc          => 'directs NI correctly, 1',
        unset_whendef => 1,
        email_count   => 1,
        dear          => qr'Dear Ballymoney Borough Council',
        to            => qr'Ballymoney Borough Council',
        body          => 14279,
        category      => 'Graffiti',
    }, {
        %common,
        desc          => 'directs NI correctly, 2',
        unset_whendef => 1,
        email_count   => 1,
        dear          => qr'Dear Roads Service \(Western\)',
        to            => qr'Roads Service \(Western\)" <roads',
        body          => 14279,
        category      => 'Street lighting',
    }, {
        %common,
        desc          => 'does not send to unconfirmed contact',
        unset_whendef => 1,
        stays_unsent  => 1,
        email_count   => 0,
        body          => 2636,
    },
) {
    subtest $test->{ desc } => sub {
        if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) {
            plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand';
        }

        $mech->clear_emails_ok;

        FixMyStreet::App->model('DB::Problem')->search(
            {
                whensent => undef
            }
        )->update( { whensent => \'ms_current_timestamp()' } );

        $problem->discard_changes;
        $problem->update( {
            bodies_str => $test->{ body },
            state => 'confirmed',
            confirmed => \'ms_current_timestamp()',
            whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
            category => $test->{ category } || 'potholes',
            name => $test->{ name },
            cobrand => $test->{ cobrand } || 'fixmystreet',
        } );

        FixMyStreet::App->model('DB::Problem')->send_reports();

        $mech->email_count_is( $test->{ email_count } );
        if ( $test->{ email_count } ) {
            my $email = $mech->get_email;
            like $email->header('To'), $test->{ to }, 'to line looks correct';
            is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct';
            like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
            like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
            like $email->body, qr/Subject: A Title/, 'more email body checking';
            like $email->body, $test->{ dear }, 'Salutation looks correct';

            if ( $test->{multiple} ) {
                like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
            } elsif ( $test->{ missing } ) {
                like $email->body, $test->{ missing }, 'missing body information correct';
            }

            if ( $test->{url} ) {
                (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{};
                my $id = $problem->id;
                like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct';
            }

            $problem->discard_changes;
            ok defined( $problem->whensent ), 'whensent set';
        }
        if ( $test->{stays_unsent} ) {
            $problem->discard_changes;
            ok !defined( $problem->whensent ), 'whensent not set';
        }
    };
}

subtest 'check can turn on report sent email alerts' => sub {
    my $send_confirmation_mail_override = Sub::Override->new(
        "FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
        sub { return 1; }
    );
    $mech->clear_emails_ok;

    FixMyStreet::App->model('DB::Problem')->search(
        {
            whensent => undef
        }
    )->update( { whensent => \'ms_current_timestamp()' } );

    $problem->discard_changes;
    $problem->update( {
        bodies_str => 2651,
        state => 'confirmed',
        confirmed => \'ms_current_timestamp()',
        whensent => undef,
        category => 'potholes',
        name => 'Test User',
        cobrand => 'fixmystreet',
        send_fail_count => 0,
    } );

    FixMyStreet::App->model('DB::Problem')->send_reports();

    $mech->email_count_is( 2 );
    my @emails = $mech->get_email;
    my $email = $emails[0];

    like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct';
    is $email->header('From'), '"Test User" <system_user@example.com>', 'from line looks correct';
    like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
    like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
    like $email->body, qr/Subject: A Title/, 'more email body checking';
    like $email->body, qr/Dear City of Edinburgh Council/, 'Salutation looks correct';

    $problem->discard_changes;
    ok defined( $problem->whensent ), 'whensent set';

    $email = $emails[1];
    like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct';
    like $email->body, qr/Your report about/, 'report sent body correct';

    $send_confirmation_mail_override->restore();
};


subtest 'check iOS app store test reports not sent' => sub {
    $mech->clear_emails_ok;

    FixMyStreet::App->model('DB::Problem')->search(
        {
            whensent => undef
        }
    )->update( { whensent => \'ms_current_timestamp()' } );

    $problem->discard_changes;
    $problem->update( {
        bodies_str => 2651,
        title => 'App store test',
        state => 'confirmed',
        confirmed => \'ms_current_timestamp()',
        whensent => undef,
        category => 'potholes',
        send_fail_count => 0,
    } );

    FixMyStreet::App->model('DB::Problem')->send_reports();

    $mech->email_count_is( 0 );

    $problem->discard_changes();
    is $problem->state, 'hidden', 'iOS test reports are hidden automatically';
    is $problem->whensent, undef, 'iOS test reports are not sent';
};

subtest 'check reports from abuser not sent' => sub {
    $mech->clear_emails_ok;

    FixMyStreet::App->model('DB::Problem')->search(
        {
            whensent => undef
        }
    )->update( { whensent => \'ms_current_timestamp()' } );

    $problem->discard_changes;
    $problem->update( {
        bodies_str => 2651,
        title => 'Report',
        state => 'confirmed',
        confirmed => \'ms_current_timestamp()',
        whensent => undef,
        category => 'potholes',
        send_fail_count => 0,
    } );

    FixMyStreet::App->model('DB::Problem')->send_reports();

    $mech->email_count_is( 1 );

    $problem->discard_changes();
    ok $problem->whensent, 'Report has been sent';

    $problem->update( {
        state => 'confirmed',
        confirmed => \'ms_current_timestamp()',
        whensent => undef,
    } );

    my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } );

    $mech->clear_emails_ok;
    FixMyStreet::App->model('DB::Problem')->send_reports();

    $mech->email_count_is( 0 );

    $problem->discard_changes();
    is $problem->state, 'hidden', 'reports from abuse user are hidden automatically';
    is $problem->whensent, undef, 'reports from abuse user are not sent';

    ok $abuse->delete(), 'user removed from abuse table';
};


$problem->comments->delete;
$problem->delete;
$mech->delete_user( $user );

foreach (@contacts) {
    $_->delete;
}

done_testing();