1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
#!perl
# vim:ft=perl:
use strict;
use warnings;
use Test::More tests => 113;
use Test::Exception;
use constant METHODS => (
'new', 'to_form', 'from_form', 'rt_type', 'comment', 'correspond',
'attachments', 'transactions', 'take', 'untake', 'steal',
# attributes:
'id', 'queue', 'owner', 'creator', 'subject', 'status', 'priority',
'initial_priority', 'final_priority', 'requestors', 'cc', 'admin_cc',
'created', 'starts', 'started', 'due', 'resolved', 'told',
'time_estimated', 'time_worked', 'time_left', 'last_updated',
);
BEGIN {
use_ok('RT::Client::REST::Ticket');
}
my $ticket;
lives_ok {
$ticket = RT::Client::REST::Ticket->new;
} 'Ticket can get successfully created';
for my $method (METHODS) {
can_ok($ticket, $method);
}
for my $method (qw(comment correspond)) {
# Need local copy.
my $ticket = RT::Client::REST::Ticket->new;
throws_ok {
$ticket->$method(1);
} 'RT::Client::REST::Exception'; # Make sure exception inheritance works
throws_ok {
$ticket->$method(1);
} 'RT::Client::REST::Object::OddNumberOfArgumentsException';
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without RT object";
throws_ok {
$ticket->rt('anc');
} 'RT::Client::REST::Object::InvalidValueException',
"'rt' expects an actual RT object";
lives_ok {
$ticket->rt(RT::Client::REST->new);
} "RT object successfully set";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'id' attribute";
lives_ok {
$ticket->id(1);
} "'id' successfully set to a numeric value";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::InvalidValueException';
lives_ok {
$ticket->id(1);
} "'id' successfully set to a numeric value";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::InvalidValueException',
"Need 'message' to $method";
throws_ok {
$ticket->$method(message => 'abc');
} 'RT::Client::REST::RequiredAttributeUnsetException';
throws_ok {
$ticket->$method(
message => 'abc',
attachments => ['- this file does not exist -'],
);
} 'RT::Client::REST::CannotReadAttachmentException';
}
for my $method (qw(attachments transactions)) {
# Need local copy.
my $ticket = RT::Client::REST::Ticket->new;
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without RT object";
throws_ok {
$ticket->rt('anc');
} 'RT::Client::REST::Object::InvalidValueException',
"'rt' expects an actual RT object";
lives_ok {
$ticket->rt(RT::Client::REST->new);
} "RT object successfully set";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'id' attribute";
lives_ok {
$ticket->id(1);
} "'id' successfully set to a numeric value";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::RequiredAttributeUnsetException';
}
for my $method (qw(take untake steal)) {
# Need local copy.
my $ticket = RT::Client::REST::Ticket->new;
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without RT object";
throws_ok {
$ticket->rt('anc');
} 'RT::Client::REST::Object::InvalidValueException',
"'rt' expects an actual RT object";
lives_ok {
$ticket->rt(RT::Client::REST->new);
} "RT object successfully set";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::Object::RequiredAttributeUnsetException',
"won't go on without 'id' attribute";
lives_ok {
$ticket->id(1);
} "'id' successfully set to a numeric value";
throws_ok {
$ticket->$method;
} 'RT::Client::REST::RequiredAttributeUnsetException';
}
# Test list attributes:
my @emails = qw(dmitri@localhost dude@localhost);
throws_ok {
$ticket->requestors(@emails);
} 'RT::Client::REST::Object::InvalidValueException',
'List attributes (requestors) only accept array reference';
lives_ok {
$ticket->requestors(\@emails);
} 'Set requestors to list of two values';
ok(2 == $ticket->requestors, 'There are 2 requestors');
lives_ok {
$ticket->add_requestors(qw(xyz@localhost root pgsql));
} 'Added three more requestors';
ok(5 == $ticket->requestors, 'There are now 5 requestors');
lives_ok {
$ticket->delete_requestors('root');
} 'Deleted a requestor (root)';
ok(4 == $ticket->requestors, 'There are now 4 requestors');
ok('ticket' eq $ticket->rt_type);
# Test time parsing
$ticket->due('Thu Jan 12 11:14:31 2012');
my $dt = $ticket->due_datetime();
is($dt->year, 2012);
is($dt->month, 1);
is($dt->day, 12);
is($dt->hour, 11);
is($dt->minute, 14);
is($dt->second, 31);
is($dt->time_zone->name, 'UTC');
$dt = DateTime->new(
year => 1983,
month => 9,
day => 1,
hour => 1,
minute => 2,
second => 3,
time_zone => 'EST'
);
$dt=$ticket->due_datetime($dt);
is($dt->year, 1983);
is($dt->month, 9);
is($dt->day, 1);
is($dt->hour, 6);
is($dt->minute, 2);
is($dt->second, 3);
is($dt->time_zone->name, 'UTC');
is($ticket->due, 'Thu Sep 01 01:02:03 1983');
throws_ok {
$ticket->due_datetime(bless {}, 'foo');
} 'RT::Client::REST::Object::InvalidValueException';
|