예제 #1
0
    def test__manager_user(self, mock_glance_wrap):
        user = mock.Mock()
        glance = resources.GlanceImage(user=user)
        manager = glance._manager()

        mock_glance_wrap.assert_called_once_with(user.glance, glance)
        self.assertEqual(manager, mock_glance_wrap.return_value)
예제 #2
0
    def test_delete(self, mock_glance_image__manager):
        glance = resources.GlanceImage()
        glance.raw_resource = mock.Mock()

        manager = mock_glance_image__manager.return_value
        self.assertEqual(glance.delete(), manager.delete_image.return_value)
        manager.delete_image.assert_called_once_with(glance.raw_resource)
예제 #3
0
    def test_list(self, mock_glance_image__manager):
        glance = resources.GlanceImage()
        glance.tenant_uuid = mock.Mock()

        manager = mock_glance_image__manager.return_value
        self.assertEqual(glance.list(), manager.list_images.return_value)
        manager.list_images.assert_called_once_with(owner=glance.tenant_uuid)
예제 #4
0
    def test__client_user(self, mock_image):
        user = mock.Mock()
        glance = resources.GlanceImage(user=user)
        wrapper = glance._client()

        mock_image.assert_called_once_with(user)
        self.assertEqual(wrapper, mock_image.return_value)
예제 #5
0
    def test__manager_admin(self, mock_glance_wrap):
        admin = mock.Mock()
        glance = resources.GlanceImage(admin=admin)
        manager = glance._manager()

        mock_glance_wrap.assert_called_once_with(admin.glance, glance)
        self.assertEqual(manager, mock_glance_wrap.return_value)
예제 #6
0
    def test__client_admin(self, mock_image):
        admin = mock.Mock()
        glance = resources.GlanceImage(admin=admin)
        client = glance._client()

        mock_image.assert_called_once_with(admin)
        self.assertEqual(client, mock_image.return_value)
예제 #7
0
    def test__wrapper_admin_preferred(self, mock_glance_wrap):
        admin = mock.Mock()
        user = mock.Mock()
        glance = resources.GlanceImage(admin=admin, user=user)
        wrapper = glance._wrapper()

        mock_glance_wrap.assert_called_once_with(admin.glance, glance)
        self.assertEqual(wrapper, mock_glance_wrap.return_value)
예제 #8
0
    def test_list(self):
        glance = resources.GlanceImage()
        glance._wrapper = mock.Mock()
        glance.tenant_uuid = mock.Mock()

        self.assertEqual(glance.list(),
                         glance._wrapper.return_value.list_images.return_value)
        glance._wrapper.return_value.list_images.assert_called_once_with(
            owner=glance.tenant_uuid)
예제 #9
0
    def test_list(self, mock_glance_image__manager):
        glance = resources.GlanceImage()
        glance.tenant_uuid = mock.MagicMock()

        mock_glance_image__manager().list.return_value = ["a", "b", "c"]

        self.assertEqual(["a", "b", "c"], glance.list())
        mock_glance_image__manager().list.assert_called_once_with(
            owner=glance.tenant_uuid)
예제 #10
0
    def test_delete(self):
        glance = resources.GlanceImage()
        glance._wrapper = mock.Mock()
        glance.raw_resource = mock.Mock()

        self.assertEqual(
            glance.delete(),
            glance._wrapper.return_value.delete_image.return_value)
        glance._wrapper.return_value.delete_image.assert_called_once_with(
            glance.raw_resource)
예제 #11
0
    def test_delete(self):
        glance = resources.GlanceImage()
        glance._client = mock.Mock()
        glance._wrapper = mock.Mock()
        glance.raw_resource = mock.Mock()

        client = glance._client.return_value

        deleted_image = mock.Mock(status="DELETED")
        client.get_image.side_effect = [glance.raw_resource, deleted_image]

        glance.delete()
        client.delete_image.assert_called_once_with(glance.raw_resource.id)
예제 #12
0
    def test_list(self):
        glance = resources.GlanceImage()
        glance._client = mock.Mock()
        list_images = glance._client.return_value.list_images
        list_images.side_effect = (["active-image1",
                                    "active-image2"], ["deactivated-image1"])
        glance.tenant_uuid = mock.Mock()

        self.assertEqual(
            glance.list(),
            ["active-image1", "active-image2", "deactivated-image1"])
        list_images.assert_has_calls([
            mock.call(owner=glance.tenant_uuid),
            mock.call(status="deactivated", owner=glance.tenant_uuid)
        ])
예제 #13
0
    def test_is_deleted(self,
                        mock_glance_image__manager,
                        resource=None,
                        exception=None,
                        deleted=True):
        if resource is None:
            resource = mock.Mock()
        manager = mock_glance_image__manager.return_value
        if exception is not None:
            manager.get_image.side_effect = exception
        else:
            manager.get_image.return_value = resource

        glance = resources.GlanceImage(resource=resource)
        self.assertEqual(deleted, glance.is_deleted())
        manager.get_image.assert_called_once_with(resource)