aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-03-03 08:33:21 +0000
committerEdmund von der Burg <evdb@mysociety.org>2011-03-03 08:33:21 +0000
commit20fe27a76cd5ba8d912024f40c6ea881791623b0 (patch)
tree01cfed5e0729c61044dd8b3747ef7c1e16b9ef96
parente2df7e1ba55faafb5d14909b973b7d4b9a46535a (diff)
Added tests for token
-rw-r--r--Makefile.PL4
-rw-r--r--t/app/model/token.t81
2 files changed, 85 insertions, 0 deletions
diff --git a/Makefile.PL b/Makefile.PL
index 3677f0b5e..cc26b66d4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -20,9 +20,13 @@ requires 'Catalyst::Runtime' => '5.80031';
requires 'Config::General';
requires 'Email::Send';
requires 'Email::Simple';
+requires 'Email::Valid';
+requires 'IO::String';
requires 'Moose';
requires 'namespace::autoclean';
+requires 'Net::Domain::TLD';
requires 'Path::Class';
+requires 'RABX';
requires 'Readonly';
test_requires 'Test::More' => '0.88';
diff --git a/t/app/model/token.t b/t/app/model/token.t
new file mode 100644
index 000000000..f7124ffc0
--- /dev/null
+++ b/t/app/model/token.t
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 13;
+
+use FixMyStreet;
+use FixMyStreet::App;
+use mySociety::AuthToken;
+use mySociety::DBHandle 'dbh';
+
+# set things up so that code using mySociety::DBHandle is happy
+FixMyStreet->configure_mysociety_dbhandle();
+
+# NOTE - remember that you need to explicitly dbh()->commit after making
+# database changes with the mySociety::* modules.
+
+# create a token using DBIC and check we can read it using AuthToken, and vice
+# versa
+
+my $test_data = { foo => 'bar', and => [ 'baz', 'bundy' ] };
+
+my $token_rs = FixMyStreet::App->model('DB::Token');
+
+{ # create using DBIC
+ my $dbic_token =
+ $token_rs->create( { scope => 'testing', data => $test_data } );
+ my $token = $dbic_token->token;
+ ok $token, "stored token '$token'";
+ is_deeply $dbic_token->data, $test_data, "data stored correctly using DBIC";
+
+ # read back using DBIC
+ is_deeply $token_rs->find( { token => $token, scope => 'testing' } )->data,
+ $test_data,
+ "data read back correctly with DBIC";
+
+ # read back using mySociety::AuthToken
+ is_deeply mySociety::AuthToken::retrieve( 'testing', $token ),
+ $test_data, "data read back correctly with m::AT";
+
+ # delete token
+ ok $dbic_token->delete, "delete token";
+
+ is $token_rs->find( { token => $token, scope => 'testing' } ),
+ undef,
+ "token gone for DBIC";
+
+ # read back using mySociety::AuthToken
+ is mySociety::AuthToken::retrieve( 'testing', $token ),
+ undef, "token gone with m::AT";
+
+}
+
+{ # create using m::AT
+ my $token = mySociety::AuthToken::store( 'testing', $test_data );
+ dbh->commit();
+ ok $token, "stored token '$token'";
+
+ # read back using DBIC
+ is_deeply $token_rs->find( { token => $token, scope => 'testing' } )->data,
+ $test_data,
+ "data read back correctly with DBIC";
+
+ # read back using mySociety::AuthToken
+ is_deeply mySociety::AuthToken::retrieve( 'testing', $token ),
+ $test_data, "data read back correctly with m::AT";
+
+ # delete token
+ ok mySociety::AuthToken::destroy( 'testing', $token ), "destroy token";
+ dbh->commit();
+
+ is $token_rs->find( { token => $token, scope => 'testing' } ),
+ undef,
+ "token gone for DBIC";
+
+ # read back using mySociety::AuthToken
+ is mySociety::AuthToken::retrieve( 'testing', $token ),
+ undef, "token gone with m::AT";
+
+}