[Rt-commit] [svn] r828 - in RT-Client: . lib/RT t

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Tue May 4 13:43:38 EDT 2004


Author: autrijus
Date: Tue May  4 13:43:37 2004
New Revision: 828

Added:
   RT-Client/t/
   RT-Client/t/spec.t
Modified:
   RT-Client/   (props changed)
   RT-Client/lib/RT/Client.pm
Log:
 ----------------------------------------------------------------------
 r4460 at not:  autrijus | 2004-05-04T15:50:56.659921Z
 
 * Clean up POD some more.
 * Supports the 'su' function, $rt->current_user(), to act on behalf of
   other users.
 ----------------------------------------------------------------------
 r4463 at not:  autrijus | 2004-05-04T17:43:12.069180Z
 
 * the verb "Put" is now "Set".
 * Beginning of the test suite according to the spec.
 
 ----------------------------------------------------------------------


Modified: RT-Client/lib/RT/Client.pm
==============================================================================
--- RT-Client/lib/RT/Client.pm	(original)
+++ RT-Client/lib/RT/Client.pm	Tue May  4 13:43:37 2004
@@ -23,7 +23,7 @@
 
     my $rt = RT::Client->new('http://root@password:localhost');
 
-    # search / list
+    # search
     my $results = $rt->search(
         URI     => 'tickets',
         Query   => "Priority > 5 and Status='new'",
@@ -37,22 +37,20 @@
     # perform actions
     $results->delete(); # perform action
 
-    # get / show -- single parameter means URI implicitly
-    my $user = $rt->get( 'users/autrijus' );
+    # get
+    my $user = $rt->Users('autrijus');
 
-    # update / edit
-    my $group = $rt->edit(
-        URI     => 'groups/3',
-        Set     => { Disabled => 1 },
-        Add     => {},
-        Delete  => {},
-    );
+    # switch identity - superuser only!
+    $rt->current_user('autrijus');
 
-    # create / insert
-    my $queue = $rt->create(
-        URI     => 'queues',
-        Set     => { Name => 'Test Queue' },
-    );
+    # switch back
+    $rt->current_user($rt->username);
+
+    # update
+    my $group = $rt->Groups(3)->update( Disabled => 1 );
+
+    # add
+    my $queue = $rt->Queues->add( Name => 'Test Queue' );
 
 =head1 DESCRIPTION
 
@@ -71,7 +69,7 @@
         update      createUpdate
 
         get         getEntry
-        put         updateEntry
+        set         updateEntry
         describe    getDescription
     );
     while (my ($key, $value) = splice(@delegate_map, 0, 2)) {
@@ -146,6 +144,12 @@
     return $self->{realm};
 }
 
+sub current_user {
+    my $self = shift;
+    $self->{current_user} = shift if @_;
+    return $self->{current_user};
+}
+
 sub server {
     my $self = shift;
     if (@_) {
@@ -180,10 +184,20 @@
     $req->header(
         Accept => 'application/x.atom+xml, application/xml, text/xml, */*',
     );
+    $req->header(
+        'X-RT-CurrentUser' => $self->current_user,
+    );
     return $req unless $self->realm;
     return $self->SUPER::munge_request($req);
 }
 
+sub munge_response {
+    my ($self, $res) = @_;
+    $self->current_user($res->header( 'X-RT-CurrentUser' ));
+    return $self->SUPER::munge_response($res);
+}
+
+
 1;
 
 # my $rt = RT::Client->new('http://root:password@localhost/');

Added: RT-Client/t/spec.t
==============================================================================
--- (empty file)
+++ RT-Client/t/spec.t	Tue May  4 13:43:37 2004
@@ -0,0 +1,91 @@
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Test::More 'no_plan';
+
+use_ok('RT::Client');
+my $rt = RT::Client->new;
+isa_ok($rt, 'RT::Client');
+
+# Requirements:
+# 1. Ticket Creation and Modification via an External Interface
+
+my $tickets = $rt->Tickets;
+isa_ok($tickets, 'RT::Client::Container');
+can_ok($tickets, 'search');
+can_ok($tickets, 'add');
+
+my $results = $tickets->search;
+isa_ok($results, 'RT::Client::ResultSet');
+can_ok($results, 'remove');
+can_ok($results, 'update');
+
+is($tickets->_errstr, undef, 'Nothing bad had happened yet');
+is($tickets->add, undef, 'Adding an empty ticket shall fail');
+isnt($tickets->_errstr, undef, 'Error message is in ->_errstr');
+is($rt->_errstr, undef, 'Error message shall not propagate up');
+
+my $ticket = $tickets->add( Queue => 1, Subject => 'Testing' );
+isa_ok($ticket, 'RT::Client::Object');
+can_ok($ticket, 'remove');
+can_ok($ticket, 'update');
+can_ok($ticket, 'comment');
+can_ok($ticket, 'correspond');
+
+is($ticket->Subject, 'Testing');
+is($ticket->Queue, 1);
+
+# exercise different update syntaxes
+is($ticket->setSubject('Set0'), 'Set0');
+is($ticket->update( Subject => 'Set1' ), 'Set1');
+is($ticket->update( Subject => [ 'Fnord', 'Set2' ] ), 'Set2');
+is($ticket->update( Subject => { set => 'Set3' } ), 'Set3');
+is($ticket->update( Subject => { set => [ 'Fnord', 'Set4' ] } ), 'Set4');
+
+# equivalent to $ticket->_top->Queues($ticket->Queue)
+my $queue = $ticket->QueueObj;
+isa_ok($queue, 'RT::Client::Object');
+can_ok($queue, 'remove');
+can_ok($queue, 'update');
+ok(!$queue->can('comment'), 'Cannot comment on a Queue');
+ok(!$queue->can('correspond'), 'Cannot correspond on a Queue');
+
+# 1.1 Independent of CLI login credentials, need ability to specify
+# "requestor" field so that replies are sent to the requestor.
+
+my $email = 'rand-' . rand() . '@example.com';
+is($ticket->Requestor->search->_count, 1);
+$ticket->addRequestor($email);
+is($ticket->Requestor->search->_count, 2);
+
+# 1.2 Ability to post a ticket to a specific queue.
+
+$queue->Tickets->add( ... )
+
+# 1.3 Ability to specify message body. May contain utf8 OR localized
+# charset.
+
+# 1.4 Ability to set values in n existing custom fields.
+
+# 1.5 Ability to set values in "Select One Value" and "Enter One Value"
+# -type custom fields
+
+# 1.6 For modifications, need to identify ticket number. We'd prefer to
+# identify modifying user as well if possible.
+
+
+# 2. Ability to Close a Ticket via an External Interface
+
+# 2.1 Ability to close a ticket based on ticket number. We'd prefer to
+# identify closing user as well if possible.
+
+# 3. General CLI Requirements
+
+# 3.1 Error Responses: CLI must return status and error responses
+# instead of end-user help text. As this application will be called
+# programmatically, we should be able to easily interpret error responses
+# in scripts as well as log them. The full help text should only appear
+# if a "help" command is entered. Bascially, this should work no
+# differently than any other CLI app in a Unix or Linux environment.
+
+# 3.2 Environment: Support perl 5.6.1.
+


More information about the Rt-commit mailing list