Commit 0436b9e5 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Fixed unitary tests for Policy
- Added missing kpiId field
parent 1a0b0665
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
        'policyrule_state'    : policyrule_state,
        'policyrule_state_msg': policyrule_state_msg,
        'policyrule_priority' : policyrule_basic.priority,
        'policyrule_kpi_id'   : policyrule_basic.kpiId.kpi_id.uuid,
        'policyrule_eca_data' : policyrule_eca_data,
        'created_at'          : now,
        'updated_at'          : now,
@@ -119,6 +120,7 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
                policyrule_state     = stmt.excluded.policyrule_state,
                policyrule_state_msg = stmt.excluded.policyrule_state_msg,
                policyrule_priority  = stmt.excluded.policyrule_priority,
                policyrule_kpi_id    = stmt.excluded.policyrule_kpi_id,
                policyrule_eca_data  = stmt.excluded.policyrule_eca_data,
                updated_at           = stmt.excluded.updated_at,
            )
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class PolicyRuleModel(_Base):
    policyrule_state        = Column(Enum(ORM_PolicyRuleStateEnum), nullable=False)
    policyrule_state_msg    = Column(String, nullable=False)
    policyrule_priority     = Column(Integer, nullable=False)
    policyrule_kpi_id       = Column(String, nullable=False)
    policyrule_service_uuid = Column(ForeignKey('service.service_uuid', ondelete='RESTRICT'), nullable=True, index=True)
    policyrule_eca_data     = Column(String, nullable=False)
    created_at              = Column(DateTime, nullable=False)
@@ -58,6 +59,7 @@ class PolicyRuleModel(_Base):
                'policyRuleStateMessage': self.policyrule_state_msg,
            },
            'priority': self.policyrule_priority,
            'kpiId': {'kpi_id': {'uuid': self.policyrule_kpi_id}},
        })
        result = {
            'policyRuleBasic': policyrule_basic,
+1 −1
Original line number Diff line number Diff line
@@ -186,4 +186,4 @@ CONNECTION_R1_R3_NAME, CONNECTION_R1_R3_ID, CONNECTION_R1_R3 = compose_connectio
# ----- PolicyRule -------------------------------------------------------------------------------------------------------
POLICYRULE_NAME = 'my-device-policy'
POLICYRULE_ID   = json_policyrule_id(POLICYRULE_NAME)
POLICYRULE      = json_policyrule(POLICYRULE_NAME, policy_priority=1)
POLICYRULE      = json_policyrule(POLICYRULE_NAME, policy_priority=1, policy_kpi_id='my-kpi-id')
+3 −0
Original line number Diff line number Diff line
@@ -60,8 +60,10 @@ def test_policy(context_client : ContextClient):

    # ----- Update the object ------------------------------------------------------------------------------------------
    new_policy_priority = 100
    new_policy_kpi_id = 'new-kpi-id'
    POLICYRULE_UPDATED = copy.deepcopy(POLICYRULE)
    POLICYRULE_UPDATED['device']['policyRuleBasic']['priority'] = new_policy_priority
    POLICYRULE_UPDATED['device']['policyRuleBasic']['kpiId']['kpi_id']['uuid'] = new_policy_kpi_id
    response = context_client.SetPolicyRule(PolicyRule(**POLICYRULE_UPDATED))
    assert response.uuid.uuid == policyrule_uuid

@@ -78,6 +80,7 @@ def test_policy(context_client : ContextClient):
    assert len(response.policyRules) == 1
    assert response.policyRules[0].device.policyRuleBasic.policyRuleId.uuid.uuid == policyrule_uuid
    assert response.policyRules[0].device.policyRuleBasic.priority == new_policy_priority
    assert response.policyRules[0].device.policyRuleBasic.kpiId.kpi_id.uuid == new_policy_priority

    # ----- Remove the object ------------------------------------------------------------------------------------------
    context_client.RemovePolicyRule(PolicyRuleId(**POLICYRULE_ID))