From 9c0bf8ab5a8eee87a3b225d5ebc4988e20fc6634 Mon Sep 17 00:00:00 2001 From: Jon Langseth Date: Sun, 22 Jan 2012 22:25:07 +0100 Subject: [PATCH] Adding tests for phone-nodes --- api/t/phone.t | 99 ++++++++++++++++++++++++++++++++++++++++++++++ api/t/run_tests.sh | 3 +- 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 api/t/phone.t diff --git a/api/t/phone.t b/api/t/phone.t new file mode 100644 index 0000000..695610b --- /dev/null +++ b/api/t/phone.t @@ -0,0 +1,99 @@ +#!/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_domain); + +my $test_macaddress = '12341d6db76c'; + +isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua'); +isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies'); + +login_apikey(); + +# First: fetch a supported domain from the API... +$data = exec_apinode("domain/list", undef); +ok($data, 'domain/list JSON decode'); +is( $data->{'response'}, 'ok', 'domain/list result'); +ok($data->{'list'}, 'domain/list array'); + +# NOW: Set the $test_domain to something useful (i.e. the first reported domain) +$test_domain = $data->{'list'}[0]; + +ok($test_domain, 'test_domain set.'); +undef $data; + +$data = exec_apinode("user/available", { "user" => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'user/available is available'); +undef $data; + +$data = exec_apinode("user/add_local", { + "user" => $test_username . "\@" . $test_domain, + "displayname" => "Automatic testing", + "email" => "noreply\@" . $test_domain, +} ); +is( $data->{'response'}, 'ok', 'user/add_local created new account'); + +$data = exec_apinode("phone/list", undef); +is( $data->{'response'}, 'ok', 'phone/list result'); +ok($data->{'list'}, 'phone/list array'); +undef $data; + +$data = exec_apinode("phone/add", { + 'user' => $test_username . "\@" . $test_domain, + 'mac' => $test_macaddress, +}); + +is( $data->{'response'}, 'ok', 'phone/add result'); +ok($data->{'mac'}, 'phone/add mac set'); +ok($data->{'username'}, 'phone/add username set'); +ok($data->{'domain'}, 'phone/add domain set'); +undef $data; + +$data = exec_apinode("phone/list", { 'search' => $test_macaddress }); +is( $data->{'response'}, 'ok', 'phone/list search result'); +ok($data->{'list'}, 'phone/list search array'); +print Dumper($data->{'list'}); + +undef $data; + +$data = exec_apinode("phone/get", { 'mac' => $test_macaddress }); +is( $data->{'response'}, 'ok', 'phone/get mac result'); +ok($data->{'list'}, 'phone/get mac array'); +undef $data; + +$data = exec_apinode("phone/get", { 'user' => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'phone/get user result'); +ok($data->{'list'}, 'phone/get user array'); +undef $data; + +$data = exec_apinode("phone/remove", { + 'user' => $test_username . "\@" . $test_domain, + 'mac' => $test_macaddress, +}); +is( $data->{'response'}, 'ok', 'phone/remove result'); +ok($data->{'mac'}, 'phone/remove mac set'); +ok($data->{'username'}, 'phone/remove username set'); +ok($data->{'domain'}, 'phone/remove domain set'); +undef $data; + +$data = exec_apinode("user/remove", { "user" => $test_username . "\@" . $test_domain }); +is( $data->{'response'}, 'ok', 'user/remove deleted user'); +undef $data; + + +logout(); diff --git a/api/t/run_tests.sh b/api/t/run_tests.sh index d11b8d8..4a35423 100755 --- a/api/t/run_tests.sh +++ b/api/t/run_tests.sh @@ -3,5 +3,6 @@ perl auth.t perl user.t perl domain.t -perl alias.t +perl phone.t perl numbers.t +perl alias.t -- 2.39.2