* 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: I2dcedf30433b3d5b94efa9292437a4e7501588a3changes/23/12823/4
parent
ce0a9fd104
commit
efab0961ea
@ -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
|
@ -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…
Reference in new issue