Commit 4de71f91 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Replace wrond HasField() calls for non-message fields
parent b92efe09
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -102,9 +102,10 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link)
    total_capacity_gbps, used_capacity_gbps = None, None
    if request.HasField('attributes'):
        attributes = request.attributes
        if attributes.HasField('total_capacity_gbps'):
        attribute_names = set([field.name for field in attributes._fields])
        if 'total_capacity_gbps' in attribute_names:
            total_capacity_gbps = attributes.total_capacity_gbps
        if attributes.HasField('used_capacity_gbps'):
        if 'used_capacity_gbps' in attribute_names:
            used_capacity_gbps = attributes.used_capacity_gbps
        elif total_capacity_gbps is not None:
            used_capacity_gbps = total_capacity_gbps
+6 −4
Original line number Diff line number Diff line
@@ -96,9 +96,10 @@ def test_link(context_client : ContextClient) -> None:
    assert response.name == LINK_R1_R2_NAME
    assert len(response.link_endpoint_ids) == 2
    assert response.HasField('attributes')
    assert response.attributes.HasField('total_capacity_gbps')
    attribute_names = set([field.name for field in response.attributes._fields])
    assert 'total_capacity_gbps' in attribute_names
    assert abs(response.attributes.total_capacity_gbps - 100) < 1.e-12
    assert response.attributes.HasField('used_capacity_gbps')
    assert 'used_capacity_gbps' in attribute_names
    assert abs(response.attributes.used_capacity_gbps - response.attributes.total_capacity_gbps) < 1.e-12

    # ----- List when the object exists --------------------------------------------------------------------------------
@@ -133,9 +134,10 @@ def test_link(context_client : ContextClient) -> None:
    assert response.name == new_link_name
    assert len(response.link_endpoint_ids) == 2
    assert response.HasField('attributes')
    assert response.attributes.HasField('total_capacity_gbps')
    attribute_names = set([field.name for field in response.attributes._fields])
    assert 'total_capacity_gbps' in attribute_names
    assert abs(response.attributes.total_capacity_gbps - 200) < 1.e-12
    assert response.attributes.HasField('used_capacity_gbps')
    assert 'used_capacity_gbps' in attribute_names
    assert abs(response.attributes.used_capacity_gbps - 50) < 1.e-12

    # ----- List when the object is modified ---------------------------------------------------------------------------