[Rt-commit] r5248 - in RT-Extension-CommandByEmail: .
ruz at bestpractical.com
ruz at bestpractical.com
Thu May 18 10:34:00 EDT 2006
Author: ruz
Date: Thu May 18 10:34:00 2006
New Revision: 5248
Added:
RT-Extension-CommandByEmail/t/02.create.t
Modified:
RT-Extension-CommandByEmail/Makefile.PL
RT-Extension-CommandByEmail/t/utils.pl
Log:
* +117 tests on create
Modified: RT-Extension-CommandByEmail/Makefile.PL
==============================================================================
--- RT-Extension-CommandByEmail/Makefile.PL (original)
+++ RT-Extension-CommandByEmail/Makefile.PL Thu May 18 10:34:00 2006
@@ -5,9 +5,11 @@
author ('Jesse Vincent <jesse at bestpractical.com>');
license('perl');
+build_requires('Test::More');
+build_requires('IPC::Open2');
+
# the patch for RT-3.4.5 has this requirement
# RT may be require it too, but put it here to be sure
requires('UNIVERSAL::require');
-build_requires('Test::More');
WriteAll();
Added: RT-Extension-CommandByEmail/t/02.create.t
==============================================================================
--- (empty file)
+++ RT-Extension-CommandByEmail/t/02.create.t Thu May 18 10:34:00 2006
@@ -0,0 +1,223 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+my $test_ticket_id;
+
+diag("simle test of the mailgate") if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ $test_ticket_id = $id;
+}
+
+# XXX: use statuses from config/libs
+diag("set status on create") if $ENV{'TEST_VERBOSE'};
+foreach my $status ( qw(new open stalled rejected) ) {
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+Status: $status
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->Status, $status, 'set status' );
+}
+
+diag("set priority and final_priority on create") if $ENV{'TEST_VERBOSE'};
+foreach my $priority ( 10, 20 ) { foreach my $final_priority ( 5, 15, 20 ) {
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+Priority: $priority
+FinalPriority: $final_priority
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->Priority, $priority, 'set priority' );
+ is($obj->FinalPriority, $final_priority, 'set final priority' );
+} }
+
+# XXX: these test are fail as
+diag("set date on create") if $ENV{'TEST_VERBOSE'};
+foreach my $date ( qw(Due Starts Started) ) {
+ my $value = '2005-12-01 12:34:00';
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+$date: $value
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ my $method = $date .'Obj';
+ is($obj->$method->ISO, $value, 'set date' );
+}
+
+diag("set time on create") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(TimeWorked TimeEstimated TimeLeft) ) {
+ my $value = int rand 10;
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+$field: $value
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->$field(), $value, 'set time' );
+}
+
+
+diag("set watchers on create") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(Requestor Cc AdminCc) ) {
+ my $value = 'test at localhost';
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+$field: $value
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ my $method = $field .'Addresses';
+ is($obj->$method(), $value, 'set '. $field );
+}
+
+diag("add requestor on create") if $ENV{'TEST_VERBOSE'};
+{
+ my $value = 'test at localhost';
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+AddRequestor: $value
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->RequestorAddresses, "root\@localhost, $value", 'add requestor' );
+}
+
+diag("del requestor on create") if $ENV{'TEST_VERBOSE'};
+{
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+DelRequestor: root\@localhost
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->RequestorAddresses, '', 'del requestor' );
+}
+
+diag("set links on create") if $ENV{'TEST_VERBOSE'};
+foreach my $field ( qw(DependsOn DependedOnBy RefersTo ReferredToBy Members MemberOf) ) {
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+$field: $test_ticket_id
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+
+ my $links = $obj->$field();
+ ok($links, "ticket has links");
+ is($links->Count, 1, "one link");
+
+ my $link_type = $obj->LINKTYPEMAP->{ $field }->{'Type'};
+ my $link_mode = $obj->LINKTYPEMAP->{ $field }->{'Mode'};
+
+ my $link = $links->First;
+ is($link->Type, $link_type, "correct type");
+ isa_ok($link, 'RT::Link');
+ my $method = $link_mode .'Obj';
+ is($link->$method()->Id, $test_ticket_id, 'set '. $field );
+}
+
+diag("set custom fields on create") if $ENV{'TEST_VERBOSE'};
+{
+ require RT::CustomField;
+ my $cf = RT::CustomField->new( $RT::SystemUser );
+ my $cf_name = 'test'.rand $$;
+ $cf->Create( Name => $cf_name, Queue => 0, Type => 'Freeform' );
+ ok($cf->id, "created global CF");
+
+ my $text = <<END;
+Subject: test
+From: root\@localhost
+
+CustomField.{$cf_name}: foo
+
+test
+END
+ my $id = create_ticket_via_gate( $text );
+ ok($id, "created ticket");
+ my $obj = RT::Ticket->new( $RT::SystemUser );
+ $obj->Load( $id );
+ is($obj->id, $id, "loaded ticket");
+ is($obj->FirstCustomFieldValue($cf_name), 'foo', 'correct cf value' );
+}
+
+
+
+
+
Modified: RT-Extension-CommandByEmail/t/utils.pl
==============================================================================
--- RT-Extension-CommandByEmail/t/utils.pl (original)
+++ RT-Extension-CommandByEmail/t/utils.pl Thu May 18 10:34:00 2006
@@ -9,5 +9,42 @@
push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib);
}
+use RT;
+RT::LoadConfig();
+
+use IPC::Open2;
+
+### after: push @INC, qw(@RT_LIB_PATH@);
+our $mailgate = '/opt/rt3/bin/rt-mailgate';
+$mailgate .= ' --debug';
+$mailgate .= ' --url '. $RT::WebURL;
+
+sub run_gate {
+ my %args = (
+ message => '',
+ action => 'correspond',
+ queue => 'General',
+ @_
+ );
+ my $cmd = $mailgate
+ ." --queue '$args{'queue'}'"
+ ." --action $args{'action'}"
+ ." 2>&1";
+
+ my ($child_out, $child_in);
+ my $pid = open2($child_out, $child_in, $cmd);
+ print $child_in $args{'message'};
+ close $child_in;
+ my $result = do { local $/; <$child_out> };
+ return $result;
+}
+
+sub create_ticket_via_gate {
+ my $message = shift;
+ my $gate_result = run_gate( message => $message );
+ $gate_result =~ /Ticket: (\d+)/;
+ return $1;
+}
+
1;
More information about the Rt-commit
mailing list