[Jifty-commit] r4506 - in Net-Jifty: . lib/Net t/lib t/lib/Net t/lib/Net/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Nov 20 15:15:11 EST 2007


Author: sartak
Date: Tue Nov 20 15:15:08 2007
New Revision: 4506

Added:
   Net-Jifty/t/
   Net-Jifty/t/000-load.t
   Net-Jifty/t/001-login.t
   Net-Jifty/t/lib/
   Net-Jifty/t/lib/Net/
   Net-Jifty/t/lib/Net/Jifty/
   Net-Jifty/t/lib/Net/Jifty/Test.pm
Modified:
   Net-Jifty/   (props changed)
   Net-Jifty/Makefile.PL
   Net-Jifty/lib/Net/Jifty.pm

Log:
 r45418 at onn:  sartak | 2007-11-20 15:14:59 -0500
 Begin adding tests. Test::MockObject *rocks*


Modified: Net-Jifty/Makefile.PL
==============================================================================
--- Net-Jifty/Makefile.PL	(original)
+++ Net-Jifty/Makefile.PL	Tue Nov 20 15:15:08 2007
@@ -10,6 +10,7 @@
 requires        'Encode';
 
 build_requires  'Test::More';
+build_requires  'Test::MockObject';
 
 auto_install;
 WriteAll;

Modified: Net-Jifty/lib/Net/Jifty.pm
==============================================================================
--- Net-Jifty/lib/Net/Jifty.pm	(original)
+++ Net-Jifty/lib/Net/Jifty.pm	Tue Nov 20 15:15:08 2007
@@ -55,7 +55,7 @@
     is            => 'ro',
     isa           => 'Str',
     required      => 1,
-    documentation => "The name of the session ID cookie",
+    documentation => "The name of the session ID cookie. This can be found in your config under Framework/Web/SessinCookieName",
 );
 
 has appname => (
@@ -89,7 +89,7 @@
                                           $self->sid, '/',
                                           $uri->host, $uri->port,
                                           0, 0, undef, 1);
-    }
+    },
 );
 
 has ua => (
@@ -106,7 +106,7 @@
         $ua->env_proxy;
 
         return $ua;
-    }
+    },
 );
 
 sub BUILD {

Added: Net-Jifty/t/000-load.t
==============================================================================
--- (empty file)
+++ Net-Jifty/t/000-load.t	Tue Nov 20 15:15:08 2007
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+use_ok 'Net::Jifty';
+
+no warnings; *Net::Jifty::login = sub { 1 }; use warnings;
+
+my $j = Net::Jifty->new(site => 'http://mushroom.mu/', cookie_name => 'MUSHROOM_KINGDOM_SID', appname => 'MushroomKingdom', email => 'god at mushroom.mu', password => 'melange');
+
+ok($j, "got a defined return value from Net::Jifty");
+ok($j->isa('Net::Jifty'), "got a Net::Jifty object");
+

Added: Net-Jifty/t/001-login.t
==============================================================================
--- (empty file)
+++ Net-Jifty/t/001-login.t	Tue Nov 20 15:15:08 2007
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+use lib 't/lib';
+use Net::Jifty::Test;
+
+my $j = Net::Jifty::Test->new();
+my ($name, $args) = $j->ua->next_call();
+is($name, "post", "the called method was post");
+is($args->[1], "http://jifty.org/__jifty/webservices/yaml", "correct URL");
+
+my $login = {
+    'J:A-fnord'            => 'Login',
+    'J:A:F-address-fnord'  => 'user at host.tld',
+    'J:A:F-password-fnord' => 'password',
+};
+
+is_deeply($args->[2], $login, "correct login arguments");
+

Added: Net-Jifty/t/lib/Net/Jifty/Test.pm
==============================================================================
--- (empty file)
+++ Net-Jifty/t/lib/Net/Jifty/Test.pm	Tue Nov 20 15:15:08 2007
@@ -0,0 +1,77 @@
+#!/usr/bin/env perl
+package Net::Jifty::Test;
+use Moose;
+extends 'Net::Jifty';
+
+use Test::MockObject;
+
+our $content = << "YAML";
+---
+fnord:
+    success: 1
+
+foo: 1
+bar: 2
+baz: 3
+
+quux:
+    - quuuux
+    - quuuux
+
+Atreides:
+    - Leto: male
+    - Jessica: female
+    - Paul: male
+    - Alia: female
+YAML
+
+has '+ua' => (
+    default => sub {
+
+        # the result object. change $Net::Jifty::Test::content to change the
+        # results
+        my $res = Test::MockObject->new;
+        $res->set_bound(is_success => \$content);
+        $res->set_bound(content    => \$content);
+
+        # the cookie object. the cookie name is hardcoded to JIFTY_SID
+        my $cookie = Test::MockObject->new;
+        $cookie->set_always(as_string => "JIFTY_SID=1010101");
+        $cookie->set_true('set_cookie');
+
+        my $mock = Test::MockObject->new;
+        for (qw/get post put delete head/) {
+            $mock->set_always($_ => $res);
+        }
+        $mock->set_always(cookie_jar => $cookie);
+
+        $mock->set_isa('LWP::UserAgent');
+
+        return $mock;
+    },
+);
+
+# give the rest of the attributes defaults for brevity
+
+has '+site' => (
+    default => 'http://jifty.org',
+);
+
+has '+cookie_name' => (
+    default => 'JIFTY_SID',
+);
+
+has '+appname' => (
+    default => 'JiftyApp',
+);
+
+has '+email' => (
+    default => 'user at host.tld',
+);
+
+has '+password' => (
+    default => 'password',
+);
+
+1;
+


More information about the Jifty-commit mailing list