def test_equality_not_equals(): """Check two Vendors are not equals if name is not the same.""" vendor_1 = Vendor(name="equal") vendor_1.identifier = "1234" vendor_2 = Vendor(name="not_equal") vendor_2.identifier = "1234" assert vendor_1 != vendor_2
def test_equality_really_equals(): """Check two Vendors are equals if name is the same.""" vendor_1 = Vendor(name="equal") vendor_1.identifier = "1234" vendor_2 = Vendor(name="equal") vendor_2.identifier = "1235" assert vendor_1 == vendor_2
def test_exists_exists(mock_get_all): """Return True if vendor exists in SDC.""" vendor_1 = Vendor(name="one") vendor_1.identifier = "1234" mock_get_all.return_value = [vendor_1] vendor = Vendor(name="one") assert vendor.exists()
def test_exists_not_exists(mock_get_all): """Return False if vendor doesn't exist in SDC.""" vendor_1 = Vendor(name="one") vendor_1.identifier = "1234" mock_get_all.return_value = [vendor_1] vendor = Vendor(name="two") assert not vendor.exists()
def test_status_no_load_created(mock_load, mock_created): mock_created.return_value = True vendor = Vendor() vendor.identifier = "12345" vendor._status = "Draft" assert vendor.status == "Draft" mock_load.assert_not_called()
def test_vendor_onboard_unknown(): """Integration tests for Vendor.""" response = requests.post("{}/reset".format(SDC.base_front_url)) response.raise_for_status() vendor = Vendor(name="test") vendor.onboard() assert vendor.status == const.CERTIFIED
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 vendor(self) -> Vendor: """Return and lazy load the vendor.""" if self.created() and not self._vendor: details = self._get_vsp_details() if details: self._vendor = Vendor(name=details['vendorName']) return self._vendor
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_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_submit_already_certified(mock_send, mock_load, mock_exists): """Do nothing if already certified.""" mock_exists.return_value = True vendor = Vendor() vendor._status = const.CERTIFIED vendor.submit() mock_send.assert_not_called()
def test_onboard_whole_vendor(mock_create, mock_submit): getter_mock = mock.Mock(wraps=Vendor.status.fget) mock_status = Vendor.status.getter(getter_mock) with mock.patch.object(Vendor, 'status', mock_status): getter_mock.side_effect = [None, const.DRAFT, const.DRAFT, None] vendor = Vendor() vendor.onboard() mock_submit.assert_called_once() mock_create.assert_called_once()
def test__get_items_version_details(mock_send): vendor = Vendor() vendor.identifier = "1234" vendor._version = "4567" mock_send.return_value = {'return': 'value'} assert vendor._get_item_version_details() == {'return': 'value'} mock_send.assert_called_once_with( 'GET', 'get item version', "{}/items/1234/versions/4567".format(vendor._base_url()))
def test_init_with_name(): """Check init with no names.""" vendor = Vendor(name="YOLO") assert vendor._identifier == None assert vendor._version == None assert vendor.name == "YOLO" assert vendor.headers["USER_ID"] == "cs0008" assert isinstance(vendor._base_url(), str) assert "sdc1/feProxy/onboarding-api/v1.0" in vendor._base_url()
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_create_issue_in_creation(mock_send, mock_exists): """Do nothing if not created but issue during creation.""" vendor = Vendor() expected_data = '{\n "iconRef": "icon",\n "vendorName": "Generic-Vendor",\n "description": "vendor"\n}' mock_exists.return_value = False mock_send.return_value = {} vendor.create() mock_send.assert_called_once_with("POST", "create Vendor", mock.ANY, data=expected_data) assert vendor.created() == False
def test_init_no_name(mock_exists): """Check init with no names.""" mock_exists.return_value = False vendor = Vendor() assert isinstance(vendor, SdcElement) assert vendor._identifier == None assert vendor._version == None assert vendor.name == "Generic-Vendor" assert vendor.created() == False assert vendor.headers["USER_ID"] == "cs0008" assert isinstance(vendor._base_url(), str) assert "sdc1/feProxy/onboarding-api/v1.0" in vendor._base_url()
def test_create_issue_in_creation(mock_send, mock_exists): """Do nothing if not created but issue during creation.""" vsp = Vsp() vendor = Vendor() vendor._identifier = "1232" vsp.vendor = vendor expected_data = '{\n "name": "ONAP-test-VSP",\n "description": "vendor software product",\n "icon": "icon",\n "category": "resourceNewCategory.generic",\n "subCategory": "resourceNewCategory.generic.abstract",\n "vendorName": "Generic-Vendor",\n "vendorId": "1232",\n "licensingData": {},\n "onboardingMethod": "NetworkPackage"\n}' mock_exists.return_value = False mock_send.return_value = {} vsp.create() mock_send.assert_called_once_with("POST", "create Vsp", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products', data=expected_data) assert vsp.created() == False
def test_load_not_created(mock_send, mock_get_all): mock_send.return_value = { 'results': [{ 'status': 'state_one', 'id': "5678" }] } vendor = Vendor(name="one") vendor.load() mock_get_all.return_value = [] mock_send.assert_not_called() assert vendor._status == None assert vendor.version == None assert vendor._identifier == None
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_submit_certified_OK(mock_send, mock_load, mock_exists): """Set status to CERTIFIED if submission OK.""" mock_exists.return_value = True vendor = Vendor() vendor._status = "Draft" vendor._version = "1234" vendor.identifier = "12345" mock_send.return_value = mock.Mock() expected_data = '{\n\n "action": "Submit"\n}' vendor.submit() mock_send.assert_called_once_with( "PUT", "Submit Vendor", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-license-models/12345/versions/1234/actions', data=expected_data) assert vendor.status == const.CERTIFIED
def test_load_created(mock_send, mock_get_all): mock_send.return_value = { 'results': [{ 'status': 'state_one', 'id': "5678" }] } vendor = Vendor(name="one") vendor.identifier = "1234" vendor.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 vendor.status == "state_one" assert vendor.version == "5678"
def test_create_OK(mock_send, mock_exists): """Create and update object.""" vsp = Vsp() vendor = Vendor() vendor._identifier = "1232" vsp.vendor = vendor expected_data = '{\n "name": "ONAP-test-VSP",\n "description": "vendor software product",\n "icon": "icon",\n "category": "resourceNewCategory.generic",\n "subCategory": "resourceNewCategory.generic.abstract",\n "vendorName": "Generic-Vendor",\n "vendorId": "1232",\n "licensingData": {},\n "onboardingMethod": "NetworkPackage"\n}' mock_exists.return_value = False mock_send.return_value = { 'itemId': "1234", 'version': {'id': "5678", 'status': 'state_created'}} vsp.create() mock_send.assert_called_once_with("POST", "create Vsp", 'https://sdc.api.fe.simpledemo.onap.org:30207/sdc1/feProxy/onboarding-api/v1.0/vendor-software-products', data=expected_data) assert vsp.created() == True assert vsp._status == const.DRAFT assert vsp.identifier == "1234" assert vsp.version == "5678"
def import_from_sdc(cls, values: Dict[str, Any]) -> 'Vsp': """ Import Vsp from SDC. Args: values (Dict[str, Any]): dict to parse returned from SDC. Returns: a Vsp instance with right values """ cls._logger.debug("importing VSP %s from SDC", values['name']) vsp = Vsp(values['name']) vsp.identifier = values['id'] vsp.vendor = Vendor(name=values['vendorName']) vsp.load_status() cls._logger.info("status of VSP %s: %s", vsp.name, vsp.status) return vsp
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_create_OK(mock_send, mock_exists): """Create and update object.""" vendor = Vendor() expected_data = '{\n "iconRef": "icon",\n "vendorName": "Generic-Vendor",\n "description": "vendor"\n}' mock_exists.return_value = False mock_send.return_value = { 'itemId': "1234", 'version': { 'id': "5678", 'status': 'state_created' } } vendor.create() mock_send.assert_called_once_with("POST", "create Vendor", mock.ANY, data=expected_data) assert vendor.status == const.DRAFT assert vendor.identifier == "1234" assert vendor.version == "5678"
def test_vf_unknown(): """Integration tests for Vf.""" 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() vf = Vf(name='test') vf.vsp = vsp vf.create() assert vf.identifier is not None assert vf.status == const.DRAFT assert vf.version == "0.1" vf.submit() assert vsp.status == const.CERTIFIED assert vf.version == "1.0" vf.load() assert vsp.status == const.CERTIFIED assert vf.version == "1.0"
def test_vsp_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") vsp.vendor = vendor vsp.create() assert vsp.identifier is not None assert vsp.status == const.DRAFT vsp.upload_package( open( "{}/ubuntu16.zip".format(os.path.dirname( os.path.abspath(__file__))), 'rb')) assert vsp.status == const.UPLOADED vsp.validate() assert vsp.status == const.VALIDATED vsp.commit() assert vsp.status == const.COMMITED vsp.submit() assert vsp.status == const.CERTIFIED vsp.create_csar() assert vsp.csar_uuid is not None
def test__get_items_version_details_no_version(mock_send, mock_load): vendor = Vendor() vendor.identifier = "1234" assert vendor._get_item_version_details() == {} mock_send.assert_not_called()