mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 13:49:53 +05:00
Update apier/v1/suppliers_it_test and tpattribute_it_test
This commit is contained in:
committed by
Dan Christian Bogos
parent
11e713ee72
commit
e1d6b96dd8
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/cache"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -28,7 +29,7 @@ func (apierV1 *ApierV1) GetAttributeProfile(arg utils.TenantID, reply *engine.Ex
|
||||
if missing := utils.MissingStructFields(&arg, []string{"Tenant", "ID"}); len(missing) != 0 { //Params missing
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, true, utils.NonTransactional); err != nil {
|
||||
if alsPrf, err := apierV1.DataManager.GetAttributeProfile(arg.Tenant, arg.ID, false, utils.NonTransactional); err != nil {
|
||||
if err.Error() != utils.ErrNotFound.Error() {
|
||||
err = utils.NewErrServerError(err)
|
||||
}
|
||||
@@ -48,6 +49,7 @@ func (apierV1 *ApierV1) SetAttributeProfile(extAls *engine.ExternalAttributeProf
|
||||
if err := apierV1.DataManager.SetAttributeProfile(alsPrf); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
cache.RemKey(utils.AttributeProfilePrefix+utils.ConcatenatedKey(extAls.Tenant, extAls.ID), true, "") // ToDo: Remove here with autoreload
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"github.com/cgrates/cgrates/cache"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
@@ -47,6 +48,7 @@ func (apierV1 *ApierV1) SetSupplierProfile(spp *engine.SupplierProfile, reply *s
|
||||
if err := apierV1.DataManager.SetSupplierProfile(spp); err != nil {
|
||||
return utils.APIErrorHandler(err)
|
||||
}
|
||||
cache.RemKey(utils.SupplierProfilePrefix+utils.ConcatenatedKey(spp.Tenant, spp.ID), true, "") // ToDo: Remove here with autoreload
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ var (
|
||||
splSv1CfgPath string
|
||||
splSv1Cfg *config.CGRConfig
|
||||
splSv1Rpc *rpc.Client
|
||||
splPrf *engine.SupplierProfile
|
||||
splSv1ConfDIR string //run tests for specific configuration
|
||||
splsDelay int
|
||||
)
|
||||
@@ -49,6 +50,9 @@ var sTestsSupplierSV1 = []func(t *testing.T){
|
||||
testV1SplSFromFolder,
|
||||
testV1SplSGetWeightSuppliers,
|
||||
testV1SplSGetLeastCostSuppliers,
|
||||
testV1SplSSetSupplierProfiles,
|
||||
testV1SplSUpdateSupplierProfiles,
|
||||
testV1SplSRemSupplierProfiles,
|
||||
testV1SplSStopEngine,
|
||||
}
|
||||
|
||||
@@ -207,6 +211,116 @@ func testV1SplSGetLeastCostSuppliers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testV1SplSSetSupplierProfiles(t *testing.T) {
|
||||
var reply *engine.SupplierProfile
|
||||
if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
splPrf = &engine.SupplierProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TEST_PROFILE1",
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
Sorting: "Sort1",
|
||||
SortingParams: []string{"Param1", "Param2"},
|
||||
Suppliers: []*engine.Supplier{
|
||||
&engine.Supplier{
|
||||
ID: "SPL1",
|
||||
RatingPlanIDs: []string{"RP1"},
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc"},
|
||||
ResourceIDs: []string{"Res1", "ResGroup2"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 20,
|
||||
},
|
||||
},
|
||||
Blocker: false,
|
||||
Weight: 10,
|
||||
}
|
||||
var result string
|
||||
if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(splPrf, reply) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", splPrf, reply)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1SplSUpdateSupplierProfiles(t *testing.T) {
|
||||
splPrf.Suppliers = []*engine.Supplier{
|
||||
&engine.Supplier{
|
||||
ID: "SPL1",
|
||||
RatingPlanIDs: []string{"RP1"},
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc"},
|
||||
ResourceIDs: []string{"Res1", "ResGroup2"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 20,
|
||||
},
|
||||
&engine.Supplier{
|
||||
ID: "SPL2",
|
||||
RatingPlanIDs: []string{"RP2"},
|
||||
FilterIDs: []string{"FLTR_2"},
|
||||
AccountIDs: []string{"Acc"},
|
||||
ResourceIDs: []string{"Res2", "ResGroup2"},
|
||||
StatIDs: []string{"Stat2"},
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
reverseSuppliers := []*engine.Supplier{
|
||||
&engine.Supplier{
|
||||
ID: "SPL2",
|
||||
RatingPlanIDs: []string{"RP2"},
|
||||
FilterIDs: []string{"FLTR_2"},
|
||||
AccountIDs: []string{"Acc"},
|
||||
ResourceIDs: []string{"Res2", "ResGroup2"},
|
||||
StatIDs: []string{"Stat2"},
|
||||
Weight: 20,
|
||||
},
|
||||
&engine.Supplier{
|
||||
ID: "SPL1",
|
||||
RatingPlanIDs: []string{"RP1"},
|
||||
FilterIDs: []string{"FLTR_1"},
|
||||
AccountIDs: []string{"Acc"},
|
||||
ResourceIDs: []string{"Res1", "ResGroup2"},
|
||||
StatIDs: []string{"Stat1"},
|
||||
Weight: 20,
|
||||
},
|
||||
}
|
||||
var result string
|
||||
if err := splSv1Rpc.Call("ApierV1.SetSupplierProfile", splPrf, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
var reply *engine.SupplierProfile
|
||||
if err := splSv1Rpc.Call("ApierV1.GetSupplierProfile",
|
||||
&utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if !reflect.DeepEqual(splPrf.Suppliers, reply.Suppliers) && !reflect.DeepEqual(reverseSuppliers, reply.Suppliers) {
|
||||
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(splPrf), utils.ToJSON(reply))
|
||||
}
|
||||
}
|
||||
|
||||
func testV1SplSRemSupplierProfiles(t *testing.T) {
|
||||
var resp string
|
||||
if err := splSv1Rpc.Call("ApierV1.RemSupplierProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil {
|
||||
t.Error(err)
|
||||
} else if resp != utils.OK {
|
||||
t.Error("Unexpected reply returned", resp)
|
||||
}
|
||||
var reply *engine.SupplierProfile
|
||||
if err := splSv1Rpc.Call("ApierV1.GetAttributeProfile", &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testV1SplSStopEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(100); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -130,8 +130,8 @@ func testTPAlsPrfSetTPAlsPrf(t *testing.T) {
|
||||
ExpiryTime: "",
|
||||
},
|
||||
Context: "con1",
|
||||
Attributes: []*utils.TPRequestAttribute{
|
||||
&utils.TPRequestAttribute{
|
||||
Substitutes: []*utils.TPRequestSubstitute{
|
||||
&utils.TPRequestSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
@@ -168,14 +168,14 @@ func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) {
|
||||
tpAlsPrf.Attributes = []*utils.TPRequestAttribute{
|
||||
&utils.TPRequestAttribute{
|
||||
tpAlsPrf.Substitutes = []*utils.TPRequestSubstitute{
|
||||
&utils.TPRequestSubstitute{
|
||||
FieldName: "FL1",
|
||||
Initial: "In1",
|
||||
Alias: "Al1",
|
||||
Append: true,
|
||||
},
|
||||
&utils.TPRequestAttribute{
|
||||
&utils.TPRequestSubstitute{
|
||||
FieldName: "FL2",
|
||||
Initial: "In2",
|
||||
Alias: "Al2",
|
||||
|
||||
Reference in New Issue
Block a user