def test_create_csar_not_Certified(mock_send, mock_status, status): """Do nothing if not created.""" vsp = Vsp() vsp._status = status vsp.create_csar() mock_send.assert_not_called() assert vsp.csar_uuid == None
def test__get_vsp_details(mock_send): vsp = Vsp() vsp.identifier = "1234" vsp._version = "4567" mock_send.return_value = {'return': 'value'} assert vsp._get_vsp_details() == {'return': 'value'} mock_send.assert_called_once_with('GET', 'get vsp version', "{}/vendor-software-products/1234/versions/4567".format(vsp._base_url()))
def test_vendor_created_but_already_vendor(mock_created, mock_details): mock_created.return_value = True vsp = Vsp() vendor = Vendor() vsp.vendor = vendor assert vsp.vendor == vendor mock_details.assert_not_called()
def test_status_version_is_not_dirty(mock_vsp_items, mock_vsp_items_version, mock_vsp_details): vsp = Vsp() vsp.identifier = "1234" mock_vsp_items.return_value={'results':[{'status': const.DRAFT}]} mock_vsp_items_version.return_value={"state": {'dirty': False}} mock_vsp_details.return_value={'validationData': "true"} assert vsp.status == const.COMMITED
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_service_unknown(): """Integration tests for Service.""" response = requests.post("{}/reset".format(SDC.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() vsp = Vsp(name="test", package=open("{}/ubuntu16.zip".format( os.path.dirname(os.path.abspath(__file__))), 'rb')) vsp.vendor = vendor vsp.onboard() vf = Vf(name='test', vsp=vsp) vf.onboard() svc = Service(name='test') assert svc.identifier is None assert svc.status is None svc.create() assert svc.identifier is not None assert svc.status == const.DRAFT svc.add_resource(vf) svc.checkin() assert svc.status == const.CHECKED_IN svc.certify() assert svc.status == const.CERTIFIED svc.distribute() assert svc.status == const.DISTRIBUTED assert svc.distributed
def test_onboard_whole_vsp(mock_load, mock_created, mock_create, mock_upload_package, mock_validate, mock_commit, mock_submit, mock_create_csar): getter_mock = mock.Mock(wraps=Vsp.status.fget) mock_status = Vsp.status.getter(getter_mock) with mock.patch.object(Vsp, 'status', mock_status): getter_mock.side_effect = [None, const.DRAFT, const.DRAFT, const.UPLOADED, const.UPLOADED, const.UPLOADED, const.VALIDATED, const.VALIDATED, const.VALIDATED, const.VALIDATED, const.COMMITED, const.COMMITED, const.COMMITED, const.COMMITED, const.COMMITED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, None] vendor = Vendor() vsp = Vsp(vendor=vendor, package="yes") vsp.onboard() mock_create.assert_called_once() mock_upload_package.assert_called_once() mock_validate.assert_called_once() mock_commit.assert_called_once() mock_submit.assert_called_once() mock_create_csar.assert_called_once()
def test__get_item_details_created(mock_send): vsp = Vsp() vsp.identifier = "1234" mock_send.return_value = {'return': 'value'} assert vsp._get_item_details() == {'return': 'value'} mock_send.assert_called_once_with( 'GET', 'get item', "{}/items/1234/versions".format(vsp._base_url()))
def test_status_version_is_dirty_no_validation_data_but_networkPackageName(mock_vsp_items, mock_vsp_items_version, mock_vsp_details): vsp = Vsp() vsp.identifier = "1234" mock_vsp_items.return_value={'results':[{'status': const.DRAFT}]} mock_vsp_items_version.return_value={"state": {'dirty': True}} mock_vsp_details.return_value={'no_validationData': {'some': 'thing'}, 'networkPackageName': 'ubuntu16'} assert vsp.status == const.UPLOADED
def test_status_version_is_dirty_no_validation_data_no_state(mock_vsp_items, mock_vsp_items_version, mock_vsp_details): vsp = Vsp() vsp.identifier = "1234" mock_vsp_items.return_value={'results':[{'status': const.DRAFT}]} mock_vsp_items_version.return_value={"status": {'dirty': False}} mock_vsp_details.return_value={'no_validationData': {'some': 'thing'}} assert vsp.status == const.DRAFT
def test_create_already_exists(mock_send, mock_exists): """Do nothing if already created in SDC.""" vf = Vf() vsp = Vsp() vsp._identifier = "1232" vf.vsp = vsp mock_exists.return_value = True vf.create() mock_send.assert_not_called()
def test_create_already_exists(mock_send, mock_exists): """Do nothing if already created in SDC.""" vsp = Vsp() vendor = Vendor() vendor._identifier = "1232" vsp.vendor = vendor mock_exists.return_value = True vsp.create() mock_send.assert_not_called()
def test_load_created(mock_send, mock_get_all): mock_send.return_value = {'results': [{'status': 'state_one', 'id': "5678", 'vendorName': 'vspOne'}]} vsp = Vsp(name="one") vsp.identifier = "1234" vsp.load() mock_get_all.assert_not_called() mock_send.assert_called_once_with('GET', 'get item', 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items/1234/versions') assert vsp._status == None assert vsp.version == "5678"
def test_load_not_created(mock_send, mock_get_all): mock_send.return_value = {'results': [{'status': 'state_one', 'id': "5678", 'vendorName': 'vspOne'}]} vsp = Vsp(name="one") vsp.load() mock_get_all.return_value = [] mock_send.assert_not_called() assert vsp._status == None assert vsp.version == None assert vsp.identifier == None
def test_init_with_name(mock_exists): """Check init with no names.""" vsp = Vsp(name="YOLO") mock_exists.return_value = False assert vsp._identifier == None assert vsp._version == None assert vsp.name == "YOLO" assert vsp.created() == False assert vsp.headers["USER_ID"] == "cs0008" assert vsp.vendor == None assert isinstance(vsp._base_url(), str) assert "sdc1/feProxy/onboarding-api/v1.0" in vsp._base_url()
def test_init_no_name(mock_created): """Check init with no names.""" mock_created.return_value = False vsp = Vsp() assert isinstance(vsp, SdcElement) assert vsp._identifier == None assert vsp._version == None assert vsp.name == "ONAP-test-VSP" assert vsp.headers["USER_ID"] == "cs0008" assert vsp.vendor == None assert isinstance(vsp._base_url(), str) assert "sdc1/feProxy/onboarding-api/v1.0" in vsp._base_url()
def test_vsp_onboard_unknown(): """Integration tests for Vsp.""" response = requests.post("{}/reset".format(Vendor.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() vsp = Vsp(name="test", package=open( "{}/ubuntu16.zip".format( os.path.dirname(os.path.abspath(__file__))), 'rb')) vsp.vendor = vendor vsp.onboard() assert vsp.status == const.CERTIFIED assert vsp.csar_uuid is not None
def test_service_onboard_unknown(): """Integration tests for Service.""" response = requests.post("{}/reset".format(SDC.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() vsp = Vsp(name="test", package=open("{}/ubuntu16.zip".format( os.path.dirname(os.path.abspath(__file__))), 'rb')) vsp.vendor = vendor vsp.onboard() vf = Vf(name='test', vsp=vsp) vf.onboard() svc = Service(name='test', resources=[vf]) svc.onboard() assert svc.distributed
def test_get_all_no_vsp(mock_send): """Returns empty array if no vsps.""" mock_send.return_value = {} assert Vsp.get_all() == [] mock_send.assert_called_once_with( "GET", 'get Vsps', 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products')
def test_onboard_new_vsp_validate(mock_create, mock_upload_package, mock_validate, mock_commit, mock_submit, mock_create_csar): getter_mock = mock.Mock(wraps=Vsp.status.fget) mock_status = Vsp.status.getter(getter_mock) with mock.patch.object(Vsp, 'status', mock_status): getter_mock.side_effect = [const.UPLOADED, const.UPLOADED, const.UPLOADED, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, None] vsp = Vsp() vsp.onboard() mock_create.assert_not_called() mock_upload_package.assert_not_called() mock_validate.assert_called_once() mock_commit.assert_not_called() mock_submit.assert_not_called() mock_create_csar.assert_not_called()
def test_onboard_vsp_upload_no_files(mock_create, mock_upload_package, mock_validate, mock_commit, mock_submit, mock_create_csar): getter_mock = mock.Mock(wraps=Vsp.status.fget) mock_status = Vsp.status.getter(getter_mock) with mock.patch.object(Vsp, 'status', mock_status): getter_mock.side_effect = [const.DRAFT, const.DRAFT, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, None] vsp = Vsp() with pytest.raises(ValueError): vsp.onboard() mock_create.assert_not_called() mock_upload_package.assert_not_called() mock_validate.assert_not_called() mock_commit.assert_not_called() mock_submit.assert_not_called() mock_create_csar.assert_not_called()
def test_get_all_some_vsps(mock_send, mock_load_status): """Returns a list of vsp.""" mock_send.return_value = {'results':[ {'name': 'one', 'id': '1234', 'vendorName': 'vspOne'}, {'name': 'two', 'id': '1235', 'vendorName': 'vspOne'}]} assert len(Vsp.get_all()) == 2 vsp_1 = Vsp.get_all()[0] assert vsp_1.name == "one" assert vsp_1.identifier == "1234" assert vsp_1.created() vsp_2 = Vsp.get_all()[1] assert vsp_2.name == "two" assert vsp_2.identifier == "1235" assert vsp_2.vendor == vsp_1.vendor assert vsp_2.created() mock_send.assert_called_with( "GET", 'get Vsps', 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products')
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()
def test_onboard_new_vsp(mock_created, mock_create, mock_upload_package, mock_validate, mock_commit, mock_submit, mock_create_csar): mock_created.return_value = False getter_mock = mock.Mock(wraps=Vsp.status.fget) mock_status = Vsp.status.getter(getter_mock) with mock.patch.object(Vsp, 'status', mock_status): getter_mock.side_effect = [None, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, const.APPROVED, None] vendor = Vendor() vsp = Vsp(vendor=vendor) vsp.onboard() mock_create.assert_called_once() mock_upload_package.assert_not_called() mock_validate.assert_not_called() mock_commit.assert_not_called() mock_submit.assert_not_called() mock_create_csar.assert_not_called()
def test_submit_OK(mock_send, mock_status): """Don't update status if submission NOK.""" vsp = Vsp() vsp._status = const.COMMITED expected_data = '{\n\n "action": "Submit"\n}' vsp._version = "1234" vsp._identifier = "12345" vsp.submit() mock_send.assert_called_once_with("PUT", "Submit Vsp", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products/12345/versions/1234/actions', data=expected_data)
def test_commit_OK(mock_send, mock_status): """Don't update status if submission NOK.""" vsp = Vsp() vsp._status = const.VALIDATED expected_data = '{\n\n "commitRequest":{"message":"ok"},\n\n "action": "Commit"\n}' vsp._version = "1234" vsp._identifier = "12345" vsp.commit() mock_send.assert_called_once_with("PUT", "Commit Vsp", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/items/12345/versions/1234/actions', data=expected_data)
def test_validate_OK(mock_send, mock_status): """Don't update status if submission NOK.""" vsp = Vsp() vsp._status = const.UPLOADED mock_send.return_value = {'status': 'Success'} vsp._version = "1234" vsp._identifier = "12345" vsp.validate() mock_send.assert_called_once_with('PUT', 'Validate artifacts for Vsp', 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products/12345/versions/1234/orchestration-template-candidate/process')
def test_upload_OK(mock_send, mock_status): """Don't update status if submission NOK.""" vsp = Vsp() vsp._status = const.DRAFT mock_send.return_value = True expected_data = '{\n\n "action": "Create_Package"\n}' vsp._version = "1234" vsp._identifier = "12345" vsp.upload_package('data') mock_send.assert_called_once_with('POST', 'upload ZIP for Vsp', "https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products/12345/versions/1234/orchestration-template-candidate", files={'upload': 'data'}, headers={'Accept': 'application/json', 'USER_ID': 'cs0008', 'Authorization': 'Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=', 'X-ECOMP-InstanceID': 'onapsdk', 'Accept-Encoding': 'gzip, deflate'})
def test_equality_not_equals(): """Check two vsps are not equals if name is not the same.""" vsp_1 = Vsp(name="equal") vsp_1.identifier = "1234" vsp_2 = Vsp(name="not_equal") vsp_2.identifier = "1234" assert vsp_1 != vsp_2
def test_exists_not_exists(mock_get_all): """Return False if vsp doesn't exist in SDC.""" vsp_1 = Vsp(name="one") vsp_1.identifier = "1234" mock_get_all.return_value = [vsp_1] vsp = Vsp(name="two") assert not vsp.exists()