예제 #1
0
def test_service_instance_aai_service_instance():
    customer_mock = mock.MagicMock()
    service_instantiation = ServiceInstantiation(
        name="test",
        request_id="test_request_id",
        instance_id="test_instance_id",
        sdc_service=mock.MagicMock(),
        cloud_region=mock.MagicMock(),
        tenant=mock.MagicMock(),
        customer=customer_mock,
        owning_entity=mock.MagicMock(),
        project=mock.MagicMock())
    status_mock = mock.PropertyMock(
        return_value=ServiceInstantiation.StatusEnum.IN_PROGRESS)
    type(service_instantiation).status = status_mock
    with pytest.raises(StatusError):
        service_instantiation.aai_service_instance

    status_mock.return_value = return_value = ServiceInstantiation.StatusEnum.COMPLETED
    assert service_instantiation.aai_service_instance is not None

    customer_mock.get_service_subscription_by_service_type.side_effect = APIError
    with pytest.raises(APIError) as err:
        service_instantiation.aai_service_instance
    assert err.type == APIError
예제 #2
0
def test_instantiation_wait_for_finish():
    with mock.patch.object(ServiceInstantiation,
                           "finished",
                           new_callable=mock.PropertyMock) as mock_finished:
        with mock.patch.object(
                ServiceInstantiation, "completed",
                new_callable=mock.PropertyMock) as mock_completed:
            instantiation = ServiceInstantiation(
                name="test",
                request_id="test",
                instance_id="test",
                sdc_service=mock.MagicMock(),
                cloud_region=mock.MagicMock(),
                tenant=mock.MagicMock(),
                customer=mock.MagicMock(),
                owning_entity=mock.MagicMock(),
                project=mock.MagicMock())
            instantiation.WAIT_FOR_SLEEP_TIME = 0
            mock_finished.side_effect = [False, False, True]
            mock_completed.return_value = True
            rv = namedtuple("Value", ["return_value"])
            instantiation._wait_for_finish(rv)
            assert rv.return_value