[Bps-public-commit] rt-extension-rest2 branch, master, updated. b0d5e708c16a88f4b9e5c08d0d401905a334f4ff
Shawn Moore
shawn at bestpractical.com
Tue Dec 13 14:53:15 EST 2016
The branch, master has been updated
via b0d5e708c16a88f4b9e5c08d0d401905a334f4ff (commit)
from 40d50270b6577177317067a59fe3464cc166329c (commit)
Summary of changes:
t/lib/RT/Extension/REST2/Test.pm.in | 20 ++++++++++++++++++
t/tickets.t | 41 +++++++++++++++----------------------
2 files changed, 37 insertions(+), 24 deletions(-)
- Log -----------------------------------------------------------------
commit b0d5e708c16a88f4b9e5c08d0d401905a334f4ff
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Tue Dec 13 19:53:05 2016 +0000
post_json and put_json helper methods
diff --git a/t/lib/RT/Extension/REST2/Test.pm.in b/t/lib/RT/Extension/REST2/Test.pm.in
index 771e3c9..927441f 100644
--- a/t/lib/RT/Extension/REST2/Test.pm.in
+++ b/t/lib/RT/Extension/REST2/Test.pm.in
@@ -54,6 +54,26 @@ sub mech { RT::Extension::REST2::Test::Mechanize->new }
return $class->SUPER::new(%args);
}
+ sub post_json {
+ my ($self, $url, $payload, %headers) = @_;
+ $self->post(
+ $url,
+ Content => $json->encode($payload),
+ 'Content-Type' => 'application/json; charset=utf-8',
+ %headers,
+ );
+ }
+
+ sub put_json {
+ my ($self, $url, $payload, %headers) = @_;
+ $self->put(
+ $url,
+ Content => $json->encode($payload),
+ 'Content-Type' => 'application/json; charset=utf-8',
+ %headers,
+ );
+ }
+
sub json_response {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $self = shift;
diff --git a/t/tickets.t b/t/tickets.t
index bce0484..0d946de 100644
--- a/t/tickets.t
+++ b/t/tickets.t
@@ -7,7 +7,6 @@ my $mech = RT::Extension::REST2::Test->mech;
my $auth = RT::Extension::REST2::Test->authorization_header;
my $rest_base_path = '/REST/2.0';
-my $json = JSON->new->utf8;
my $user = RT::Extension::REST2::Test->user;
# Empty DB
@@ -21,13 +20,11 @@ my $user = RT::Extension::REST2::Test->user;
# Missing Queue
{
- my $payload = $json->encode({
- Subject => 'Ticket creation using REST',
- From => 'test at bestpractical.com',
- });
- my $res = $mech->post("$rest_base_path/ticket",
- Content => $payload,
- 'Content-Type' => 'application/json; charset=utf-8',
+ my $res = $mech->post_json("$rest_base_path/ticket",
+ {
+ Subject => 'Ticket creation using REST',
+ From => 'test at bestpractical.com',
+ },
'Authorization' => $auth,
);
is($res->code, 400);
@@ -37,18 +34,17 @@ my $user = RT::Extension::REST2::Test->user;
# Ticket Creation
my ($ticket_url, $ticket_id);
{
- my $payload = $json->encode({
+ my $payload = {
Subject => 'Ticket creation using REST',
From => 'test at bestpractical.com',
To => 'rt at localhost',
Queue => 'General',
Content => 'Testing ticket creation using REST API.',
- });
+ };
# Rights Test - No CreateTicket
- my $res = $mech->post("$rest_base_path/ticket",
- 'Content' => $payload,
- 'Content-Type' => 'application/json; charset=utf-8',
+ my $res = $mech->post_json("$rest_base_path/ticket",
+ $payload,
'Authorization' => $auth,
);
TODO: {
@@ -58,9 +54,8 @@ my ($ticket_url, $ticket_id);
# Rights Test - With CreateTicket
$user->PrincipalObj->GrantRight( Right => 'CreateTicket' );
- $res = $mech->post("$rest_base_path/ticket",
- 'Content' => $payload,
- 'Content-Type' => 'application/json; charset=utf-8',
+ $res = $mech->post_json("$rest_base_path/ticket",
+ $payload,
'Authorization' => $auth,
);
is($res->code, 201);
@@ -138,15 +133,14 @@ my ($ticket_url, $ticket_id);
# Ticket Update
{
- my $payload = $json->encode({
+ my $payload = {
Subject => 'Ticket update using REST',
Priority => 42,
- });
+ };
# Rights Test - No ModifyTicket
- my $res = $mech->put($ticket_url,
- 'Content' => $payload,
- 'Content-Type' => 'application/json; charset=utf-8',
+ my $res = $mech->put_json($ticket_url,
+ $payload,
'Authorization' => $auth,
);
TODO: {
@@ -157,9 +151,8 @@ my ($ticket_url, $ticket_id);
$user->PrincipalObj->GrantRight( Right => 'ModifyTicket' );
- $res = $mech->put($ticket_url,
- 'Content' => $payload,
- 'Content-Type' => 'application/json; charset=utf-8',
+ $res = $mech->put_json($ticket_url,
+ $payload,
'Authorization' => $auth,
);
is($res->code, 200);
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list