]> git.defcon.no Git - hermes/blob - api/t/numbers.t
Tests for numbers nodes.
[hermes] / api / t / numbers.t
1 #!/usr/bin/perl
2
3 use strict;
4 use Test::More 'no_plan';
5 use tests_common;
6 use Data::Dumper;
7
8 # Configuration variables defined in tests_common
9 # Make sure those are updated/set correctly..
10 # $api_base
11 # $api_key
12 #
13 # Further variables defined in tests_common:
14 # $invalid_key
15 # $test_username
16 # $test_password
17 # $invalid_username
18 my ($data, $temp, $test_number_start, $test_number_end);
19
20 $test_number_end .= int(rand(255))
21 while ( length( $test_number_end ) < 8 );
22
23 $test_number_end = substr( $test_number_end, 0, 8 );
24 $test_number_start = $test_number_end - 1;
25
26 $test_number_start = '+47' . $test_number_start;
27 $test_number_end = '+47' . $test_number_end;
28
29 isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
30 isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
31
32 login_apikey();
33
34 $data = exec_apinode("numbers/list", undef);
35 is( $data->{'response'}, 'ok', 'numbers/list result');
36 ok($data->{'list'}, 'numbers/list array');
37 undef $data;
38
39 $data = exec_apinode("numbers/add_range", {
40 'start' => $test_number_end,
41 'end' => $test_number_start,
42 });
43
44 is( $data->{'response'}, 'failed', 'numbers/add_range invalid result');
45 undef $data;
46
47 $data = exec_apinode("numbers/add_range", {
48 'start' => $test_number_start,
49 'end' => $test_number_end,
50 });
51 is( $data->{'response'}, 'ok', 'numbers/add_range result');
52 undef $data;
53
54 $data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
55 is( $data->{'response'}, 'ok', 'numbers/inpool result');
56 undef $data;
57
58 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
59 is( $data->{'response'}, 'ok', 'numbers/remove 1 result');
60 undef $data;
61
62 $data = exec_apinode("numbers/remove", { 'number' => $test_number_end, });
63 is( $data->{'response'}, 'ok', 'numbers/remove 2 result');
64 undef $data;
65
66 $data = exec_apinode("numbers/add", { 'number' => $test_number_start, });
67 is( $data->{'response'}, 'ok', 'numbers/add result');
68 undef $data;
69
70 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
71 is( $data->{'response'}, 'ok', 'numbers/remove 3 result');
72 undef $data;
73
74 $data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
75 is( $data->{'response'}, 'failed', 'numbers/remove inpool removed');
76 undef $data;
77
78 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
79 is( $data->{'response'}, 'failed', 'numbers/remove invalid remove result');
80 undef $data;
81
82
83 logout();