]> git.defcon.no Git - hermes/commitdiff
Tests for numbers nodes.
authorJon Langseth <jon.langseth@lilug.no>
Sun, 22 Jan 2012 21:43:19 +0000 (22:43 +0100)
committerJon Langseth <jon.langseth@lilug.no>
Sun, 22 Jan 2012 21:43:19 +0000 (22:43 +0100)
api/t/numbers.t [new file with mode: 0644]

diff --git a/api/t/numbers.t b/api/t/numbers.t
new file mode 100644 (file)
index 0000000..ac41b81
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+
+use strict;
+use Test::More 'no_plan';
+use tests_common;
+use Data::Dumper;
+
+# Configuration variables defined in tests_common
+# Make sure those are updated/set correctly..
+#   $api_base
+#   $api_key
+#
+# Further variables defined in tests_common:
+#   $invalid_key
+#   $test_username
+#   $test_password
+#   $invalid_username
+my ($data, $temp, $test_number_start, $test_number_end);
+
+$test_number_end .= int(rand(255))
+       while ( length( $test_number_end ) < 8 );
+
+$test_number_end = substr( $test_number_end, 0, 8 );
+$test_number_start = $test_number_end - 1;
+
+$test_number_start = '+47' . $test_number_start;
+$test_number_end = '+47' . $test_number_end;
+
+isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
+isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
+
+login_apikey();
+
+$data = exec_apinode("numbers/list", undef);
+is( $data->{'response'}, 'ok',                 'numbers/list result');
+ok($data->{'list'},                    'numbers/list array');
+undef $data;
+
+$data = exec_apinode("numbers/add_range", {
+       'start' => $test_number_end,
+       'end' => $test_number_start,
+});
+
+is( $data->{'response'}, 'failed',     'numbers/add_range invalid result');
+undef $data;
+
+$data = exec_apinode("numbers/add_range", {
+       'start' => $test_number_start,
+       'end' => $test_number_end,
+});
+is( $data->{'response'}, 'ok',                 'numbers/add_range result');
+undef $data;
+
+$data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'ok',                 'numbers/inpool result');
+undef $data;
+
+$data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'ok',                 'numbers/remove 1 result');
+undef $data;
+
+$data = exec_apinode("numbers/remove", { 'number' => $test_number_end, });
+is( $data->{'response'}, 'ok',                 'numbers/remove 2 result');
+undef $data;
+
+$data = exec_apinode("numbers/add", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'ok',                 'numbers/add result');
+undef $data;
+
+$data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'ok',                 'numbers/remove 3 result');
+undef $data;
+
+$data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'failed',             'numbers/remove inpool removed');
+undef $data;
+
+$data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
+is( $data->{'response'}, 'failed',             'numbers/remove invalid remove result');
+undef $data;
+
+
+logout();