[Rt-commit] rt branch, 4.2/rest-search-refactor, updated. rt-4.0.1-242-g600c037
? sunnavy
sunnavy at bestpractical.com
Mon Jul 4 10:27:11 EDT 2011
The branch, 4.2/rest-search-refactor has been updated
via 600c03742937f8c91dafa0541c78bb1f2a643401 (commit)
via ea91ca2b4e1111ebfbef8c7ef08e93b686667716 (commit)
from 862b6b8f3a75128b9ab37447c28fc3aa9e8edc93 (commit)
Summary of changes:
share/html/REST/1.0/search/dhandler | 2 +-
t/web/rest-search-group.t | 85 +++++++++++++++++++++++++++++
t/web/rest-search-queue.t | 83 +++++++++++++++++++++++++++++
t/web/rest-search-user.t | 100 +++++++++++++++++++++++++++++++++++
4 files changed, 269 insertions(+), 1 deletions(-)
create mode 100644 t/web/rest-search-group.t
create mode 100644 t/web/rest-search-queue.t
create mode 100644 t/web/rest-search-user.t
- Log -----------------------------------------------------------------
commit ea91ca2b4e1111ebfbef8c7ef08e93b686667716
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Jul 4 18:52:27 2011 +0800
allow < and > ops too
diff --git a/share/html/REST/1.0/search/dhandler b/share/html/REST/1.0/search/dhandler
index 118867b..492b963 100755
--- a/share/html/REST/1.0/search/dhandler
+++ b/share/html/REST/1.0/search/dhandler
@@ -129,7 +129,7 @@ if ( $type =~ /^(ticket|queue|user|group)$/i ) {
require Text::ParseWords;
my ( $field, $op, $value ) = Text::ParseWords::shellwords($query);
if ( $op !~
- /^(?:[!<>]?=|(NOT )?LIKE|STARTSWITH|ENDSWITH|MATCHES)$/i )
+ /^(?:[!<>]?=|[<>]|(NOT )?LIKE|STARTSWITH|ENDSWITH|MATCHES)$/i )
{
$status = "400 Bad Request";
$output = "Invalid operator specification: $op";
commit 600c03742937f8c91dafa0541c78bb1f2a643401
Author: sunnavy <sunnavy at bestpractical.com>
Date: Mon Jul 4 20:19:26 2011 +0800
tests for restful search of queue/group/user
diff --git a/t/web/rest-search-group.t b/t/web/rest-search-group.t
new file mode 100644
index 0000000..a5bc4e6
--- /dev/null
+++ b/t/web/rest-search-group.t
@@ -0,0 +1,85 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use RT::Test tests => 18;
+
+my $group_foo = RT::Group->new($RT::SystemUser);
+$group_foo->CreateUserDefinedGroup( Name => 'foo' );
+
+my $group_bar = RT::Group->new($RT::SystemUser);
+$group_bar->CreateUserDefinedGroup( Name => 'bar' );
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+ok( $m->login, 'logged in' );
+
+search_groups_ok(
+ { query => 'id = ' . $group_foo->id },
+ [ $group_foo->id . ': foo' ],
+ 'search by id'
+);
+
+search_groups_ok(
+ {
+ query => 'Name = ' . $group_foo->Name,
+ format => 's',
+ fields => 'id,name',
+ },
+ [ "id\tName", $group_foo->id . "\tfoo" ],
+ 'search by name with customized fields'
+);
+
+search_groups_ok(
+ { query => 'foo = 3' },
+ ['Invalid field specification: foo'],
+ 'invalid field'
+);
+
+search_groups_ok(
+ { query => 'id foo 3' },
+ ['Invalid operator specification: foo'],
+ 'invalid op'
+);
+
+search_groups_ok(
+ { query => '', orderby => 'id' },
+ [ $group_foo->id . ': foo', $group_bar->id . ': bar', ],
+ 'order by id'
+);
+
+search_groups_ok(
+ { query => '', orderby => 'name' },
+ [ $group_bar->id . ': bar', $group_foo->id . ': foo' ],
+ 'order by name'
+);
+
+search_groups_ok(
+ { query => '', orderby => '+name' },
+ [ $group_bar->id . ': bar', $group_foo->id . ': foo' ],
+ 'order by +name'
+);
+
+search_groups_ok(
+ { query => '', orderby => '-name' },
+ [ $group_foo->id . ': foo', $group_bar->id . ': bar' ],
+ 'order by -name'
+);
+
+sub search_groups_ok {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my $query = shift;
+ my $expected = shift;
+ my $name = shift || 'search groups';
+
+ my $uri = URI->new("$baseurl/REST/1.0/search/group");
+ $uri->query_form(%$query);
+ $m->get_ok($uri);
+
+ my @lines = split /\n/, $m->content;
+ shift @lines; # header
+ shift @lines; # empty line
+
+ is_deeply( \@lines, $expected, $name );
+
+}
+
diff --git a/t/web/rest-search-queue.t b/t/web/rest-search-queue.t
new file mode 100644
index 0000000..e9701ad
--- /dev/null
+++ b/t/web/rest-search-queue.t
@@ -0,0 +1,83 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use RT::Test tests => 20;
+
+my $queue_foo = RT::Test->load_or_create_queue( Name => 'foo' );
+my $queue_bar = RT::Test->load_or_create_queue( Name => 'bar' );
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+ok( $m->login, 'logged in' );
+
+search_queues_ok( { query => 'id = 1' }, ['1: General'], 'search id = 1' );
+search_queues_ok(
+ {
+ query => 'Name = General',
+ format => 's',
+ fields => 'id,name,description'
+ },
+ [ "id\tName\tDescription", "1\tGeneral\tThe default queue" ],
+ 'search by name with customized fields'
+);
+
+search_queues_ok(
+ { query => 'id > 10' },
+ ['No matching results.'],
+ 'no matching results'
+);
+
+search_queues_ok(
+ { query => 'foo = 3' },
+ ['Invalid field specification: foo'],
+ 'invalid field'
+);
+
+search_queues_ok(
+ { query => 'id foo 3' },
+ ['Invalid operator specification: foo'],
+ 'invalid op'
+);
+
+search_queues_ok(
+ { query => '', orderby => 'id' },
+ [ '1: General', $queue_foo->id . ': foo', $queue_bar->id . ': bar', ],
+ 'order by id'
+);
+
+search_queues_ok(
+ { query => '', orderby => 'name' },
+ [ '1: General', $queue_bar->id . ': bar', $queue_foo->id . ': foo' ],
+ 'order by name'
+);
+
+search_queues_ok(
+ { query => '', orderby => '+name' },
+ [ '1: General', $queue_bar->id . ': bar', $queue_foo->id . ': foo' ],
+ 'order by +name'
+);
+
+search_queues_ok(
+ { query => '', orderby => '-name' },
+ [ $queue_foo->id . ': foo', $queue_bar->id . ': bar', '1: General', ],
+ 'order by -name'
+);
+
+sub search_queues_ok {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my $query = shift;
+ my $expected = shift;
+ my $name = shift || 'search queues';
+
+ my $uri = URI->new("$baseurl/REST/1.0/search/queue");
+ $uri->query_form(%$query);
+ $m->get_ok($uri);
+
+ my @lines = split /\n/, $m->content;
+ shift @lines; # header
+ shift @lines; # empty line
+
+ is_deeply( \@lines, $expected, $name );
+
+}
+
diff --git a/t/web/rest-search-user.t b/t/web/rest-search-user.t
new file mode 100644
index 0000000..e633aa3
--- /dev/null
+++ b/t/web/rest-search-user.t
@@ -0,0 +1,100 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use RT::Test tests => 23;
+
+my $root = RT::Test->load_or_create_user( Name => 'root', );
+my $user_foo = RT::Test->load_or_create_user(
+ Name => 'foo',
+ Password => 'password',
+);
+my $user_bar = RT::Test->load_or_create_user( Name => 'bar' );
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+ok( $m->login, 'logged in' );
+
+search_users_ok(
+ { query => 'id = ' . $user_foo->id },
+ [ $user_foo->id . ': foo' ],
+ 'search by id'
+);
+
+search_users_ok(
+ {
+ query => 'Name = ' . $user_foo->Name,
+ format => 's',
+ fields => 'id,name'
+ },
+ [ "id\tName", $user_foo->id . "\tfoo" ],
+ 'search by name with customized fields'
+);
+
+
+search_users_ok(
+ { query => 'foo = 3' },
+ ['Invalid field specification: foo'],
+ 'invalid field'
+);
+
+search_users_ok(
+ { query => 'id foo 3' },
+ ['Invalid operator specification: foo'],
+ 'invalid op'
+);
+
+search_users_ok(
+ { query => 'password = foo' },
+ ['Invalid field specification: password'],
+ "can't search password"
+);
+
+search_users_ok(
+ { query => '', orderby => 'id' },
+ [ $root->id . ': root', $user_foo->id . ': foo', $user_bar->id . ': bar', ],
+ 'order by id'
+);
+
+search_users_ok(
+ { query => '', orderby => 'name' },
+ [ $user_bar->id . ': bar', $user_foo->id . ': foo', $root->id . ': root' ],
+ 'order by name'
+);
+
+search_users_ok(
+ { query => '', orderby => '+name' },
+ [ $user_bar->id . ': bar', $user_foo->id . ': foo', $root->id . ': root' ],
+ 'order by +name'
+);
+
+search_users_ok(
+ { query => '', orderby => '-name' },
+ [ $root->id . ': root', $user_foo->id . ': foo', $user_bar->id . ': bar' ],
+ 'order by -name'
+);
+
+ok( $m->login( 'foo', 'password', logout => 1 ), 'logged in as foo' );
+search_users_ok(
+ { query => 'id = ' . $user_foo->id },
+ [ 'Permission denied' ],
+ "can't search without permission"
+);
+
+sub search_users_ok {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my $query = shift;
+ my $expected = shift;
+ my $name = shift || 'search users';
+
+ my $uri = URI->new("$baseurl/REST/1.0/search/user");
+ $uri->query_form(%$query);
+ $m->get_ok($uri);
+
+ my @lines = split /\n/, $m->content;
+ shift @lines; # header
+ shift @lines; # empty line
+
+ is_deeply( \@lines, $expected, $name );
+
+}
+
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list