test for TP aliases and users

This commit is contained in:
Radu Ioan Fericean
2015-09-03 14:29:12 +03:00
parent 7f0925c4e0
commit 1c94fca45c
7 changed files with 82 additions and 10 deletions

View File

@@ -367,7 +367,7 @@ CREATE TABLE tp_aliases (
`account` varchar(64) NOT NULL,
`subject` varchar(64) NOT NULL,
`group` varchar(64) NOT NULL,
`destionation_id` varchar(64) NOT NULL,
`destination_id` varchar(64) NOT NULL,
`alias` varchar(64) NOT NULL,
`weight` decimal(8,2) NOT NULL,
`created_at` TIMESTAMP,

View File

@@ -363,7 +363,7 @@ CREATE TABLE tp_aliases (
"account" VARCHAR(64) NOT NULL,
"subject" VARCHAR(64) NOT NULL,
"group" VARCHAR(64) NOT NULL,
"destionation_id" VARCHAR(64) NOT NULL,
"destination_id" VARCHAR(64) NOT NULL,
"alias" VARCHAR(64) NOT NULL,
"weight" NUMERIC(8,2) NOT NULL,
"created_at" TIMESTAMP

View File

@@ -0,0 +1,3 @@
#Direction,Tenant,Category,Account,Subject,DestinationId,Group,Alias,Weight
*out,cgrates.org,call,1006,1006,*any,*rating_profile,1001,10
*out,cgrates.org,call,1006,1006,*any,*account,1002,10
1 #Direction Tenant Category Account Subject DestinationId Group Alias Weight
2 *out cgrates.org call 1006 1006 *any *rating_profile 1001 10
3 *out cgrates.org call 1006 1006 *any *account 1002 10

View File

@@ -0,0 +1,19 @@
#Tenant[0],UserName[1],AttributeName[2],AttributeValue[3]
cgrates.org,1001,SysUserName,danb
cgrates.org,1001,SysPassword,hisPass321
cgrates.org,1001,Cli,+4986517174963
cgrates.org,1001,Account,1001
cgrates.org,1001,Subject,1001
cgrates.org,1001,Uuid,388539dfd4f5cefee8f488b78c6c244b9e19138e
cgrates.org,1001,ReqType,*prepaid
cgrates.org,1002,SysUserName,rif
cgrates.org,1002,RifAttr,RifVal
cgrates.org,1002,Account,1002
cgrates.org,1002,Subject,1002
cgrates.org,1002,Uuid,27f37edec0670fa34cf79076b80ef5021e39c5b5
cgrates.org,1004,SysUserName,danb4
cgrates.org,1004,SysPassword,hisPass321
cgrates.org,1004,Cli,+4986517174964
cgrates.org,1004,Account,1004
cgrates.org,1004,Subject,1004
cgrates.org,1004,ReqType,*rated
1 #Tenant[0] UserName[1] AttributeName[2] AttributeValue[3]
2 cgrates.org 1001 SysUserName danb
3 cgrates.org 1001 SysPassword hisPass321
4 cgrates.org 1001 Cli +4986517174963
5 cgrates.org 1001 Account 1001
6 cgrates.org 1001 Subject 1001
7 cgrates.org 1001 Uuid 388539dfd4f5cefee8f488b78c6c244b9e19138e
8 cgrates.org 1001 ReqType *prepaid
9 cgrates.org 1002 SysUserName rif
10 cgrates.org 1002 RifAttr RifVal
11 cgrates.org 1002 Account 1002
12 cgrates.org 1002 Subject 1002
13 cgrates.org 1002 Uuid 27f37edec0670fa34cf79076b80ef5021e39c5b5
14 cgrates.org 1004 SysUserName danb4
15 cgrates.org 1004 SysPassword hisPass321
16 cgrates.org 1004 Cli +4986517174964
17 cgrates.org 1004 Account 1004
18 cgrates.org 1004 Subject 1004
19 cgrates.org 1004 ReqType *rated

View File

@@ -131,7 +131,6 @@ func TestLoadFromCSV(t *testing.T) {
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DERIVED_CHARGERS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.CDR_STATS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.USERS_CSV),
path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ALIASES_CSV),
), "", "", lCfg.LoadHistorySize)
@@ -169,6 +168,9 @@ func TestLoadFromCSV(t *testing.T) {
if err = loader.LoadDerivedChargers(); err != nil {
t.Error("Failed loading derived chargers: ", err.Error())
}
if err = loader.LoadLCRs(); err != nil {
t.Error("Failed loading lcr rules: ", err.Error())
}
if err = loader.LoadUsers(); err != nil {
t.Error("Failed loading users: ", err.Error())
}
@@ -241,6 +243,15 @@ func TestLoadFromStorDb(t *testing.T) {
if err := loader.LoadDerivedChargers(); err != nil {
t.Error("Failed loading derived chargers: ", err.Error())
}
if err := loader.LoadLCRs(); err != nil {
t.Error("Failed loading lcr rules: ", err.Error())
}
if err := loader.LoadUsers(); err != nil {
t.Error("Failed loading users: ", err.Error())
}
if err := loader.LoadAliases(); err != nil {
t.Error("Failed loading aliases: ", err.Error())
}
if err := loader.WriteToDatabase(true, false); err != nil {
t.Error("Could not write data into ratingDb: ", err.Error())
}
@@ -322,6 +333,30 @@ func TestLoadIndividualProfiles(t *testing.T) {
}
}
}
// Load users
if users, err := storDb.GetTpUsers(&TpUser{Tpid: utils.TEST_SQL}); err != nil {
t.Fatal("Could not retrieve users, error: ", err.Error())
} else if len(users) == 0 {
t.Fatal("Could not retrieve users")
} else {
for _, usr := range users {
if found, err := loader.LoadUsersFiltered(&usr); found && err != nil {
t.Fatalf("Could not user with id: %s, error: %s", usr.GetId(), err.Error())
}
}
}
// Load aliases
if aliases, err := storDb.GetTpAliases(&TpAlias{Tpid: utils.TEST_SQL}); err != nil {
t.Fatal("Could not retrieve aliases, error: ", err.Error())
} else if len(aliases) == 0 {
t.Fatal("Could not retrieve aliases")
} else {
for _, al := range aliases {
if found, err := loader.LoadAliasesFiltered(&al); found && err != nil {
t.Fatalf("Could not load aliase with id: %s, error: %s", al.GetId(), err.Error())
}
}
}
// Load account actions
if accountActions, err := storDb.GetTpAccountActions(&TpAccountAction{Tpid: utils.TEST_SQL, Loadid: loadId}); err != nil {
t.Fatal("Could not retrieve account action profiles, error: ", err.Error())

View File

@@ -1388,24 +1388,24 @@ func (self *SQLStorage) SetTpAliases(aliases []TpAlias) error {
func (self *SQLStorage) GetTpAliases(filter *TpAlias) ([]TpAlias, error) {
var tpAliases []TpAlias
q := self.db.Where("tpid = ?", filter.Tpid)
q := self.db.Where("`tpid` = ?", filter.Tpid)
if len(filter.Direction) != 0 {
q = q.Where("direction = ?", filter.Direction)
q = q.Where("`direction` = ?", filter.Direction)
}
if len(filter.Tenant) != 0 {
q = q.Where("tenant = ?", filter.Tenant)
q = q.Where("`tenant` = ?", filter.Tenant)
}
if len(filter.Category) != 0 {
q = q.Where("category = ?", filter.Category)
q = q.Where("`category` = ?", filter.Category)
}
if len(filter.Account) != 0 {
q = q.Where("account = ?", filter.Account)
q = q.Where("`account` = ?", filter.Account)
}
if len(filter.Subject) != 0 {
q = q.Where("subject = ?", filter.Subject)
q = q.Where("`subject` = ?", filter.Subject)
}
if len(filter.Group) != 0 {
q = q.Where("group = ?", filter.Group)
q = q.Where("`group` = ?", filter.Group)
}
if err := q.Find(&tpAliases).Error; err != nil {

View File

@@ -55,6 +55,7 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{
utils.DERIVED_CHARGERS_CSV: (*TPCSVImporter).importDerivedChargers,
utils.CDR_STATS_CSV: (*TPCSVImporter).importCdrStats,
utils.USERS_CSV: (*TPCSVImporter).importUsers,
utils.ALIASES_CSV: (*TPCSVImporter).importAliases,
}
func (self *TPCSVImporter) Run() error {
@@ -314,3 +315,17 @@ func (self *TPCSVImporter) importUsers(fn string) error {
return self.StorDb.SetTpUsers(tps)
}
func (self *TPCSVImporter) importAliases(fn string) error {
if self.Verbose {
log.Printf("Processing file: <%s> ", fn)
}
tps, err := self.csvr.GetTpAliases(nil)
if err != nil {
return err
}
for i := 0; i < len(tps); i++ {
tps[i].Tpid = self.TPid
}
return self.StorDb.SetTpAliases(tps)
}