mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 16:48:45 +05:00
lcr load and torfield to categoryfield
This commit is contained in:
@@ -19,10 +19,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var cfgDcT *config.CGRConfig
|
||||
@@ -47,7 +48,7 @@ func TestHandleGetEmptyDC(t *testing.T) {
|
||||
// Accounting db has no DerivedChargers, configured defaults
|
||||
func TestHandleGetConfiguredDC(t *testing.T) {
|
||||
cfgedDC := utils.DerivedChargers{&utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
cfgDcT.DerivedChargers = cfgedDC
|
||||
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Tor: "call", Direction: "*out", Account: "test3", Subject: "test3"}
|
||||
if dcs, err := HandleGetDerivedChargers(acntDb, cfgDcT, attrs); err != nil {
|
||||
@@ -61,9 +62,9 @@ func TestHandleGetConfiguredDC(t *testing.T) {
|
||||
func TestHandleGetStoredDC(t *testing.T) {
|
||||
keyCharger1 := utils.DerivedChargersKey("cgrates.org", "call", "*out", "rif", "rif")
|
||||
charger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
if err := acntDb.SetDerivedChargers(keyCharger1, charger1); err != nil {
|
||||
@@ -71,7 +72,7 @@ func TestHandleGetStoredDC(t *testing.T) {
|
||||
}
|
||||
// Expected Charger should have default configured values added
|
||||
expCharger1 := append(charger1, &utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"})
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"})
|
||||
acntDb.CacheAccounting(nil, nil, nil, nil)
|
||||
attrs := utils.AttrDerivedChargers{Tenant: "cgrates.org", Tor: "call", Direction: "*out", Account: "rif", Subject: "rif"}
|
||||
if dcs, err := HandleGetDerivedChargers(acntDb, cfgDcT, attrs); err != nil {
|
||||
|
||||
@@ -835,7 +835,7 @@ func (csvr *CSVReader) LoadDerivedChargers() (err error) {
|
||||
ReqTypeField: ValueOrDefault(record[6], "*default"),
|
||||
DirectionField: ValueOrDefault(record[7], "*default"),
|
||||
TenantField: ValueOrDefault(record[8], "*default"),
|
||||
TorField: ValueOrDefault(record[9], "*default"),
|
||||
CategoryField: ValueOrDefault(record[9], "*default"),
|
||||
AccountField: ValueOrDefault(record[10], "*default"),
|
||||
SubjectField: ValueOrDefault(record[11], "*default"),
|
||||
DestinationField: ValueOrDefault(record[12], "*default"),
|
||||
@@ -854,7 +854,7 @@ func (csvr *CSVReader) LoadDerivedChargers() (err error) {
|
||||
ReqTypeField: ValueOrDefault(record[6], "*default"),
|
||||
DirectionField: ValueOrDefault(record[7], "*default"),
|
||||
TenantField: ValueOrDefault(record[8], "*default"),
|
||||
TorField: ValueOrDefault(record[9], "*default"),
|
||||
CategoryField: ValueOrDefault(record[9], "*default"),
|
||||
AccountField: ValueOrDefault(record[10], "*default"),
|
||||
SubjectField: ValueOrDefault(record[11], "*default"),
|
||||
DestinationField: ValueOrDefault(record[12], "*default"),
|
||||
|
||||
@@ -909,9 +909,9 @@ func TestLoadDerivedChargers(t *testing.T) {
|
||||
t.Error("Failed to load derivedChargers: ", csvr.derivedChargers)
|
||||
}
|
||||
expCharger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
keyCharger1 := utils.DerivedChargersKey("cgrates.org", "call", "*out", "dan", "dan")
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
@@ -474,59 +473,8 @@ func (dbr *DbReader) LoadSharedGroups() (err error) {
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadLCRs() (err error) {
|
||||
dbr.sharedGroups, err = dbr.storDb.GetTpSharedGroups(dbr.tpid, "")
|
||||
dbr.lcrs, err = dbr.storDb.GetTpLCRs(dbr.tpid, "")
|
||||
return err
|
||||
csvReader, fp, err := csvr.readerFunc(csvr.lcrFn, csvr.sep, utils.LCRS_NRCOLS)
|
||||
if err != nil {
|
||||
log.Print("Could not load LCR rules file: ", err)
|
||||
// allow writing of the other values
|
||||
return nil
|
||||
}
|
||||
if fp != nil {
|
||||
defer fp.Close()
|
||||
}
|
||||
for record, err := csvReader.Read(); err == nil; record, err = csvReader.Read() {
|
||||
direction, tenant, customer := record[0], record[1], record[2]
|
||||
id := fmt.Sprintf("%s:%s:%s", direction, tenant, customer)
|
||||
lcr, found := csvr.lcrs[id]
|
||||
activationTime, err := utils.ParseTimeDetectLayout(record[7])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not parse LCR activation time: %v", err)
|
||||
}
|
||||
weight, err := strconv.ParseFloat(record[8], 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not parse LCR weight: %v", err)
|
||||
}
|
||||
if !found {
|
||||
lcr = &LCR{
|
||||
Direction: direction,
|
||||
Tenant: tenant,
|
||||
Customer: customer,
|
||||
}
|
||||
}
|
||||
var act *LCRActivation
|
||||
for _, existingAct := range lcr.Activations {
|
||||
if existingAct.ActivationTime.Equal(activationTime) {
|
||||
act = existingAct
|
||||
break
|
||||
}
|
||||
}
|
||||
if act == nil {
|
||||
act = &LCRActivation{
|
||||
ActivationTime: activationTime,
|
||||
}
|
||||
lcr.Activations = append(lcr.Activations, act)
|
||||
}
|
||||
act.Entries = append(act.Entries, &LCREntry{
|
||||
DestinationId: record[3],
|
||||
Category: record[4],
|
||||
Strategy: record[5],
|
||||
Suppliers: record[6],
|
||||
Weight: weight,
|
||||
})
|
||||
csvr.lcrs[id] = lcr
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (dbr *DbReader) LoadActions() (err error) {
|
||||
|
||||
@@ -19,17 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
// Test internal abilites of GetDerivedChargers
|
||||
func TestResponderGetDerivedChargers(t *testing.T) {
|
||||
cfg, _ := config.NewDefaultCGRConfig()
|
||||
cfgedDC := utils.DerivedChargers{&utils.DerivedCharger{RunId: "responder1", ReqTypeField: "test", DirectionField: "test", TenantField: "test",
|
||||
TorField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
CategoryField: "test", AccountField: "test", SubjectField: "test", DestinationField: "test", SetupTimeField: "test", AnswerTimeField: "test", DurationField: "test"}}
|
||||
cfg.DerivedChargers = cfgedDC
|
||||
config.SetCgrConfig(cfg)
|
||||
r := Responder{}
|
||||
|
||||
@@ -57,9 +57,9 @@ func TestSetGetDerivedCharges(t *testing.T) {
|
||||
}
|
||||
keyCharger1 := utils.ConcatenatedKey("cgrates.org", "call", "*out", "dan", "dan")
|
||||
charger1 := utils.DerivedChargers{
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra1", ReqTypeField: "^prepaid", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "rif", SubjectField: "rif", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", TorField: "*default",
|
||||
&utils.DerivedCharger{RunId: "extra2", ReqTypeField: "*default", DirectionField: "*default", TenantField: "*default", CategoryField: "*default",
|
||||
AccountField: "ivo", SubjectField: "ivo", DestinationField: "*default", SetupTimeField: "*default", AnswerTimeField: "*default", DurationField: "*default"},
|
||||
}
|
||||
if err := rds.SetDerivedChargers(keyCharger1, charger1); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user