mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add category in http agent templates and update tests
This commit is contained in:
committed by
Dan Christian Bogos
parent
0281571b35
commit
32363d7913
@@ -149,6 +149,20 @@ func testHAitTPFromFolder(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
//add a default charger
|
||||
chargerProfile := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := haRPC.Call("ApierV1.SetChargerProfile", chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testHAitAuthDryRun(t *testing.T) {
|
||||
@@ -197,14 +211,15 @@ func testHAitAuth1001(t *testing.T) {
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
httpConst := "http"
|
||||
addr := haCfg.ListenCfg().HTTPListen
|
||||
if isTls {
|
||||
addr = haCfg.ListenCfg().HTTPTLSListen
|
||||
httpConst = "https"
|
||||
|
||||
}
|
||||
|
||||
reqUrl := fmt.Sprintf("%s://%s%s?request_type=OutboundAUTH&CallID=123456&Msisdn=%s&Imsi=2343000000000123&Destination=1002&MSRN=0102220233444488999&ProfileID=1&AgentID=176&GlobalMSISDN=497700056129&GlobalIMSI=214180000175129&ICCID=8923418450000089629&MCC=234&MNC=10&calltype=callback",
|
||||
httpConst, addr, haCfg.HttpAgentCfg()[0].Url, acnt)
|
||||
rply, err := httpC.Get(reqUrl)
|
||||
|
||||
@@ -40,7 +40,7 @@ var (
|
||||
sSv1Cfg *config.CGRConfig
|
||||
sSv1BiRpc *rpc2.Client
|
||||
sSApierRpc *rpc.Client
|
||||
discEvChan = make(chan *utils.AttrDisconnectSession)
|
||||
discEvChan = make(chan *utils.AttrDisconnectSession, 1)
|
||||
)
|
||||
|
||||
func handleDisconnectSession(clnt *rpc2.Client,
|
||||
@@ -655,14 +655,13 @@ func TestSSv1ItCDRsGetCdrs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
var aSessions []*sessions.ActiveSession
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions,
|
||||
nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
aSessions := make([]*sessions.ActiveSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Error: %v with len(asessions)=%v", err, len(aSessions))
|
||||
}
|
||||
var acnt *engine.Account
|
||||
attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}
|
||||
eAcntVal := 9.3995
|
||||
eAcntVal := 9.399500
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
@@ -720,7 +719,6 @@ func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(eAttrs, rply.Attributes) {
|
||||
t.Errorf("expecting: %+v, received: %+v",
|
||||
utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
|
||||
@@ -728,31 +726,30 @@ func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
if *rply.MaxUsage != reqUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
|
||||
aSessions = make([]*sessions.ActiveSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 2 {
|
||||
t.Errorf("wrong active ssesions: %s", utils.ToJSON(aSessions))
|
||||
}
|
||||
|
||||
eAcntVal = 9.2495
|
||||
eAcntVal = 9.249500
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
|
||||
var rplyt string
|
||||
rplyt := ""
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
map[string]string{utils.OriginID: "TestSSv1It"}, &rplyt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rplyt != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rplyt)
|
||||
}
|
||||
|
||||
aSessions = make([]*sessions.ActiveSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Error: %v with len(asessions)=%v and sessions : %+v", err, len(aSessions), utils.ToJSON(aSessions))
|
||||
t.Error(err)
|
||||
}
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"tenant": "cgrates.org",
|
||||
"flags": [ "*auth", "*accounts", "*attributes"],
|
||||
"request_fields":[
|
||||
{"tag": "Category", "field_id": "Category", "type": "*constant", "value": "call"},
|
||||
{"tag": "RequestType", "field_id": "RequestType", "type": "*constant",
|
||||
"value": "*pseudoprepaid", "mandatory": true},
|
||||
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed",
|
||||
|
||||
@@ -50,6 +50,12 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
{"address": "*internal"}
|
||||
],
|
||||
},
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"tenant": "cgrates.org",
|
||||
"flags": [ "*auth", "*accounts", "*attributes"],
|
||||
"request_fields":[
|
||||
{"tag": "Category", "field_id": "Category", "type": "*constant", "value": "call"},
|
||||
{"tag": "RequestType", "field_id": "RequestType", "type": "*constant",
|
||||
"value": "*pseudoprepaid", "mandatory": true},
|
||||
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed",
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
@@ -54,6 +54,10 @@
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"chargers": {
|
||||
"enabled": true,
|
||||
},
|
||||
|
||||
"sessions": {
|
||||
"enabled": true,
|
||||
"attributes_conns": [
|
||||
|
||||
@@ -29,10 +29,11 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/apier/v2"
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
v2 "github.com/cgrates/cgrates/apier/v2"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/sessions"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -101,6 +102,21 @@ func TestA1itLoadTPFromFolder(t *testing.T) {
|
||||
} else if cc.Cost != 0.0 {
|
||||
t.Errorf("Calling Responder.GetCost got callcost: %v", cc)
|
||||
}
|
||||
|
||||
//add a default charger
|
||||
chargerProfile := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := a1rpc.Call("ApierV1.SetChargerProfile", chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestA1itAddBalance1(t *testing.T) {
|
||||
@@ -125,82 +141,115 @@ func TestA1itAddBalance1(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestA1itDataSession1(t *testing.T) {
|
||||
smgEv := map[string]interface{}{
|
||||
utils.EVENT_NAME: "INITIATE_SESSION",
|
||||
utils.ToR: utils.DATA,
|
||||
utils.OriginID: "504966119",
|
||||
utils.Direction: utils.OUT,
|
||||
utils.Account: "rpdata1",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Destination: "data",
|
||||
utils.Category: "data1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Usage: "10240",
|
||||
utils.SessionTTL: "28800s",
|
||||
utils.SessionTTLLastUsed: "0s",
|
||||
utils.SessionTTLUsage: "0s",
|
||||
|
||||
usage := time.Duration(10240)
|
||||
initArgs := &sessions.V1InitSessionArgs{
|
||||
InitSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestA1itDataSession1",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "INITIATE_SESSION",
|
||||
utils.ToR: utils.DATA,
|
||||
utils.OriginID: "504966119",
|
||||
utils.Account: "rpdata1",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Destination: "data",
|
||||
utils.Category: "data1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Usage: "10240",
|
||||
utils.SessionTTL: "28800s",
|
||||
utils.SessionTTLLastUsed: "0s",
|
||||
utils.SessionTTLUsage: "0s",
|
||||
},
|
||||
},
|
||||
}
|
||||
var maxUsage float64
|
||||
if err := a1rpc.Call(utils.SMGenericV2InitiateSession, smgEv, &maxUsage); err != nil {
|
||||
|
||||
var initRpl *sessions.V1InitSessionReply
|
||||
if err := a1rpc.Call(utils.SessionSv1InitiateSession,
|
||||
initArgs, &initRpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if maxUsage != 10240 {
|
||||
t.Error("Received: ", maxUsage)
|
||||
}
|
||||
smgEv = map[string]interface{}{
|
||||
utils.EVENT_NAME: "UPDATE_SESSION",
|
||||
utils.Account: "rpdata1",
|
||||
utils.Category: "data1",
|
||||
utils.Destination: "data",
|
||||
utils.Direction: utils.OUT,
|
||||
utils.InitialOriginID: "504966119",
|
||||
utils.LastUsed: "0s",
|
||||
utils.OriginID: "504966119-1",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SessionTTL: "28800s",
|
||||
utils.SessionTTLLastUsed: "2097152s",
|
||||
utils.SessionTTLUsage: "0s",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.ToR: utils.DATA,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Usage: "2097152",
|
||||
if *initRpl.MaxUsage != usage {
|
||||
t.Errorf("Expecting : %+v, received: %+v", usage, *initRpl.MaxUsage)
|
||||
}
|
||||
if err := a1rpc.Call(utils.SMGenericV2UpdateSession,
|
||||
smgEv, &maxUsage); err != nil {
|
||||
|
||||
updateArgs := &sessions.V1UpdateSessionArgs{
|
||||
UpdateSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSessionsVoiceLastUsed",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "UPDATE_SESSION",
|
||||
utils.Account: "rpdata1",
|
||||
utils.Category: "data1",
|
||||
utils.Destination: "data",
|
||||
utils.InitialOriginID: "504966119",
|
||||
utils.LastUsed: "0s",
|
||||
utils.OriginID: "504966119-1",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SessionTTL: "28800s",
|
||||
utils.SessionTTLLastUsed: "2097152s",
|
||||
utils.SessionTTLUsage: "0s",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.ToR: utils.DATA,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Usage: "2097152",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
usage = time.Duration(2097152)
|
||||
var updateRpl *sessions.V1UpdateSessionReply
|
||||
if err := a1rpc.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if maxUsage != 2097152 {
|
||||
t.Error("Bad max usage: ", maxUsage)
|
||||
}
|
||||
smgEv = map[string]interface{}{
|
||||
utils.EVENT_NAME: "TERMINATE_SESSION",
|
||||
utils.Account: "rpdata1",
|
||||
utils.Category: "data1",
|
||||
utils.Destination: "data",
|
||||
utils.Direction: utils.OUT,
|
||||
utils.LastUsed: "2202800",
|
||||
utils.OriginID: "504966119-1",
|
||||
utils.OriginIDPrefix: "504966119-1",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.ToR: utils.DATA,
|
||||
if *updateRpl.MaxUsage != usage {
|
||||
t.Errorf("Expected: %+v, received: %+v", usage, *updateRpl.MaxUsage)
|
||||
}
|
||||
|
||||
usage = time.Duration(1 * time.Minute)
|
||||
termArgs := &sessions.V1TerminateSessionArgs{
|
||||
TerminateSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSessionsVoiceLastUsed",
|
||||
Event: map[string]interface{}{
|
||||
utils.EVENT_NAME: "TERMINATE_SESSION",
|
||||
utils.Account: "rpdata1",
|
||||
utils.Category: "data1",
|
||||
utils.Destination: "data",
|
||||
utils.LastUsed: "2202800",
|
||||
utils.OriginID: "504966119-1",
|
||||
utils.OriginIDPrefix: "504966119-1",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SetupTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.AnswerTime: "2017-03-03 11:39:32 +0100 CET",
|
||||
utils.Subject: "rpdata1",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.ToR: utils.DATA,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var rpl string
|
||||
if err = a1rpc.Call("SMGenericV1.TerminateSession", smgEv, &rpl); err != nil || rpl != utils.OK {
|
||||
if err := a1rpc.Call(utils.SessionSv1TerminateSession, termArgs, &rpl); err != nil || rpl != utils.OK {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := a1rpc.Call("SMGenericV1.ProcessCDR", smgEv, &rpl); err != nil {
|
||||
|
||||
if err := a1rpc.Call(utils.SessionSv1ProcessCDR, termArgs.CGREvent, &rpl); err != nil {
|
||||
t.Error(err)
|
||||
} else if rpl != utils.OK {
|
||||
t.Errorf("Received reply: %s", rpl)
|
||||
}
|
||||
|
||||
time.Sleep(time.Duration(20) * time.Millisecond)
|
||||
|
||||
var cdrs []*engine.ExternalCDR
|
||||
req := utils.RPCCDRsFilter{RunIDs: []string{utils.META_DEFAULT}}
|
||||
if err := a1rpc.Call("ApierV2.GetCdrs", req, &cdrs); err != nil {
|
||||
|
||||
@@ -172,7 +172,7 @@ func TestRPCITLclStatusFirstFailback(t *testing.T) {
|
||||
// Make sure it executes on the first node supporting the command
|
||||
func TestRPCITLclTDirectedRPC(t *testing.T) {
|
||||
var sessions []*sessions.ActiveSession
|
||||
if err := rpcPoolFirst.Call("SMGenericV1.GetActiveSessions", map[string]string{}, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
if err := rpcPoolFirst.Call(utils.SessionSv1GetActiveSessions, map[string]string{}, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,21 @@ func TestSrItLoadFromFolder(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
//add a default charger
|
||||
chargerProfile := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := srrpc.Call("ApierV1.SetChargerProfile", chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func testAccountBalance(t *testing.T, sracc, srten, balType string, expected float64) {
|
||||
|
||||
Reference in New Issue
Block a user