def test_create_already_exists(mock_category, mock_send, mock_exists):
    """Do nothing if already created in SDC."""
    pnf = Pnf()
    vsp = Vsp()
    vsp._identifier = "1232"
    pnf.vsp = vsp
    mock_exists.return_value = True
    pnf.create()
    mock_send.assert_not_called()
def test_create_OK(mock_category, mock_send, mock_exists):
    """Create and update object."""
    pnf = Pnf()
    vsp = Vsp()
    vendor = Vendor()
    vsp._identifier = "1232"
    pnf.vsp = vsp
    vsp.vendor = vendor
    vsp._csar_uuid = "1234"
    expected_data = '{\n    "artifacts": {},\n    "attributes": [],\n    "capabilities": {},\n      "categories": [\n    {\n      "normalizedName": "generic",\n      "name": "Generic",\n      "uniqueId": "resourceNewCategory.generic",\n      "subcategories": [{"empty": false, "groupings": null, "icons": ["objectStorage", "compute"], "name": "Abstract", "normalizedName": "abstract", "ownerId": null, "type": null, "uniqueId": "resourceNewCategory.generic.abstract", "version": null}],\n      "version": null,\n      "ownerId": null,\n      "empty": false,\n      "type": null,\n      "icons": null\n    }\n  ],\n    "componentInstances": [],\n    "componentInstancesAttributes": {},\n    "componentInstancesProperties": {},\n    "componentType": "RESOURCE",\n    "contactId": "cs0008",\n    \n    "csarUUID": "1234",\n    "csarVersion": "1.0",\n    "vendorName": "Generic-Vendor",\n    \n    "deploymentArtifacts": {},\n    "description": "PNF",\n    "icon": "defaulticon",\n    "name": "ONAP-test-PNF",\n    "properties": [],\n    "groups": [],\n    "requirements": {},\n    "resourceType": "PNF",\n    "tags": ["ONAP-test-PNF"],\n    "toscaArtifacts": {},\n    "vendorRelease": "1.0"\n}'
    mock_exists.return_value = False
    mock_send.return_value = {
        'resourceType': 'PNF',
        'name': 'one',
        'uuid': '1234',
        'invariantUUID': '5678',
        'version': '1.0',
        'uniqueId': '91011',
        'lifecycleState': 'NOT_CERTIFIED_CHECKOUT'
    }
    rc = ResourceCategory(name="Generic")
    rc.normalized_name = "generic"
    rc.unique_id = "resourceNewCategory.generic"
    rc.subcategories = [{
        "empty": False,
        "groupings": None,
        "icons": ["objectStorage", "compute"],
        "name": "Abstract",
        "normalizedName": "abstract",
        "ownerId": None,
        "type": None,
        "uniqueId": "resourceNewCategory.generic.abstract",
        "version": None
    }]
    rc.version = None
    rc.owner_id = None
    rc.empty = False
    rc.type = None
    rc.icons = None
    mock_category.return_value = rc
    pnf.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Pnf",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources',
        data=expected_data)
    assert pnf.created()
    assert pnf._status == const.DRAFT
    assert pnf.identifier == "1234"
    assert pnf.unique_uuid == "5678"
    assert pnf.version == "1.0"
def test_create_issue_in_creation(mock_category, mock_send, mock_exists):
    # def test_create_issue_in_creation(mock_send, mock_exists):
    """Do nothing if not created but issue during creation."""
    pnf = Pnf()
    vsp = Vsp()
    vendor = Vendor()
    vsp._identifier = "1232"
    vsp.create_csar = MagicMock(return_value=True)
    vsp.vendor = vendor
    pnf.vsp = vsp
    expected_data = '{\n    "artifacts": {},\n    "attributes": [],\n    "capabilities": {},\n      "categories": [\n    {\n      "normalizedName": "generic",\n      "name": "Generic",\n      "uniqueId": "resourceNewCategory.generic",\n      "subcategories": [{"empty": false, "groupings": null, "icons": ["objectStorage", "compute"], "name": "Abstract", "normalizedName": "abstract", "ownerId": null, "type": null, "uniqueId": "resourceNewCategory.generic.abstract", "version": null}],\n      "version": null,\n      "ownerId": null,\n      "empty": false,\n      "type": null,\n      "icons": null\n    }\n  ],\n    "componentInstances": [],\n    "componentInstancesAttributes": {},\n    "componentInstancesProperties": {},\n    "componentType": "RESOURCE",\n    "contactId": "cs0008",\n    \n    "csarUUID": "None",\n    "csarVersion": "1.0",\n    "vendorName": "Generic-Vendor",\n    \n    "deploymentArtifacts": {},\n    "description": "PNF",\n    "icon": "defaulticon",\n    "name": "ONAP-test-PNF",\n    "properties": [],\n    "groups": [],\n    "requirements": {},\n    "resourceType": "PNF",\n    "tags": ["ONAP-test-PNF"],\n    "toscaArtifacts": {},\n    "vendorRelease": "1.0"\n}'
    mock_exists.return_value = False
    mock_send.side_effect = RequestError
    rc = ResourceCategory(name="Generic")
    rc.normalized_name = "generic"
    rc.unique_id = "resourceNewCategory.generic"
    rc.subcategories = [{
        "empty": False,
        "groupings": None,
        "icons": ["objectStorage", "compute"],
        "name": "Abstract",
        "normalizedName": "abstract",
        "ownerId": None,
        "type": None,
        "uniqueId": "resourceNewCategory.generic.abstract",
        "version": None
    }]
    rc.version = None
    rc.owner_id = None
    rc.empty = False
    rc.type = None
    rc.icons = None
    mock_category.return_value = rc
    with pytest.raises(RequestError) as exc:
        pnf.create()
    mock_send.assert_called_once_with(
        "POST",
        "create Pnf",
        'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/rest/v1/catalog/resources',
        data=expected_data)
    assert not pnf.created()