From: Jon Langseth Date: Sun, 22 Jan 2012 21:43:19 +0000 (+0100) Subject: Tests for numbers nodes. X-Git-Url: https://git.defcon.no/?a=commitdiff_plain;h=615ba8a8122904adc40a159c42bc6c12c3497c22;hp=9c0bf8ab5a8eee87a3b225d5ebc4988e20fc6634;p=hermes Tests for numbers nodes. --- diff --git a/api/t/numbers.t b/api/t/numbers.t new file mode 100644 index 0000000..ac41b81 --- /dev/null +++ b/api/t/numbers.t @@ -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();