]>
git.defcon.no Git - hermes/blob - api/t/phone.t
2 # Copyright (c) 2012, Gjøvik University College
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.
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.
28 use Test
::More
'no_plan';
31 # Configuration variables defined in tests_common
32 # Make sure those are updated/set correctly..
36 # Further variables defined in tests_common:
42 my ($data, $temp, $test_domain);
44 my $test_macaddress = '12341d6db76c';
46 isa_ok
( $g_ua, 'LWP::UserAgent', '$g_ua');
47 isa_ok
( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
51 # First: fetch a supported domain from the API...
52 $data = exec_apinode
("domain/list", undef);
53 ok
($data, 'domain/list JSON decode');
54 is
( $data->{'response'}, 'ok', 'domain/list result');
55 ok
($data->{'list'}, 'domain/list array');
57 # NOW: Set the $test_domain to something useful (i.e. the first reported domain)
58 $test_domain = $data->{'list'}[0];
60 ok
($test_domain, 'test_domain set.');
63 $data = exec_apinode
("user/available", { "user" => $test_username . "\@" . $test_domain });
64 is
( $data->{'response'}, 'ok', 'user/available is available');
67 $data = exec_apinode
("user/add_local", {
68 "user" => $test_username . "\@" . $test_domain,
69 "displayname" => "Automatic testing",
70 "email" => "noreply\@" . $test_domain,
72 is
( $data->{'response'}, 'ok', 'user/add_local created new account');
74 $data = exec_apinode
("phone/list", undef);
75 is
( $data->{'response'}, 'ok', 'phone/list result');
76 ok
($data->{'list'}, 'phone/list array');
79 $data = exec_apinode
("phone/add", {
80 'user' => $test_username . "\@" . $test_domain,
81 'mac' => $test_macaddress,
84 is
( $data->{'response'}, 'ok', 'phone/add result');
85 ok
($data->{'mac'}, 'phone/add mac set');
86 ok
($data->{'username'}, 'phone/add username set');
87 ok
($data->{'domain'}, 'phone/add domain set');
90 $data = exec_apinode
("phone/list", { 'search' => $test_macaddress });
91 is
( $data->{'response'}, 'ok', 'phone/list search result');
92 ok
($data->{'list'}, 'phone/list search array');
95 $data = exec_apinode
("phone/get", { 'mac' => $test_macaddress });
96 is
( $data->{'response'}, 'ok', 'phone/get mac result');
97 ok
($data->{'list'}, 'phone/get mac array');
100 $data = exec_apinode
("phone/get", { 'user' => $test_username . "\@" . $test_domain });
101 is
( $data->{'response'}, 'ok', 'phone/get user result');
102 ok
($data->{'list'}, 'phone/get user array');
105 $data = exec_apinode
("phone/remove", {
106 'user' => $test_username . "\@" . $test_domain,
107 'mac' => $test_macaddress,
109 is
( $data->{'response'}, 'ok', 'phone/remove result');
110 ok
($data->{'mac'}, 'phone/remove mac set');
111 ok
($data->{'username'}, 'phone/remove username set');
112 ok
($data->{'domain'}, 'phone/remove domain set');
115 $data = exec_apinode
("user/remove", { "user" => $test_username . "\@" . $test_domain });
116 is
( $data->{'response'}, 'ok', 'user/remove deleted user');