]> git.defcon.no Git - hermes/blob - api/t/numbers.t
Added license text
[hermes] / api / t / numbers.t
1 #!/usr/bin/perl
2 # Copyright (c) 2012, Gjøvik University College
3 # All rights reserved.
4
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of the Gjøvik University College nor the
13 # names of its contributors may be used to endorse or promote products
14 # derived from this software without specific prior written permission.
15 #
16 # THIS SOFTWARE IS PROVIDED BY Gjøvik University College ''AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL Gjøvik University College BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 use strict;
28 use Test::More 'no_plan';
29 use tests_common;
30
31 # Configuration variables defined in tests_common
32 # Make sure those are updated/set correctly..
33 # $api_base
34 # $api_key
35 #
36 # Further variables defined in tests_common:
37 # $invalid_key
38 # $test_username
39 # $test_password
40 # $invalid_username
41 my ($data, $temp, $test_number_start, $test_number_end);
42
43 $test_number_end .= int(rand(255))
44 while ( length( $test_number_end ) < 8 );
45
46 $test_number_end = substr( $test_number_end, 0, 8 );
47 $test_number_start = $test_number_end - 1;
48
49 $test_number_start = '+47' . $test_number_start;
50 $test_number_end = '+47' . $test_number_end;
51
52 isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
53 isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
54
55 login_apikey();
56
57 $data = exec_apinode("numbers/list", undef);
58 is( $data->{'response'}, 'ok', 'numbers/list result');
59 ok($data->{'list'}, 'numbers/list array');
60 undef $data;
61
62 $data = exec_apinode("numbers/add_range", {
63 'start' => $test_number_end,
64 'end' => $test_number_start,
65 });
66
67 is( $data->{'response'}, 'failed', 'numbers/add_range invalid result');
68 undef $data;
69
70 $data = exec_apinode("numbers/add_range", {
71 'start' => $test_number_start,
72 'end' => $test_number_end,
73 });
74 is( $data->{'response'}, 'ok', 'numbers/add_range result');
75 undef $data;
76
77 $data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
78 is( $data->{'response'}, 'ok', 'numbers/inpool result');
79 undef $data;
80
81 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
82 is( $data->{'response'}, 'ok', 'numbers/remove 1 result');
83 undef $data;
84
85 $data = exec_apinode("numbers/remove", { 'number' => $test_number_end, });
86 is( $data->{'response'}, 'ok', 'numbers/remove 2 result');
87 undef $data;
88
89 $data = exec_apinode("numbers/add", { 'number' => $test_number_start, });
90 is( $data->{'response'}, 'ok', 'numbers/add result');
91 undef $data;
92
93 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
94 is( $data->{'response'}, 'ok', 'numbers/remove 3 result');
95 undef $data;
96
97 $data = exec_apinode("numbers/inpool", { 'number' => $test_number_start, });
98 is( $data->{'response'}, 'failed', 'numbers/remove inpool removed');
99 undef $data;
100
101 $data = exec_apinode("numbers/remove", { 'number' => $test_number_start, });
102 is( $data->{'response'}, 'failed', 'numbers/remove invalid remove result');
103 undef $data;
104
105
106 logout();