[Rt-commit] [rtir] 01/03: update constituency basics test to support constituencies rewrite in RTIR 3.4

Dustin Graves dustin at bestpractical.com
Fri May 13 19:11:33 EDT 2016


This is an automated email from the git hooks/post-receive script.

dustin pushed a commit to branch 3.4/rewrite-constituency-tests
in repository rtir.

commit 5c2be4f76d6eb92a2cf2e0bb94e6cd30a63f4302
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Fri May 13 23:06:54 2016 +0000

    update constituency basics test to support constituencies rewrite in RTIR 3.4
---
 t/constituency/basics.t | 261 ++++++++++++------------------------------------
 1 file changed, 64 insertions(+), 197 deletions(-)

diff --git a/t/constituency/basics.t b/t/constituency/basics.t
index c309df8..03a5abb 100644
--- a/t/constituency/basics.t
+++ b/t/constituency/basics.t
@@ -1,108 +1,49 @@
 use strict;
 use warnings;
 
-use Test::More skip_all => 'constituencies being rebuilt';
 use RT::IR::Test tests => undef;
 
 use_ok('RT::IR');
 
 my ($baseurl) = RT::Test->started_ok;
 my $agent = default_agent();
+my $rtir_user = RT::CurrentUser->new( rtir_user() );
 
 my $cf;
 diag "load and check basic properties of the CF" if $ENV{'TEST_VERBOSE'};
 {
-    my $cfs = RT::CustomFields->new( $RT::SystemUser );
-    $cfs->Limit( FIELD => 'Name', VALUE => 'Constituency', CASESENSITIVE => 0 );
+    my $cfs = RT::CustomFields->new( RT->SystemUser );
+    $cfs->Limit( FIELD => 'Name', VALUE => 'RTIR Constituency', CASESENSITIVE => 0 );
     is( $cfs->Count, 1, "found one CF with name 'Constituency'" );
 
     $cf = $cfs->First;
     is( $cf->Type, 'Select', 'type check' );
-    is( $cf->LookupType, 'RT::Queue-RT::Ticket', 'lookup type check' );
+    is( $cf->LookupType, 'RT::Queue', 'lookup type check' );
     is( $cf->MaxValues, 1, "single value" );
     ok( !$cf->Disabled, "not disabled" );
 }
 
 diag "check that CF applies to all RTIR's queues" if $ENV{'TEST_VERBOSE'};
 {
-    foreach ( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
-        my $queue = RT::Queue->new( $RT::SystemUser );
-        $queue->Load( $_ );
-        ok( $queue->id, 'loaded queue '. $_ );
-        my $cfs = $queue->TicketCustomFields;
+    my $queues = RT::Queues->new( RT->SystemUser );
+    $queues->Limit(
+        FIELD => 'Lifecycle',
+        OPERATOR => 'IN',
+        VALUE => [RT::IR->Lifecycles],
+    );
+
+    while ( my $queue = $queues->Next ) {
+        ok( $queue->id, 'loaded queue '. $queue->id );
+        my $cfs = $queue->CustomFields;
         $cfs->Limit( FIELD => 'id', VALUE => $cf->id, ENTRYAGGREGATOR => 'AND' );
         is( $cfs->Count, 1, 'field applies to queue' );
     }
 }
 
-my @constituencies;
-diag "fetch list of constituencies and check that groups exist" if $ENV{'TEST_VERBOSE'};
+diag "create constituencies EDUNET and GOVNET" if $ENV{'TEST_VERBOSE'};
 {
-    @constituencies = map $_->Name, @{ $cf->Values->ItemsArrayRef };
-    ok( scalar @constituencies, "field has some predefined values" );
-    foreach ( @constituencies ) {
-        my $group = RT::Group->new( $RT::SystemUser );
-        $group->LoadUserDefinedGroup( 'DutyTeam '. $_ );
-        ok( $group->id, "loaded group for $_ constituency" );
-    }
-}
-
-diag "check that there is no option to set 'no value' on create" if $ENV{'TEST_VERBOSE'};
-{
-    my $default = RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
-    foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
-        diag "'$queue' queue" if $ENV{'TEST_VERBOSE'};
-
-        $agent->goto_create_rtir_ticket( $queue );
-
-        my $value = $agent->form_number(3)->value("Object-RT::Ticket--CustomField-". $cf->id ."-Values");
-        is lc $value, lc $default, 'correct value is selected';
-
-        my @values = $agent->current_form->find_input("Object-RT::Ticket--CustomField-". $cf->id ."-Values")->possible_values;
-        ok !grep( $_ eq '', @values ), 'have no empty value for selection';
-    }
-}
-
-diag "create a ticket via web and set field" if $ENV{'TEST_VERBOSE'};
-{
-    # we skip blocks here, as they are always connected to
-    # an incident and constituency inheritance comes into game
-    foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations' ) {
-        diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
-
-        my $val = 'GOVNET';
-        my $id = $agent->create_rtir_ticket_ok(
-            $queue,
-            { Subject => "test ip" },
-            { Constituency => $val },
-        );
-
-        $agent->display_ticket( $id);
-        $agent->content_like( qr/\Q$val/, "value on the page" );
-        DBIx::SearchBuilder::Record::Cachable::FlushCache();
-
-        my $ticket = RT::Ticket->new( $RT::SystemUser );
-        $ticket->Load( $id );
-        ok( $ticket->id, 'loaded ticket' );
-        is( $ticket->FirstCustomFieldValue('Constituency'), $val, 'correct value' );
-
-diag "check that we can edit value" if $ENV{'TEST_VERBOSE'};
-        $agent->follow_link( text => 'Edit' );
-        $agent->content_like(qr/Constituency/, 'CF on the page');
-
-        my $value = $agent->form_number(3)->value("Object-RT::Ticket-$id-CustomField-". $cf->id ."-Values");
-        is lc $value, 'govnet', 'correct value is selected';
-
-        $val = 'EDUNET';
-        $agent->select("Object-RT::Ticket-$id-CustomField-". $cf->id ."-Values" => $val );
-        $agent->click('SaveChanges');
-        $agent->content_like(qr/Constituency .* changed to \Q$val/mi, 'field is changed') or diag $agent->content;
-        DBIx::SearchBuilder::Record::Cachable::FlushCache();
-
-        $ticket = RT::Ticket->new( $RT::SystemUser );
-        $ticket->Load( $id );
-        ok( $ticket->id, 'loaded ticket' );
-        is( lc $ticket->FirstCustomFieldValue('Constituency'), lc $val, 'correct value' );
+    for my $constituency_name ( qw(EDUNET GOVNET) ) {
+        ok !system("bin/add_constituency --quiet --force --name $constituency_name 2>&1"), "add_constituency $constituency_name ran successfully";
     }
 }
 
@@ -112,79 +53,27 @@ ok $eduhandler->id, "Created eduhandler";
 my $govhandler = RT::Test->load_or_create_user( Name => 'govhandler', Password => 'govhandler' );
 ok $govhandler->id, "Created govhandler";
 
-my $ir_queue = RT::Test->load_or_create_queue(
-    Name => 'Incident Reports',
-);
-ok $ir_queue->id, "loaded or created queue";
-
-ok( RT::Test->add_rights(
-    { Principal => 'Privileged', Right => [qw(ModifyCustomField SeeCustomField)], },
-), 'set rights');
-
-foreach my $name('Incident Reports', 'Incidents', 'Investigations', 'Blocks' ) {
-    my $queue = RT::Test->load_or_create_queue(
-        Name => "$name",
-        CorrespondAddress => 'rt at example.com',
-    );
-    ok $queue->id, "loaded or created queue";
-    ok( RT::Test->add_rights(
-        { Principal => $eduhandler, Object => $queue, Right => [qw(SeeQueue CreateTicket)] },
-        { Principal => $govhandler, Object => $queue, Right => [qw(SeeQueue CreateTicket)] },
-    ), 'set rights');
-
-    $queue = RT::Test->load_or_create_queue(
-        Name => "$name - EDUNET",
-        CorrespondAddress => 'edunet at example.com',
-    );
-    ok $queue->id, "loaded or created queue";
-    ok( RT::Test->add_rights(
-        { Principal => $eduhandler, Object => $queue, Right => [qw(ShowTicket CreateTicket OwnTicket)] },
-    ), 'set rights');
-    ok($queue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "eduhnadler can see edutix"); 
-    ok(!$queue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "govhnadler can not see edutix"); 
-
-    $queue = RT::Test->load_or_create_queue(
-        Name => "$name - GOVNET",
-        CorrespondAddress => 'govnet at example.com',
-    );
-    ok $queue->id, "loaded or created queue";
-    ok( RT::Test->add_rights(
-        { Principal => $govhandler, Object => $queue, Right => [qw(ShowTicket CreateTicket OwnTicket)] },
-    ), 'set rights');
-    ok(!$queue->HasRight(Principal => $eduhandler, Right => 'ShowTicket'), "eduhnadler can not see edutix"); 
-    ok($queue->HasRight(Principal => $govhandler, Right => 'ShowTicket'), "govhnadler can see edutix"); 
-}
+my $edugroup = RT::Group->new( RT->SystemUser );
+$edugroup->LoadUserDefinedGroup('DutyTeam EDUNET');
+$edugroup->AddMember( $eduhandler->PrincipalId );
+$edugroup->AddMember( $rtir_user->PrincipalId );
 
-diag "Create an incident report with a default constituency of EDUNET" if $ENV{'TEST_VERBOSE'};
+my $govgroup = RT::Group->new( RT->SystemUser );
+$govgroup->LoadUserDefinedGroup('DutyTeam GOVNET');
+$govgroup->AddMember( $govhandler->PrincipalId );
+$govgroup->AddMember( $rtir_user->PrincipalId );
 
+diag "Create an incident report in the EDUNET queue" if $ENV{'TEST_VERBOSE'};
 
-    my $val = 'EDUNET';
-    my $ir_id = $agent->create_ir(
-        { Subject => "test" }, { Constituency => $val }
-    );
-    ok( $ir_id, "created IR #$ir_id" );
-    $agent->display_ticket( $ir_id);
-    $agent->content_like(qr/EDUNET/, "It was created by edunet");
+my $ir_id = $agent->create_rtir_ticket_ok( 'Incident Reports - EDUNET', {
+    Subject => "test"
+});
+ok( $ir_id, "created IR #$ir_id" );
+$agent->display_ticket( $ir_id);
+$agent->content_like(qr/EDUNET/, "It was created by edunet");
 
-diag "autoreply comes from the EDUNET queue address" if $ENV{'TEST_VERBOSE'};
-my $ticket = RT::Ticket->new($RT::SystemUser);
+my $ticket = RT::Ticket->new(RT->SystemUser);
 $ticket->Load($ir_id);
-$ticket->AddWatcher(Type => 'Requestor', Email => 'enduser at example.com');
-$ticket->Correspond(Content => 'Testing');
-my $txns = $ticket->Transactions;
-$txns->Limit( FIELD => 'Type', VALUE => 'EmailRecord' );
-ok $txns->Count, 'we have at least one email record';
-
-my $from_ok = 1;
-while ( my $txn = $txns->Next ) {
-    my $from = $txn->Attachments->First->GetHeader('From');
-    next if $from =~ /edunet/;
-
-    $from_ok = 0;
-    last;
-}
-ok $from_ok, "The from address picked up the edunet address";
-
 
 diag "govhandler can't see the incident report"       if $ENV{'TEST_VERBOSE'};
 my $ticket_as_gov = RT::Ticket->new($govhandler);
@@ -198,20 +87,24 @@ $ticket_as_edu->Load($ir_id);
 is($ticket_as_edu->Subject, 'test', "As the edu handler, I can see the ticket");
 
 
-
-
 diag "move the incident report from EDUNET to GOVNET" if $ENV{'TEST_VERBOSE'};
 {
     $agent->display_ticket( $ir_id);
     $agent->follow_link_ok({text => 'Edit'}, "go to Edit page");
     $agent->form_number(3);
-    ok($agent->set_custom_field( 'Incident Reports', Constituency => 'GOVNET' ), "fill value in the form");
+
+    my $ir_govnet = RT::Queue->new( RT->SystemUser );
+    $ir_govnet->Load( 'Incident Reports - GOVNET' );
+
+    $agent->set_fields(
+        Queue => $ir_govnet->id,
+    );
+
     $agent->click('SaveChanges');
     is( $agent->status, 200, "Attempting to edit ticket #$ir_id" );
     $agent->content_like( qr/GOVNET/, "value on the page" );
 
     DBIx::SearchBuilder::Record::Cachable::FlushCache();
-        $RT::IR::ConstituencyCache{$ir_id}  = undef;
 }
 
 diag "govhandler can see the incident report"         if $ENV{'TEST_VERBOSE'};
@@ -220,87 +113,61 @@ $ticket_as_gov->Load($ir_id);
 is($ticket_as_gov->Subject, 'test',"As the gov handler, I can see the ticket");
 
 diag "eduhandler can't see the incident report"       if $ENV{'TEST_VERBOSE'};
- 
+
 $ticket_as_edu = RT::Ticket->new($eduhandler);
 $ticket_as_edu->Load($ir_id);
 is($ticket_as_edu->Subject,undef , "As the edu handler, I can not see the ticket");
 
-diag "govhandler replies to the incident report" if $ENV{'TEST_VERBOSE'};
-$ticket_as_gov->Correspond(Content => 'Testing 2');
-diag "reply comes from the GOVNET queue address" if $ENV{'TEST_VERBOSE'};
-{
-my $txns = $ticket->Transactions;
-my $from;
-while (my $txn = $txns->Next) {
-    next unless ($txn->Type eq 'EmailRecord');
-    $from = $txn->Attachments->First->GetHeader('From');
-}
-ok($from =~ /govnet/, "The from address pciked up the gov address");
 
-}
+my $edunet_suffix = ' - EDUNET';
+my $govnet_suffix = ' - GOVNET';
 
-diag "check defaults";
+diag "check queues names on page - eduhandler";
 {
     $agent->login('eduhandler', 'eduhandler', logout => 1 );
-    my $ir_id = $agent->create_ir(
-        { Subject => "test" },
-    );
-    my $ticket = RT::Ticket->new($RT::SystemUser);
-    $ticket->Load($ir_id);
-    is( $ticket->FirstCustomFieldValue('Constituency'), 'EDUNET', 'correct value' );
+
+    for my $queue_name ('Incident Reports', 'Incidents', 'Blocks', 'Investigations') {
+        $agent->content_contains($queue_name . $edunet_suffix);
+        $agent->content_lacks($queue_name . $govnet_suffix);
+    }
 }
 
-diag "check defaults";
+diag "check queue names on page - govhandler";
 {
     $agent->login('govhandler', 'govhandler', logout => 1);
-    my $ir_id = $agent->create_ir(
-        { Subject => "test" },
-    );
-    my $ticket = RT::Ticket->new($RT::SystemUser);
-    $ticket->Load($ir_id);
-    is( $ticket->FirstCustomFieldValue('Constituency'), 'GOVNET', 'correct value' );
+
+    for my $queue_name ('Incident Reports', 'Incidents', 'Blocks', 'Investigations') {
+        $agent->content_lacks($queue_name . $edunet_suffix);
+        $agent->content_contains($queue_name . $govnet_suffix);
+    }
 }
 
-diag "check defaults when creating inc with inv";
+diag "check queues when creating inc with inv - govhandler";
 {
     $agent->login('govhandler', 'govhandler', logout => 1);
 	my ($inc_id, $inv_id) = $agent->create_incident_and_investigation('GOVNET',
 	    {
-            Subject => "Incident", 
+            Subject => "Incident",
 		    InvestigationSubject => "Investigation",
 		    InvestigationRequestors => 'requestor at example.com',
         },
     );
-    {
-        my $ticket = RT::Ticket->new($RT::SystemUser);
-        $ticket->Load($inc_id);
-        is( $ticket->FirstCustomFieldValue('Constituency'), 'GOVNET', 'correct value' );
-    } {
-        my $ticket = RT::Ticket->new($RT::SystemUser);
-        $ticket->Load($inv_id);
-        is( $ticket->FirstCustomFieldValue('Constituency'), 'GOVNET', 'correct value' );
-    }
+    $agent->content_contains('Incidents'.$govnet_suffix);
+    $agent->content_contains('Investigations'.$govnet_suffix);
 }
 
-diag "check defaults when creating inc with inv";
+diag "check queues when creating inc with inv - eduhandler";
 {
     $agent->login('eduhandler', 'eduhandler', logout => 1);
 	my ($inc_id, $inv_id) = $agent->create_incident_and_investigation('EDUNET',
 	    {
-            Subject => "Incident", 
+            Subject => "Incident",
 		    InvestigationSubject => "Investigation",
 		    InvestigationRequestors => 'requestor at example.com',
         },
     );
-    {
-        my $ticket = RT::Ticket->new($RT::SystemUser);
-        $ticket->Load($inc_id);
-        is( $ticket->FirstCustomFieldValue('Constituency'), 'EDUNET', 'correct value' );
-    } {
-        my $ticket = RT::Ticket->new($RT::SystemUser);
-        $ticket->Load($inv_id);
-        is( $ticket->FirstCustomFieldValue('Constituency'), 'EDUNET', 'correct value' );
-    }
+    $agent->content_contains('Incidents'.$edunet_suffix);
+    $agent->content_contains('Investigations'.$edunet_suffix);
 }
 
 undef $agent;

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the rt-commit mailing list