def test_delete_external_resource(self):
        fake_ctx = self.generate_node_context(
            properties={'use_external_resource': True})
        fake_client = self.generate_client()
        with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                        mock.MagicMock(return_value=fake_client)):
            server.delete(ctx=fake_ctx)

        self.assertFalse(
            server.VCLOUD_VAPP_NAME in fake_ctx.instance.runtime_properties)
    def test_delete_external_resource(self):
        fake_ctx = self.generate_node_context(
            properties={
                'use_external_resource': True
            }
        )
        fake_client = self.generate_client()
        with mock.patch(
            'vcloud_plugin_common.VcloudAirClient.get',
            mock.MagicMock(return_value=fake_client)
        ):
            server.delete(ctx=fake_ctx)

        self.assertFalse(
            server.VCLOUD_VAPP_NAME in fake_ctx.instance.runtime_properties
        )
    def test_delete(self):
        fake_ctx = self.generate_node_context()
        fake_client = self.generate_client()
        with mock.patch('vcloud_plugin_common.VcloudAirClient.get',
                        mock.MagicMock(return_value=fake_client)):
            # no result from delete
            fake_client._vapp.delete = mock.MagicMock(return_value=None)
            with self.assertRaises(cfy_exc.NonRecoverableError):
                server.delete(ctx=fake_ctx)
            fake_client._vapp.delete.assert_called_with()
            self.check_get_vapp(fake_client, 'vapp_name')

            # error
            fake_task = self.generate_task(
                vcloud_plugin_common.TASK_STATUS_ERROR)
            fake_client._vapp.delete = mock.MagicMock(return_value=fake_task)
            with self.assertRaises(cfy_exc.NonRecoverableError):
                server.delete(ctx=fake_ctx)

            # success
            fake_task = self.generate_task(
                vcloud_plugin_common.TASK_STATUS_SUCCESS)
            fake_client._vapp.delete = mock.MagicMock(return_value=fake_task)
            server.delete(ctx=fake_ctx)
            self.assertFalse(server.VCLOUD_VAPP_NAME in
                             fake_ctx.instance.runtime_properties)
    def test_delete(self):
        fake_ctx = self.generate_node_context()
        fake_client = self.generate_client()
        with mock.patch(
            'vcloud_plugin_common.VcloudAirClient.get',
            mock.MagicMock(return_value=fake_client)
        ):
            # no result from delete
            fake_client._vapp.delete = mock.MagicMock(
                return_value=None
            )
            with self.assertRaises(cfy_exc.NonRecoverableError):
                server.delete(ctx=fake_ctx)
            fake_client._vapp.delete.assert_called_with()
            self.check_get_vapp(fake_client, 'vapp_name')

            # error
            fake_task = self.generate_task(
                vcloud_plugin_common.TASK_STATUS_ERROR
            )
            fake_client._vapp.delete = mock.MagicMock(
                return_value=fake_task
            )
            with self.assertRaises(cfy_exc.NonRecoverableError):
                server.delete(ctx=fake_ctx)

            # success
            fake_task = self.generate_task(
                vcloud_plugin_common.TASK_STATUS_SUCCESS
            )
            fake_client._vapp.delete = mock.MagicMock(
                return_value=fake_task
            )
            server.delete(ctx=fake_ctx)
            self.assertFalse(
                server.VCLOUD_VAPP_NAME in fake_ctx.instance.runtime_properties
            )