예제 #1
0
def test_component_property_set_value(mock_component_properties):
    mock_sdc_resource = mock.MagicMock()
    service = Service(name="test")
    service.unique_identifier = "toto"
    component = Component(created_from_csar=False,
                          actual_component_uid="123",
                          unique_id="123",
                          normalized_name="123",
                          name="123",
                          origin_type="123",
                          customization_uuid="123",
                          tosca_component_name="123",
                          component_name="123",
                          component_uid="123",
                          component_version="123",
                          sdc_resource=mock_sdc_resource,
                          parent_sdc_resource=service)
    mock_component_properties.return_value = [
        ComponentProperty(unique_id="123",
                          property_type="string",
                          name="test_property",
                          component=component)
    ]
    with pytest.raises(AttributeError):
        component.get_property(property_name="non_exists")
    prop1 = component.get_property(property_name="test_property")
    assert prop1.name == "test_property"
    assert prop1.unique_id == "123"
    assert prop1.property_type == "string"
    assert not prop1.value

    prop1.value = "123"
    mock_sdc_resource.send_message_json.assert_called_once()
예제 #2
0
    def assign_properties_to_component(
            self, component: Component,
            component_properties: Dict[str, Any]) -> None:
        """Assign properties to component.

        Args:
            component (Component): Component to which properites are going to be assigned
            component_properties (Dict[str, Any]): Properties dictionary

        """
        for property_name, property_value in component_properties.items():
            prop: ComponentProperty = component.get_property(property_name)
            prop.value = property_value