コード例 #1
0
def test_sdc_resource_is_own_property(mock_send_json):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"
    mock_send_json.return_value = PROPERTIES
    prop1 = Property(name="llllll", property_type="integer")
    prop2 = Property(name="test2", property_type="string")
    assert sdc_resource.is_own_property(prop1)
    assert not sdc_resource.is_own_property(prop2)
コード例 #2
0
def test_declare_nested_input(mock_resource_inputs, mock_get_component,
                              mock_send_json):
    sdc_resource = SdcResource()
    sdc_resource.unique_identifier = "toto"
    mock_resource_inputs.return_value = "test"
    sdc_resource.declare_input(
        NestedInput(sdc_resource=mock.MagicMock(), input_obj=mock.MagicMock()))
    mock_get_component.assert_called_once()
    mock_send_json.assert_called_once()
コード例 #3
0
def test_sdc_resource_input_default_value(mock_send_message_json, mock_inputs):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"

    mock_inputs.return_value = [
        Input(unique_id="123",
              input_type="integer",
              name="test",
              sdc_resource=sdc_resource)
    ]
    assert sdc_resource.get_input("test")
    input_obj = sdc_resource.get_input("test")
    assert not input_obj.default_value
    input_obj.default_value = "123"
    mock_send_message_json.assert_called_once()
    assert input_obj.default_value == "123"
コード例 #4
0
def test_add_resource_bad_result(mock_send, mock_load):
    vf = Vf()
    vf.unique_identifier = "45"
    vf.identifier = "93"
    vf.status = const.DRAFT
    mock_send.return_value = {}
    resource = SdcResource()
    resource.unique_identifier = "12"
    resource.created = MagicMock(return_value=True)
    resource.version = "40"
    resource.name = "test"
    assert vf.add_resource(resource) is None
    mock_send.assert_called_once_with(
        'POST',
        'Add SDCRESOURCE to VF',
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources/45/resourceInstance',
        data=
        '{\n  "name": "test",\n  "componentVersion": "40",\n  "posY": 100,\n  "posX": 200,\n  "uniqueId": "12",\n  "originType": "SDCRESOURCE",\n  "componentUid": "12",\n  "icon": "defaulticon"\n}'
    )
コード例 #5
0
def test_add_resource_OK(mock_send, mock_load):
    svc = Service()
    svc.unique_identifier = "45"
    svc.identifier = "93"
    svc.status = const.DRAFT
    mock_send.return_value = {'yes': 'indeed'}
    resource = SdcResource()
    resource.unique_identifier = "12"
    resource.created = MagicMock(return_value=True)
    resource.version = "40"
    resource.name = "test"
    result = svc.add_resource(resource)
    assert result['yes'] == "indeed"
    mock_send.assert_called_once_with(
        'POST',
        'Add SdcResource to service',
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/services/45/resourceInstance',
        data=
        '{\n  "name": "test",\n  "componentVersion": "40",\n  "posY": 100,\n  "posX": 200,\n  "uniqueId": "12",\n  "originType": "SDCRESOURCE",\n  "componentUid": "12",\n  "icon": "defaulticon"\n}'
    )
コード例 #6
0
def test_sdc_resource_set_property_value(mock_send_message_json,
                                         mock_sdc_resource_properties):
    sdc_resource = SdcResource(name="test")
    sdc_resource.unique_identifier = "toto"

    mock_sdc_resource_properties.return_value = [
        Property(name="test",
                 property_type="string",
                 sdc_resource=sdc_resource)
    ]
    with pytest.raises(ValueError):
        sdc_resource.set_property_value(Property(name="test2",
                                                 property_type="integer",
                                                 sdc_resource=sdc_resource),
                                        value="lalala")
    prop = sdc_resource.get_property(property_name="test")
    assert prop.name == "test"
    assert prop.property_type == "string"
    assert not prop.value

    prop.value = "test"
    mock_send_message_json.assert_called_once()
    assert prop.value == "test"