def test_create_OK(mock_send, mock_exists): """Create and update object.""" vf = Vf() vsp = Vsp() vendor = Vendor() vsp._identifier = "1232" vf.vsp = vsp vsp.vendor = vendor vsp._csar_uuid = "1234" expected_data = '{\n "artifacts": {},\n "attributes": [],\n "capabilities": {},\n "categories":[\n {\n "name": "Generic",\n "normalizedName": "generic",\n "uniqueId": "resourceNewCategory.generic",\n "icons": null,\n "subcategories":[\n {\n "name": "Abstract",\n "normalizedName": "abstract",\n "uniqueId": "resourceNewCategory.generic.abstract",\n "icons":[\n "objectStorage",\n "compute"\n ],\n "groupings": null,\n "ownerId": null,\n "empty": false\n }\n ],\n "ownerId": null,\n "empty": false\n }\n ],\n "componentInstances": [],\n "componentInstancesAttributes": {},\n "componentInstancesProperties": {},\n "componentType": "RESOURCE",\n "contactId": "cs0008",\n "csarUUID": "1234",\n "csarVersion": "1.0",\n "deploymentArtifacts": {},\n "description": "VF",\n "icon": "defaulticon",\n "name": "ONAP-test-VF",\n "properties": [],\n "groups": [],\n "requirements": {},\n "resourceType": "VF",\n "tags": ["ONAP-test-VF"],\n "toscaArtifacts": {},\n "vendorName": "Generic-Vendor",\n "vendorRelease": "1.0"\n}' mock_exists.return_value = False mock_send.return_value = { 'resourceType': 'VF', 'name': 'one', 'uuid': '1234', 'invariantUUID': '5678', 'version': '1.0', 'uniqueId': '91011', 'lifecycleState': 'NOT_CERTIFIED_CHECKOUT' } vf.create() mock_send.assert_called_once_with( "POST", "create Vf", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources', data=expected_data) assert vf.created() assert vf._status == const.DRAFT assert vf.identifier == "1234" assert vf.unique_uuid == "5678" assert vf.version == "1.0"
def test_init_with_name(mock_exists): """Check init with no names.""" mock_exists.return_value = False vf = Vf(name="YOLO") assert vf._identifier == None assert vf._version == None assert vf.name == "YOLO" assert vf.created() == False assert vf.headers["USER_ID"] == "cs0008" assert vf.vsp == None assert isinstance(vf._base_url(), str)
def test_create_issue_in_creation(mock_send, mock_exists): """Do nothing if not created but issue during creation.""" vf = Vf() vsp = Vsp() vendor = Vendor() vsp._identifier = "1232" vsp.create_csar = MagicMock(return_value=True) vsp.vendor = vendor vf.vsp = vsp expected_data = '{\n "artifacts": {},\n "attributes": [],\n "capabilities": {},\n "categories":[\n {\n "name": "Generic",\n "normalizedName": "generic",\n "uniqueId": "resourceNewCategory.generic",\n "icons": null,\n "subcategories":[\n {\n "name": "Abstract",\n "normalizedName": "abstract",\n "uniqueId": "resourceNewCategory.generic.abstract",\n "icons":[\n "objectStorage",\n "compute"\n ],\n "groupings": null,\n "ownerId": null,\n "empty": false\n }\n ],\n "ownerId": null,\n "empty": false\n }\n ],\n "componentInstances": [],\n "componentInstancesAttributes": {},\n "componentInstancesProperties": {},\n "componentType": "RESOURCE",\n "contactId": "cs0008",\n "csarUUID": "None",\n "csarVersion": "1.0",\n "deploymentArtifacts": {},\n "description": "VF",\n "icon": "defaulticon",\n "name": "ONAP-test-VF",\n "properties": [],\n "groups": [],\n "requirements": {},\n "resourceType": "VF",\n "tags": ["ONAP-test-VF"],\n "toscaArtifacts": {},\n "vendorName": "Generic-Vendor",\n "vendorRelease": "1.0"\n}' mock_exists.return_value = False mock_send.return_value = {} vf.create() mock_send.assert_called_once_with( "POST", "create Vf", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources', data=expected_data) assert not vf.created()