def test_onboard_service_several_resources(mock_create, mock_add_resource,
                                           mock_checkin, mock_submit,
                                           mock_start_certification,
                                           mock_certify, mock_approve,
                                           mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            const.DRAFT, const.DRAFT, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, None
        ]
        resource1 = SdcResource()
        resource2 = SdcResource()
        service = Service(resources=[resource1, resource2])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_not_called()
        calls = [mock.call(resource1), mock.call(resource2)]
        mock_add_resource.assert_has_calls(calls, any_order=True)
        assert mock_add_resource.call_count == 2
        mock_checkin.assert_called_once()
        mock_submit.assert_not_called()
        mock_start_certification.assert_not_called()
        mock_certify.assert_not_called()
        mock_approve.assert_not_called()
        mock_distribute.assert_not_called()
Beispiel #2
0
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_onboard_service_distribute(mock_create, mock_add_resource,
                                    mock_checkin, mock_certify,
                                    mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED,
            const.CERTIFIED, const.CERTIFIED, const.CERTIFIED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, None
        ]
        service = Service()
        service._time_wait = 0
        service.onboard()
        mock_create.assert_not_called()
        mock_add_resource.assert_not_called()
        mock_checkin.assert_not_called()
        mock_certify.assert_not_called()
        mock_distribute.assert_called_once()
def test_onboard_whole_service(mock_create, mock_add_resource, mock_checkin,
                               mock_certify, mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            None, const.DRAFT, const.DRAFT, const.CHECKED_IN, const.CHECKED_IN,
            const.CHECKED_IN, const.CERTIFIED, const.CERTIFIED,
            const.CERTIFIED, const.CERTIFIED, const.CERTIFIED, const.CERTIFIED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, None
        ]
        resource = SdcResource()
        service = Service(resources=[resource])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_called_once()
        mock_add_resource.assert_called_once_with(resource)
        mock_checkin.assert_called_once()
        mock_certify.assert_called_once()
        mock_distribute.assert_called_once()
def test_onboard_service_resources(mock_create, mock_add_resource,
                                   mock_checkin, mock_submit,
                                   mock_start_certification, mock_certify,
                                   mock_approve, mock_distribute):
    getter_mock = mock.Mock(wraps=Service.status.fget)
    mock_status = Service.status.getter(getter_mock)
    with mock.patch.object(Service, 'status', mock_status):
        getter_mock.side_effect = [
            const.DRAFT, const.DRAFT, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, const.DISTRIBUTED,
            const.DISTRIBUTED, const.DISTRIBUTED, None
        ]
        resource = SdcResource()
        service = Service(resources=[resource])
        service._time_wait = 0
        service.onboard()
        mock_create.assert_not_called()
        mock_add_resource.assert_called_once_with(resource)
        mock_checkin.assert_called_once()
        mock_submit.assert_not_called()
        mock_start_certification.assert_not_called()
        mock_certify.assert_not_called()
        mock_approve.assert_not_called()
        mock_distribute.assert_not_called()