TT#12593 add fax_prefs xavp load for caller callee

* xavp caller_fax_prefs and callee_fax_prefs is
     added and automatically fetched as a part of
     caller_usr_load and callee_usr_load
   * fax_prefs are load all related subscriber's
     NOT NULL fax preferences from
     provisioning.voip_fax_preferences

Change-Id: I2dcedf30433b3d5b94efa9292437a4e7501588a3
changes/23/12823/4
Kirill Solomko 9 years ago committed by Victor Seva
parent ce0a9fd104
commit efab0961ea

@ -40,6 +40,8 @@ local NGCPConfig_MT = { __index = NGCPConfig }
default = { default = {
contract = { contract = {
}, },
fax = {
},
peer = { peer = {
sst_enable = "yes", sst_enable = "yes",
sst_expires = 300, sst_expires = 300,

@ -0,0 +1,122 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
local utils = require 'ngcp.utils'
local utable = utils.table
local NGCPXAvp = require 'ngcp.xavp'
local NGCPPrefs = require 'ngcp.pref'
-- class NGCPFaxPrefs
local NGCPFaxPrefs = {
__class__ = 'NGCPFaxPrefs'
}
local NGCPFaxPrefs_MT = { __index = NGCPFaxPrefs }
NGCPFaxPrefs_MT.__tostring = function ()
local xavp = NGCPXAvp:new('caller','fax_prefs')
local output = string.format("caller_fax_prefs:%s\n", tostring(xavp))
xavp = NGCPXAvp:new('callee','fax_prefs')
output = output .. string.format("callee_fax_prefs:%s\n", tostring(xavp))
return output
end
function NGCPFaxPrefs:new(config)
local t = {
config = config,
db_table = "provisioning.voip_fax_preferences"
}
-- creates xavp fax
NGCPPrefs.init("fax_prefs")
return setmetatable( t, NGCPFaxPrefs_MT )
end
function NGCPFaxPrefs:caller_load(uuid)
if uuid then
return self:_load("caller",uuid)
else
return {}
end
end
function NGCPFaxPrefs:callee_load(uuid)
if uuid then
return self:_load("callee",uuid)
else
return {}
end
end
function NGCPFaxPrefs:_defaults(level)
local defaults = self.config:get_defaults('fax')
local keys = {}
if defaults then
for k,_ in pairs(defaults) do
table.insert(keys, k)
end
end
return keys, defaults
end
function NGCPFaxPrefs:_load(level, uuid)
local con = assert (self.config:getDBConnection())
local query = "SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = '" .. uuid .. "' AND fp.subscriber_id = s.id"
local cur = assert (con:execute(query))
local colnames = cur:getcolnames()
local keys = {}
local result = {}
local row = cur:fetch({}, "a")
local xavp
if row then
for _,v in pairs(colnames) do
if row[v] ~= nil then
utable.add(keys, v)
result[v] = row[v]
end
end
else
sr.log("dbg", string.format("no results for query:%s", query))
end
cur:close()
xavp = self:xavp(level, result)
for k,v in pairs(result) do
xavp(k, v)
end
return keys
end
function NGCPFaxPrefs:xavp(level, l)
if level ~= 'caller' and level ~= 'callee' then
error(string.format("unknown level:%s. It has to be [caller|callee]", tostring(level)))
end
return NGCPXAvp:new(level,'fax_prefs', l)
end
function NGCPFaxPrefs:clean(vtype)
if not vtype then
NGCPFaxPrefs:xavp('callee'):clean()
NGCPFaxPrefs:xavp('caller'):clean()
else
NGCPFaxPrefs:xavp(vtype):clean()
end
end
-- class
return NGCPFaxPrefs

@ -25,6 +25,7 @@ local NGCPPeerPrefs = require 'ngcp.pp'
local NGCPDomainPrefs = require 'ngcp.dp' local NGCPDomainPrefs = require 'ngcp.dp'
local NGCPUserPrefs = require 'ngcp.up' local NGCPUserPrefs = require 'ngcp.up'
local NGCPRealPrefs = require 'ngcp.rp' local NGCPRealPrefs = require 'ngcp.rp'
local NGCPFaxPrefs = require 'ngcp.fp'
local NGCPConfig = require 'ngcp.config' local NGCPConfig = require 'ngcp.config'
local utils = require 'ngcp.utils' local utils = require 'ngcp.utils'
local utable = utils.table local utable = utils.table
@ -60,6 +61,7 @@ end
peer = NGCPPeerPrefs:new(t.config), peer = NGCPPeerPrefs:new(t.config),
real = NGCPRealPrefs:new(t.config), real = NGCPRealPrefs:new(t.config),
contract = NGCPContractPrefs:new(t.config), contract = NGCPContractPrefs:new(t.config),
fax = NGCPFaxPrefs:new(t.config),
} }
return t return t
end end
@ -96,7 +98,8 @@ end
local keys = { local keys = {
domain = self.prefs.dom:caller_load(domain), domain = self.prefs.dom:caller_load(domain),
prof = self.prefs.prof:caller_load(uuid), prof = self.prefs.prof:caller_load(uuid),
user = self.prefs.usr:caller_load(uuid) user = self.prefs.usr:caller_load(uuid),
fax = self.prefs.fax:caller_load(uuid)
} }
local unique_keys = utable.deepcopy(keys.domain) local unique_keys = utable.deepcopy(keys.domain)
utable.merge(unique_keys, keys.prof) utable.merge(unique_keys, keys.prof)
@ -112,7 +115,8 @@ end
local keys = { local keys = {
domain = self.prefs.dom:callee_load(domain), domain = self.prefs.dom:callee_load(domain),
prof = self.prefs.prof:callee_load(uuid), prof = self.prefs.prof:callee_load(uuid),
user = self.prefs.usr:callee_load(uuid) user = self.prefs.usr:callee_load(uuid),
fax = self.prefs.fax:callee_load(uuid)
} }
local unique_keys = utable.deepcopy(keys.domain) local unique_keys = utable.deepcopy(keys.domain)
utable.merge(unique_keys, keys.prof) utable.merge(unique_keys, keys.prof)

@ -24,6 +24,7 @@ local DPFetch = require 'tests_v.dp_vars'
local PPFetch = require 'tests_v.pp_vars' local PPFetch = require 'tests_v.pp_vars'
local PProfFetch = require 'tests_v.pprof_vars' local PProfFetch = require 'tests_v.pprof_vars'
local UPFetch = require 'tests_v.up_vars' local UPFetch = require 'tests_v.up_vars'
local FPFetch = require 'tests_v.fp_vars'
local utils = require 'ngcp.utils' local utils = require 'ngcp.utils'
local utable = utils.table local utable = utils.table
@ -35,6 +36,7 @@ local dp_vars = DPFetch:new()
local pp_vars = PPFetch:new() local pp_vars = PPFetch:new()
local up_vars = UPFetch:new() local up_vars = UPFetch:new()
local pprof_vars = PProfFetch:new() local pprof_vars = PProfFetch:new()
local fp_vars = FPFetch:new()
package.loaded.luasql = nil package.loaded.luasql = nil
package.preload['luasql.mysql'] = function () package.preload['luasql.mysql'] = function ()
@ -63,6 +65,7 @@ TestNGCP = {} --class
pp_vars:reset() pp_vars:reset()
pprof_vars:reset() pprof_vars:reset()
up_vars:reset() up_vars:reset()
fp_vars:reset()
end end
function TestNGCP:tearDown() function TestNGCP:tearDown()
@ -76,6 +79,8 @@ TestNGCP = {} --class
sr.pv.unset("$xavp(callee_usr_prefs)") sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)") sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)") sr.pv.unset("$xavp(callee_real_prefs)")
sr.pv.unset("$xavp(caller_fax_prefs)")
sr.pv.unset("$xavp(callee_fax_prefs)")
self.ngcp = nil self.ngcp = nil
end end
@ -120,6 +125,9 @@ TestNGCP = {} --class
assertTrue(self.ngcp.prefs.prof) assertTrue(self.ngcp.prefs.prof)
assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_prof_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_prof_prefs=>dummy)"),"callee")
assertTrue(self.ngcp.prefs.fax)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end end
function TestNGCP:test_log_pref() function TestNGCP:test_log_pref()
@ -160,6 +168,16 @@ TestNGCP = {} --class
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close() self.cur:close()
-- connection check
self.con:execute("SELECT 1") ;mc :returns(self.cur)
self.cur:fetch() ;mc :returns({})
self.cur:numrows() ;mc :returns(1)
self.cur:close()
--
self.con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ae736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_1"))
self.cur:close()
mc:replay() mc:replay()
local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c") local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c")
@ -253,6 +271,16 @@ TestNGCP = {} --class
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close() self.cur:close()
-- connection check
self.con:execute("SELECT 1") ;mc :returns(self.cur)
self.cur:fetch() ;mc :returns({})
self.cur:numrows() ;mc :returns(1)
self.cur:close()
--
self.con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ae736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_1"))
self.cur:close()
mc:replay() mc:replay()
local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") local keys = self.ngcp:caller_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56")
@ -325,6 +353,16 @@ TestNGCP = {} --class
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close() self.cur:close()
-- connection check
self.con:execute("SELECT 1") ;mc :returns(self.cur)
self.cur:fetch() ;mc :returns({})
self.cur:numrows() ;mc :returns(1)
self.cur:close()
--
self.con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ae736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_2"))
self.cur:close()
mc:replay() mc:replay()
local keys = self.ngcp:callee_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") local keys = self.ngcp:callee_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56")
@ -391,6 +429,16 @@ TestNGCP = {} --class
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ae736f72_21d1_4ea6_a3ea_4d7f56b3887c"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close() self.cur:close()
-- connection check
self.con:execute("SELECT 1") ;mc :returns(self.cur)
self.cur:fetch() ;mc :returns({})
self.cur:numrows() ;mc :returns(1)
self.cur:close()
--
self.con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ae736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_2"))
self.cur:close()
mc:replay() mc:replay()
local keys = self.ngcp:callee_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") local keys = self.ngcp:callee_usr_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56")
@ -454,6 +502,16 @@ TestNGCP = {} --class
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ah736f72_21d1_4ea6_a3ea_4d7f56b3887c")) self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("ah736f72_21d1_4ea6_a3ea_4d7f56b3887c"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil) self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close() self.cur:close()
-- connection check
self.con:execute("SELECT 1") ;mc :returns(self.cur)
self.cur:fetch() ;mc :returns({})
self.cur:numrows() ;mc :returns(1)
self.cur:close()
--
self.con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ah736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_2"))
self.cur:close()
mc:replay() mc:replay()
local keys = self.ngcp:callee_usr_load("ah736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56") local keys = self.ngcp:callee_usr_load("ah736f72-21d1-4ea6-a3ea-4d7f56b3887c", "192.168.51.56")
@ -644,7 +702,7 @@ TestNGCP = {} --class
end end
function TestNGCP:test_tostring() function TestNGCP:test_tostring()
assertEquals(tostring(self.ngcp), 'caller_contract_prefs:{dummy={"caller"}}\ncallee_contract_prefs:{dummy={"callee"}}\ncaller_peer_prefs:{dummy={"caller"}}\ncallee_peer_prefs:{dummy={"callee"}}\ncaller_dom_prefs:{dummy={"caller"}}\ncallee_dom_prefs:{dummy={"callee"}}\ncaller_prof_prefs:{dummy={"caller"}}\ncallee_prof_prefs:{dummy={"callee"}}\ncaller_usr_prefs:{dummy={"caller"}}\ncallee_usr_prefs:{dummy={"callee"}}\ncaller_real_prefs:{dummy={"caller"}}\ncallee_real_prefs:{dummy={"callee"}}\n') assertEquals(tostring(self.ngcp), 'caller_contract_prefs:{dummy={"caller"}}\ncallee_contract_prefs:{dummy={"callee"}}\ncaller_peer_prefs:{dummy={"caller"}}\ncallee_peer_prefs:{dummy={"callee"}}\ncaller_dom_prefs:{dummy={"caller"}}\ncallee_dom_prefs:{dummy={"callee"}}\ncaller_prof_prefs:{dummy={"caller"}}\ncallee_prof_prefs:{dummy={"callee"}}\ncaller_fax_prefs:{dummy={"caller"}}\ncallee_fax_prefs:{dummy={"callee"}}\ncaller_usr_prefs:{dummy={"caller"}}\ncallee_usr_prefs:{dummy={"callee"}}\ncaller_real_prefs:{dummy={"caller"}}\ncallee_real_prefs:{dummy={"callee"}}\n')
end end
-- class TestNGCP -- class TestNGCP
--EOF --EOF

@ -0,0 +1,206 @@
--
-- Copyright 2013 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
require('luaunit')
local lemock = require('lemock')
local FPFetch = require 'tests_v.fp_vars'
local srMock = require 'mocks.sr'
sr = srMock:new()
local mc,env,con
local fp_vars = FPFetch:new()
package.loaded.luasql = nil
package.preload['luasql.mysql'] = function ()
local luasql = {}
luasql.mysql = function ()
return env
end
end
local NGCPConfig = require 'ngcp.config'
local NGCPFaxPrefs = require 'ngcp.fp'
-- luacheck: ignore TestNGCPFaxPrefs
TestNGCPFaxPrefs = {} --class
function TestNGCPFaxPrefs:setUp()
mc = lemock.controller()
env = mc:mock()
con = mc:mock()
self.cur = mc:mock()
package.loaded.luasql = nil
package.preload['luasql.mysql'] = function ()
local luasql = {}
luasql.mysql = function ()
return env
end
end
self.config = NGCPConfig:new()
self.config.env = env
self.config.getDBConnection = function ()
return con
end
self.d = NGCPFaxPrefs:new(self.config)
end
function TestNGCPFaxPrefs:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_prof_prefs)")
sr.pv.unset("$xavp(callee_prof_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.pv.unset("$xavp(caller_fax_prefs)")
sr.pv.unset("$xavp(callee_fax_prefs)")
sr.log("info", "---TestNGCPFaxPrefs::cleaned---")
end
function TestNGCPFaxPrefs:test_init()
--print("TestNGCPFaxPrefs:test_init")
assertEquals(self.d.db_table, "provisioning.voip_fax_preferences")
end
function TestNGCPFaxPrefs:test_caller_load_empty()
assertTrue(self.d.config)
assertEquals(self.d:caller_load(), {})
end
function TestNGCPFaxPrefs:test_callee_load_empty()
assertTrue(self.d.config)
assertEquals(self.d:callee_load(), {})
end
function TestNGCPFaxPrefs:test_caller_load()
assertTrue(self.d.config)
con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ah736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_1"))
self.cur:close()
mc:replay()
local keys = self.d:caller_load("ah736f72-21d1-4ea6-a3ea-4d7f56b3887c")
mc:verify()
for k,v in pairs(fp_vars:val("fp_keys")) do
assertEquals(keys[k], v)
end
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"), "caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>active)"), 1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>t38)"), 1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>ecm)"), 1)
end
function TestNGCPFaxPrefs:test_callee_load()
assertTrue(self.d.config)
con:execute("SELECT fp.* FROM provisioning.voip_fax_preferences fp, provisioning.voip_subscribers s WHERE s.uuid = 'ah736f72-21d1-4ea6-a3ea-4d7f56b3887c' AND fp.subscriber_id = s.id") ;mc :returns(self.cur)
self.cur:getcolnames() ;mc :returns(fp_vars:val("fp_keys"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(fp_vars:val("fp_2"))
self.cur:close()
mc:replay()
local keys = self.d:callee_load("ah736f72-21d1-4ea6-a3ea-4d7f56b3887c")
mc:verify()
for k,v in pairs(fp_vars:val("fp_keys")) do
assertEquals(keys[k], v)
end
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>active)"), 1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>t38)"), 0)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>ecm)"), 0)
end
function TestNGCPFaxPrefs:test_clean()
local xavp = NGCPFaxPrefs:xavp('callee')
xavp("testid",1)
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean()
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
assertFalse(sr.pv.get("$xavp(fax)"))
end
function TestNGCPFaxPrefs:test_callee_clean()
local callee_xavp = NGCPFaxPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPFaxPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(callee_fax_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(callee_fax_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end
function TestNGCPFaxPrefs:test_caller_clean()
local callee_xavp = NGCPFaxPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPFaxPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_fax_prefs=>dummy)"),"caller")
assertFalse(sr.pv.get("$xavp(caller_fax_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(caller_fax_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_fax_prefs=>dummy)"),"callee")
end
function TestNGCPFaxPrefs:test_tostring()
local callee_xavp = NGCPFaxPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPFaxPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(tostring(self.d), 'caller_fax_prefs:{other={1},otherfoo={"foo"},dummy={"caller"}}\ncallee_fax_prefs:{dummy={"callee"},testid={1},foo={"foo"}}\n')
end
-- class TestNGCPFaxPrefs
--EOF

@ -0,0 +1,66 @@
--
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
local fp_vars = {
fp_keys = {
"active",
"send_status",
"send_copy",
"t38",
"ecm" },
fp_1 = {
id = 1,
subscriber_id = "1",
password = nil,
name = nil,
active = 1,
send_status = 1,
send_copy = 1,
t38 = 1,
ecm = 1
},
fp_2 = {
id = 2,
subscriber_id = "2",
password = nil,
name = nil,
active = 1,
send_status = 1,
send_copy = 1,
t38 = 0,
ecm = 0
}
}
local FPFetch = {
__class__ = 'FPFetch',
}
function FPFetch.new()
local t = {}
return setmetatable(t, { __index = FPFetch })
end
function FPFetch:val(uuid)
return fp_vars[uuid]
end
function FPFetch:reset()
return
end
return FPFetch
Loading…
Cancel
Save