Add test for glanceclient shells
Add unittests for the following modules: * glanceclient.shell * glanceclient.v1.shell * glanceclient.v1.legacy_shell * glanceclient.v2.shell Also add mock library to the tools/test-requires Implements: blueprint glanceclient-shells-unittests Change-Id: I5ec527c5efff3726932d234d7c67e08149643f89
This commit is contained in:
		
							
								
								
									
										84
									
								
								tests/test_shell.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								tests/test_shell.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,84 @@
 | 
			
		||||
# Copyright 2013 OpenStack LLC.
 | 
			
		||||
# Copyright (C) 2013 Yahoo! Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
			
		||||
 | 
			
		||||
import argparse
 | 
			
		||||
import cStringIO
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
from glanceclient import exc
 | 
			
		||||
from glanceclient import shell as openstack_shell
 | 
			
		||||
from tests import utils
 | 
			
		||||
 | 
			
		||||
DEFAULT_IMAGE_URL = 'http://127.0.0.1:5000/'
 | 
			
		||||
DEFAULT_USERNAME = 'username'
 | 
			
		||||
DEFAULT_PASSWORD = 'password'
 | 
			
		||||
DEFAULT_TENANT_ID = 'tenant_id'
 | 
			
		||||
DEFAULT_TENANT_NAME = 'tenant_name'
 | 
			
		||||
DEFAULT_AUTH_URL = 'http://127.0.0.1:5000/v2.0/'
 | 
			
		||||
DEFAULT_AUTH_TOKEN = ' 3bcc3d3a03f44e3d8377f9247b0ad155'
 | 
			
		||||
TEST_SERVICE_URL = 'http://127.0.0.1:5000/'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ShellTest(utils.TestCase):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(ShellTest, self).setUp()
 | 
			
		||||
        global _old_env
 | 
			
		||||
        fake_env = {
 | 
			
		||||
            'OS_USERNAME': DEFAULT_USERNAME,
 | 
			
		||||
            'OS_PASSWORD': DEFAULT_PASSWORD,
 | 
			
		||||
            'OS_TENANT_NAME': DEFAULT_TENANT_NAME,
 | 
			
		||||
            'OS_AUTH_URL': DEFAULT_AUTH_URL,
 | 
			
		||||
            'OS_IMAGE_URL': DEFAULT_IMAGE_URL,
 | 
			
		||||
            'OS_AUTH_TOKEN': DEFAULT_AUTH_TOKEN}
 | 
			
		||||
        _old_env, os.environ = os.environ, fake_env.copy()
 | 
			
		||||
 | 
			
		||||
        global shell, _shell, assert_called, assert_called_anytime
 | 
			
		||||
        _shell = openstack_shell.OpenStackImagesShell()
 | 
			
		||||
        shell = lambda cmd: _shell.main(cmd.split())
 | 
			
		||||
 | 
			
		||||
    def tearDown(self):
 | 
			
		||||
        super(ShellTest, self).tearDown()
 | 
			
		||||
        global _old_env
 | 
			
		||||
        os.environ = _old_env
 | 
			
		||||
 | 
			
		||||
    def test_help_unknown_command(self):
 | 
			
		||||
        shell = openstack_shell.OpenStackImagesShell()
 | 
			
		||||
        argstr = 'help foofoo'
 | 
			
		||||
        self.assertRaises(exc.CommandError, shell.main, argstr.split())
 | 
			
		||||
 | 
			
		||||
    def test_help(self):
 | 
			
		||||
        shell = openstack_shell.OpenStackImagesShell()
 | 
			
		||||
        argstr = 'help'
 | 
			
		||||
        actual = shell.main(argstr.split())
 | 
			
		||||
        self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_help_on_subcommand_error(self):
 | 
			
		||||
        self.assertRaises(exc.CommandError, shell, 'help bad')
 | 
			
		||||
 | 
			
		||||
    def test_get_base_parser(self):
 | 
			
		||||
        test_shell = openstack_shell.OpenStackImagesShell()
 | 
			
		||||
        actual_parser = test_shell.get_base_parser()
 | 
			
		||||
        description = 'Command-line interface to the OpenStack Images API.'
 | 
			
		||||
        expected = argparse.ArgumentParser(
 | 
			
		||||
            prog='glance', usage=None,
 | 
			
		||||
            description=description,
 | 
			
		||||
            version=None,
 | 
			
		||||
            conflict_handler='error',
 | 
			
		||||
            add_help=False,
 | 
			
		||||
            formatter_class=openstack_shell.HelpFormatter,)
 | 
			
		||||
        self.assertTrue(expected, actual_parser)
 | 
			
		||||
@@ -14,7 +14,9 @@
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import copy
 | 
			
		||||
import requests
 | 
			
		||||
import StringIO
 | 
			
		||||
import testtools
 | 
			
		||||
 | 
			
		||||
from glanceclient.common import http
 | 
			
		||||
 | 
			
		||||
@@ -63,3 +65,33 @@ class FakeResponse(object):
 | 
			
		||||
 | 
			
		||||
    def read(self, amt):
 | 
			
		||||
        return self.body.read(amt)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestCase(testtools.TestCase):
 | 
			
		||||
    TEST_REQUEST_BASE = {
 | 
			
		||||
        'config': {'danger_mode': False},
 | 
			
		||||
        'verify': True}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestResponse(requests.Response):
 | 
			
		||||
    """
 | 
			
		||||
    Class used to wrap requests.Response and provide some
 | 
			
		||||
    convenience to initialize with a dict
 | 
			
		||||
    """
 | 
			
		||||
    def __init__(self, data):
 | 
			
		||||
        self._text = None
 | 
			
		||||
        super(TestResponse, self)
 | 
			
		||||
        if isinstance(data, dict):
 | 
			
		||||
            self.status_code = data.get('status_code', None)
 | 
			
		||||
            self.headers = data.get('headers', None)
 | 
			
		||||
            # Fake the text attribute to streamline Response creation
 | 
			
		||||
            self._text = data.get('text', None)
 | 
			
		||||
        else:
 | 
			
		||||
            self.status_code = data
 | 
			
		||||
 | 
			
		||||
    def __eq__(self, other):
 | 
			
		||||
        return self.__dict__ == other.__dict__
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def text(self):
 | 
			
		||||
        return self._text
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										585
									
								
								tests/v1/test_legacy_shell.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										585
									
								
								tests/v1/test_legacy_shell.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,585 @@
 | 
			
		||||
# Copyright 2013 OpenStack LLC.
 | 
			
		||||
# Copyright (C) 2013 Yahoo! Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
			
		||||
 | 
			
		||||
import mock
 | 
			
		||||
import testtools
 | 
			
		||||
 | 
			
		||||
from glanceclient import client
 | 
			
		||||
from glanceclient import exc
 | 
			
		||||
from glanceclient.v1 import legacy_shell as test_shell
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LegacyShellV1Test(testtools.TestCase):
 | 
			
		||||
    def test_print_image_formatted(self):
 | 
			
		||||
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            endpoint = 'http://no.where'
 | 
			
		||||
 | 
			
		||||
        class FakeImage():
 | 
			
		||||
            id = 1
 | 
			
		||||
            name = 'fake_image'
 | 
			
		||||
            is_public = False
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            size = '1024'
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 10
 | 
			
		||||
            properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
            created_at = '04.03.2013'
 | 
			
		||||
            owner = 'test'
 | 
			
		||||
            updated_at = '04.03.2013'
 | 
			
		||||
            deleted_at = '04.03.2013'
 | 
			
		||||
 | 
			
		||||
        test_shell.print_image_formatted(FakeClient(), FakeImage())
 | 
			
		||||
 | 
			
		||||
    def test_print_image(self):
 | 
			
		||||
        class FakeImage():
 | 
			
		||||
            id = 1
 | 
			
		||||
            name = 'fake_image'
 | 
			
		||||
            is_public = False
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            size = '1024'
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 10
 | 
			
		||||
            properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
            created_at = '04.03.2013'
 | 
			
		||||
            owner = 'test'
 | 
			
		||||
            updated_at = '04.03.2013'
 | 
			
		||||
            deleted_at = '04.03.2013'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where:8080')
 | 
			
		||||
        test_shell.print_image_formatted(gc, FakeImage())
 | 
			
		||||
 | 
			
		||||
    def test_get_image_fields_from_args(self):
 | 
			
		||||
        args = ["field=name"]
 | 
			
		||||
        actual = test_shell.get_image_fields_from_args(args)
 | 
			
		||||
        self.assertEqual({'field': 'name'}, actual)
 | 
			
		||||
 | 
			
		||||
    def test_get_image_fields_from_args_exception_raises(self):
 | 
			
		||||
        args = {"filed": "name"}
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            RuntimeError, test_shell.get_image_fields_from_args, args)
 | 
			
		||||
 | 
			
		||||
    def test_get_filters_from_args(self):
 | 
			
		||||
        args = ["filter=name"]
 | 
			
		||||
        actual = test_shell.get_image_filters_from_args(args)
 | 
			
		||||
        self.assertEqual({'property-filter': 'name'}, actual)
 | 
			
		||||
 | 
			
		||||
    def test_get_image_filters_from_args_exception_raises(self):
 | 
			
		||||
        args = {"filter": "name"}
 | 
			
		||||
        actual = test_shell.get_image_filters_from_args(args)
 | 
			
		||||
        self.assertEqual(1, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_add_error(self):
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            endpoint = 'http://no.where'
 | 
			
		||||
 | 
			
		||||
        class args:
 | 
			
		||||
            fields = 'name'
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_add(FakeClient(), args)
 | 
			
		||||
        self.assertEqual(1, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_add(self):
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        class FakeImage():
 | 
			
		||||
            fields = ['name=test',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'id=test',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'protected=False',
 | 
			
		||||
                      'min_disk=10',
 | 
			
		||||
                      'container_format=ovi',
 | 
			
		||||
                      'status=active']
 | 
			
		||||
            dry_run = True
 | 
			
		||||
 | 
			
		||||
        test_args = FakeImage()
 | 
			
		||||
        actual = test_shell.do_add(gc, test_args)
 | 
			
		||||
        self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_add_with_image_meta(self):
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        class FakeImage():
 | 
			
		||||
            fields = ['name=test',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'id=test',
 | 
			
		||||
                      'protected=False',
 | 
			
		||||
                      'min_disk=10',
 | 
			
		||||
                      'container_format=ovi',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'size=256',
 | 
			
		||||
                      'location=test',
 | 
			
		||||
                      'checksum=1024',
 | 
			
		||||
                      'owner=test_user']
 | 
			
		||||
            dry_run = True
 | 
			
		||||
 | 
			
		||||
        test_args = FakeImage()
 | 
			
		||||
        actual = test_shell.do_add(gc, test_args)
 | 
			
		||||
        self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_add_without_dry_run(self):
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        class FakeImage():
 | 
			
		||||
            fields = ['name=test',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'id=test',
 | 
			
		||||
                      'protected=False',
 | 
			
		||||
                      'min_disk=10',
 | 
			
		||||
                      'container_format=ovi',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'size=256',
 | 
			
		||||
                      'location=test',
 | 
			
		||||
                      'checksum=1024',
 | 
			
		||||
                      'owner=test_user']
 | 
			
		||||
            dry_run = False
 | 
			
		||||
            id = 'test'
 | 
			
		||||
            verbose = False
 | 
			
		||||
 | 
			
		||||
        test_args = FakeImage()
 | 
			
		||||
        with mock.patch.object(gc.images, 'create') as mocked_create:
 | 
			
		||||
            mocked_create.return_value = FakeImage()
 | 
			
		||||
            actual = test_shell.do_add(gc, test_args)
 | 
			
		||||
            self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_clear_force_true_error(self):
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            id = 1
 | 
			
		||||
            name = 'fake_image'
 | 
			
		||||
            is_public = False
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            size = '1024'
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 10
 | 
			
		||||
            properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
            created_at = '04.03.2013'
 | 
			
		||||
            owner = 'test'
 | 
			
		||||
            updated_at = '04.03.2013'
 | 
			
		||||
            deleted_at = '04.03.2013'
 | 
			
		||||
            force = True
 | 
			
		||||
            verbose = True
 | 
			
		||||
 | 
			
		||||
        class FakeImages():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.id = 'test'
 | 
			
		||||
                self.name = 'test_image_name'
 | 
			
		||||
 | 
			
		||||
            def list(self):
 | 
			
		||||
                self.list = [FakeImage1(), FakeImage1()]
 | 
			
		||||
                return self.list
 | 
			
		||||
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.images = FakeImages()
 | 
			
		||||
 | 
			
		||||
        test_args = FakeImage1()
 | 
			
		||||
        actual = test_shell.do_clear(FakeClient(), test_args)
 | 
			
		||||
        self.assertEqual(1, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_clear_force_true(self):
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.id = 1
 | 
			
		||||
                self.name = 'fake_image'
 | 
			
		||||
                self.is_public = False
 | 
			
		||||
                self.protected = False
 | 
			
		||||
                self.status = 'active'
 | 
			
		||||
                self.size = '1024'
 | 
			
		||||
                self.min_ram = 512
 | 
			
		||||
                self.min_disk = 10
 | 
			
		||||
                self.properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
                self.created_at = '04.03.2013'
 | 
			
		||||
                self.owner = 'test'
 | 
			
		||||
                self.updated_at = '04.03.2013'
 | 
			
		||||
                self.deleted_at = '04.03.2013'
 | 
			
		||||
                self.force = True
 | 
			
		||||
                self.verbose = True
 | 
			
		||||
 | 
			
		||||
            def delete(self):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
        class FakeImages():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.id = 'test'
 | 
			
		||||
                self.name = 'test_image_name'
 | 
			
		||||
 | 
			
		||||
            def list(self):
 | 
			
		||||
                self.list = [FakeImage1(), FakeImage1()]
 | 
			
		||||
                return self.list
 | 
			
		||||
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.images = FakeImages()
 | 
			
		||||
 | 
			
		||||
        test_args = FakeImage1()
 | 
			
		||||
        actual = test_shell.do_clear(FakeClient(), test_args)
 | 
			
		||||
        self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_update_error(self):
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            endpoint = 'http://no.where'
 | 
			
		||||
 | 
			
		||||
        class Image():
 | 
			
		||||
            fields = ['id', 'is_public', 'name']
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        fake_client = FakeClient()
 | 
			
		||||
        actual = test_shell.do_update(fake_client, args)
 | 
			
		||||
        self.assertEqual(1, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_update_invalid_endpoint(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            fields = ['id=test_updated', 'is_public=True', 'name=new_name']
 | 
			
		||||
            dry_run = False
 | 
			
		||||
            id = 'test'
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint, test_shell.do_update, gc, args)
 | 
			
		||||
 | 
			
		||||
    def test_do_update(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            fields = ['id=test_updated',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'name=new_name',
 | 
			
		||||
                      'protected=False']
 | 
			
		||||
            dry_run = True
 | 
			
		||||
            id = 'test'
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        actual = test_shell.do_update(gc, args)
 | 
			
		||||
        self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_update_dry_run_false(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            fields = ['id=test_updated',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'name=new_name',
 | 
			
		||||
                      'protected=False',
 | 
			
		||||
                      'is_public=True']
 | 
			
		||||
            dry_run = False
 | 
			
		||||
            id = 'test'
 | 
			
		||||
            verbose = True
 | 
			
		||||
            is_public = True
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            size = 1024
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 512
 | 
			
		||||
            properties = {'property': 'test'}
 | 
			
		||||
            created_at = '12.09.2013'
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'update') as mocked_update:
 | 
			
		||||
            mocked_update.return_value = Image()
 | 
			
		||||
            actual = test_shell.do_update(gc, args)
 | 
			
		||||
            self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_delete(self):
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.id = 1
 | 
			
		||||
                self.name = 'fake_image'
 | 
			
		||||
                self.is_public = False
 | 
			
		||||
                self.protected = False
 | 
			
		||||
                self.status = 'active'
 | 
			
		||||
                self.size = '1024'
 | 
			
		||||
                self.min_ram = 512
 | 
			
		||||
                self.min_disk = 10
 | 
			
		||||
                self.properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
                self.created_at = '04.03.2013'
 | 
			
		||||
                self.owner = 'test'
 | 
			
		||||
                self.updated_at = '04.03.2013'
 | 
			
		||||
                self.deleted_at = '04.03.2013'
 | 
			
		||||
                self.force = True
 | 
			
		||||
                self.verbose = True
 | 
			
		||||
 | 
			
		||||
            def delete(self):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            def get(self, id):
 | 
			
		||||
                return FakeImage1()
 | 
			
		||||
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.images = FakeImage1()
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_delete(FakeClient(), FakeImage1())
 | 
			
		||||
 | 
			
		||||
    def test_show(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            fields = ['id=test_updated',
 | 
			
		||||
                      'status=active',
 | 
			
		||||
                      'is_public=True',
 | 
			
		||||
                      'name=new_name',
 | 
			
		||||
                      'protected=False']
 | 
			
		||||
            id = 'test_show'
 | 
			
		||||
            name = 'fake_image'
 | 
			
		||||
            is_public = False
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            size = '1024'
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 10
 | 
			
		||||
            properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
            created_at = '04.03.2013'
 | 
			
		||||
            owner = 'test'
 | 
			
		||||
            updated_at = '04.03.2013'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'get') as mocked_get:
 | 
			
		||||
            mocked_get.return_value = Image()
 | 
			
		||||
            actual = test_shell.do_show(gc, Image())
 | 
			
		||||
            self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_index(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            id = 'test'
 | 
			
		||||
            filters = {}
 | 
			
		||||
            limit = 18
 | 
			
		||||
            marker = False
 | 
			
		||||
            sort_key = 'test'
 | 
			
		||||
            kwarg = 'name'
 | 
			
		||||
            sort_dir = 'test'
 | 
			
		||||
            name = 'test'
 | 
			
		||||
            disk_format = 'ovi'
 | 
			
		||||
            container_format = 'ovi'
 | 
			
		||||
            size = 1024
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'list') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = [Image(), Image()]
 | 
			
		||||
            actual = test_shell.do_index(gc, args)
 | 
			
		||||
 | 
			
		||||
    def test_index_return_empty(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            id = 'test'
 | 
			
		||||
            filters = {}
 | 
			
		||||
            limit = 18
 | 
			
		||||
            marker = False
 | 
			
		||||
            sort_key = 'test'
 | 
			
		||||
            kwarg = 'name'
 | 
			
		||||
            sort_dir = 'test'
 | 
			
		||||
            name = 'test'
 | 
			
		||||
            disk_format = 'ovi'
 | 
			
		||||
            container_format = 'ovi'
 | 
			
		||||
            size = 1024
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(test_shell, '_get_images') as mocked_get:
 | 
			
		||||
            mocked_get.return_value = False
 | 
			
		||||
            actual = test_shell.do_index(gc, args)
 | 
			
		||||
            self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_details(self):
 | 
			
		||||
        class Image():
 | 
			
		||||
            id = 'test'
 | 
			
		||||
            filters = {}
 | 
			
		||||
            limit = 18
 | 
			
		||||
            marker = False
 | 
			
		||||
            sort_key = 'test'
 | 
			
		||||
            kwarg = 'name'
 | 
			
		||||
            sort_dir = 'test'
 | 
			
		||||
            name = 'test'
 | 
			
		||||
            disk_format = 'ovi'
 | 
			
		||||
            container_format = 'ovi'
 | 
			
		||||
            size = 1024
 | 
			
		||||
            is_public = True
 | 
			
		||||
            protected = False
 | 
			
		||||
            status = 'active'
 | 
			
		||||
            min_ram = 512
 | 
			
		||||
            min_disk = 512
 | 
			
		||||
            properties = {}
 | 
			
		||||
            created_at = '12.12.12'
 | 
			
		||||
 | 
			
		||||
        args = Image()
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'list') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = [Image(), Image()]
 | 
			
		||||
            actual = test_shell.do_details(gc, args)
 | 
			
		||||
 | 
			
		||||
    def test_do_image_members(self):
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.image_id = 1
 | 
			
		||||
                self.name = 'fake_image'
 | 
			
		||||
                self.is_public = False
 | 
			
		||||
                self.protected = False
 | 
			
		||||
                self.status = 'active'
 | 
			
		||||
                self.size = '1024'
 | 
			
		||||
                self.min_ram = 512
 | 
			
		||||
                self.min_disk = 10
 | 
			
		||||
                self.properties = {'a': 'b', 'c': 'd'}
 | 
			
		||||
                self.created_at = '04.03.2013'
 | 
			
		||||
                self.owner = 'test'
 | 
			
		||||
                self.updated_at = '04.03.2013'
 | 
			
		||||
                self.deleted_at = '04.03.2013'
 | 
			
		||||
                self.force = True
 | 
			
		||||
                self.verbose = True
 | 
			
		||||
 | 
			
		||||
            def delete(self):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            def get(self, id):
 | 
			
		||||
                return FakeImage1()
 | 
			
		||||
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.image_members = ImageMembers()
 | 
			
		||||
 | 
			
		||||
        class ImageMembers():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
 | 
			
		||||
            def list(self, image):
 | 
			
		||||
                return [ImageMembers(), ImageMembers()]
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_image_members(FakeClient(), FakeImage1())
 | 
			
		||||
 | 
			
		||||
    def test_do_member_add_error(self):
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.image_members = ImageMembers()
 | 
			
		||||
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
                self.fields = ["name", "id", "filter"]
 | 
			
		||||
                self.dry_run = True
 | 
			
		||||
                self.image_id = 'fake_image_id'
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
 | 
			
		||||
            def delete(self):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
            def get(self, id):
 | 
			
		||||
                return FakeImage1()
 | 
			
		||||
 | 
			
		||||
        class ImageMembers():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
 | 
			
		||||
            def list(self, image):
 | 
			
		||||
                return [ImageMembers(), ImageMembers()]
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_member_add(FakeClient(), FakeImage1())
 | 
			
		||||
 | 
			
		||||
    def test_do_member_images_empty_result(self):
 | 
			
		||||
        class FakeImage1():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.image_members, 'list') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = []
 | 
			
		||||
            actual = test_shell.do_member_images(gc, FakeImage1())
 | 
			
		||||
            self.assertEqual(0, actual)
 | 
			
		||||
 | 
			
		||||
    def test_do_member_replace(self):
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.image_members = ImageMembers()
 | 
			
		||||
 | 
			
		||||
        class ImageMembers():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
                self.dry_run = True
 | 
			
		||||
                self.image_id = "fake_image_id"
 | 
			
		||||
 | 
			
		||||
            def list(self, image):
 | 
			
		||||
                return [ImageMembers(), ImageMembers()]
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_member_add(FakeClient(), ImageMembers())
 | 
			
		||||
 | 
			
		||||
    def test_do_members_replace_dry_run_true(self):
 | 
			
		||||
        class Fake():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.dry_run = True
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
                self.image_id = 'fake_id'
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        actual = test_shell.do_members_replace(gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_do_members_replace_dry_run_false(self):
 | 
			
		||||
        class Fake():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.dry_run = False
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
                self.image_id = 'fake_id'
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        with mock.patch.object(gc.image_members, 'list') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = []
 | 
			
		||||
            with mock.patch.object(gc.image_members, 'create'):
 | 
			
		||||
                actual = test_shell.do_members_replace(gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_do_member_images(self):
 | 
			
		||||
        class FakeClient():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.image_members = ImageMembers()
 | 
			
		||||
 | 
			
		||||
        class ImageMembers():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.member_id = 'test'
 | 
			
		||||
                self.can_share = True
 | 
			
		||||
                self.dry_run = True
 | 
			
		||||
                self.image_id = "fake_image_id"
 | 
			
		||||
 | 
			
		||||
            def list(self, member):
 | 
			
		||||
                return [ImageMembers(), ImageMembers()]
 | 
			
		||||
 | 
			
		||||
        actual = test_shell.do_member_images(FakeClient(), ImageMembers())
 | 
			
		||||
 | 
			
		||||
    def test_create_pretty_table(self):
 | 
			
		||||
        class MyPrettyTable(test_shell.PrettyTable):
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.columns = []
 | 
			
		||||
 | 
			
		||||
        # Test add column
 | 
			
		||||
        my_pretty_table = MyPrettyTable()
 | 
			
		||||
        my_pretty_table.add_column(1, label='test')
 | 
			
		||||
 | 
			
		||||
        # Test make header
 | 
			
		||||
        test_res = my_pretty_table.make_header()
 | 
			
		||||
        self.assertEqual('t\n-', test_res)
 | 
			
		||||
 | 
			
		||||
        # Test make row
 | 
			
		||||
        result = my_pretty_table.make_row('t')
 | 
			
		||||
        self.assertEqual("t", result)
 | 
			
		||||
        result = my_pretty_table._clip_and_justify(
 | 
			
		||||
            data='test', width=4, just=1)
 | 
			
		||||
        self.assertEqual("test", result)
 | 
			
		||||
							
								
								
									
										136
									
								
								tests/v1/test_shell.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								tests/v1/test_shell.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
# Copyright 2013 OpenStack LLC.
 | 
			
		||||
# Copyright (C) 2013 Yahoo! Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
from glanceclient import exc
 | 
			
		||||
from glanceclient import shell
 | 
			
		||||
from tests import utils
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ShellInvalidEndpointTest(utils.TestCase):
 | 
			
		||||
 | 
			
		||||
    # Patch os.environ to avoid required auth info.
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        """Run before each test."""
 | 
			
		||||
        super(ShellInvalidEndpointTest, self).setUp()
 | 
			
		||||
        self.old_environment = os.environ.copy()
 | 
			
		||||
        os.environ = {
 | 
			
		||||
            'OS_USERNAME': 'username',
 | 
			
		||||
            'OS_PASSWORD': 'password',
 | 
			
		||||
            'OS_TENANT_ID': 'tenant_id',
 | 
			
		||||
            'OS_TOKEN_ID': 'test',
 | 
			
		||||
            'OS_AUTH_URL': 'http://127.0.0.1:5000/v2.0/',
 | 
			
		||||
            'OS_AUTH_TOKEN': 'pass',
 | 
			
		||||
            'OS_IMAGE_API_VERSION': '1',
 | 
			
		||||
            'OS_REGION_NAME': 'test',
 | 
			
		||||
            'OS_IMAGE_URL': 'http://no.where'}
 | 
			
		||||
 | 
			
		||||
        self.shell = shell.OpenStackImagesShell()
 | 
			
		||||
 | 
			
		||||
    def tearDown(self):
 | 
			
		||||
        super(ShellInvalidEndpointTest, self).tearDown()
 | 
			
		||||
        os.environ = self.old_environment
 | 
			
		||||
 | 
			
		||||
    def run_command(self, cmd):
 | 
			
		||||
        self.shell.main(cmd.split())
 | 
			
		||||
 | 
			
		||||
    def assert_called(self, method, url, body=None, **kwargs):
 | 
			
		||||
        return self.shell.cs.assert_called(method, url, body, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def assert_called_anytime(self, method, url, body=None):
 | 
			
		||||
        return self.shell.cs.assert_called_anytime(method, url, body)
 | 
			
		||||
 | 
			
		||||
    def test_image_list_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint, self.run_command, 'image-list')
 | 
			
		||||
 | 
			
		||||
    def test_image_details_invalid_endpoint_legacy(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint, self.run_command, 'details')
 | 
			
		||||
 | 
			
		||||
    def test_image_update_invalid_endpoint_legacy(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'update {"name":""test}')
 | 
			
		||||
 | 
			
		||||
    def test_image_index_invalid_endpoint_legacy(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'index')
 | 
			
		||||
 | 
			
		||||
    def test_image_create_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'image-create')
 | 
			
		||||
 | 
			
		||||
    def test_image_delete_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'image-delete <fake>')
 | 
			
		||||
 | 
			
		||||
    def test_image_download_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'image-download <fake>')
 | 
			
		||||
 | 
			
		||||
    def test_image_members_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'image-members fake_id')
 | 
			
		||||
 | 
			
		||||
    def test_members_list_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'member-list --image-id fake')
 | 
			
		||||
 | 
			
		||||
    def test_member_replace_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'members-replace image_id member_id')
 | 
			
		||||
 | 
			
		||||
    def test_image_show_invalid_endpoint_legacy(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint, self.run_command, 'show image')
 | 
			
		||||
 | 
			
		||||
    def test_image_show_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'image-show --human-readable <IMAGE_ID>')
 | 
			
		||||
 | 
			
		||||
    def test_member_images_invalid_endpoint_legacy(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command, 'member-images member_id')
 | 
			
		||||
 | 
			
		||||
    def test_member_create_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command,
 | 
			
		||||
            'member-create --can-share <IMAGE_ID> <TENANT_ID>')
 | 
			
		||||
 | 
			
		||||
    def test_member_delete_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command,
 | 
			
		||||
            'member-delete  <IMAGE_ID> <TENANT_ID>')
 | 
			
		||||
 | 
			
		||||
    def test_member_add_invalid_endpoint(self):
 | 
			
		||||
        self.assertRaises(
 | 
			
		||||
            exc.InvalidEndpoint,
 | 
			
		||||
            self.run_command,
 | 
			
		||||
            'member-add  <IMAGE_ID> <TENANT_ID>')
 | 
			
		||||
							
								
								
									
										86
									
								
								tests/v2/test_shell_v2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								tests/v2/test_shell_v2.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,86 @@
 | 
			
		||||
# Copyright 2013 OpenStack LLC.
 | 
			
		||||
# Copyright (C) 2013 Yahoo! Inc.
 | 
			
		||||
# All Rights Reserved.
 | 
			
		||||
#
 | 
			
		||||
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
			
		||||
#    not use this file except in compliance with the License. You may obtain
 | 
			
		||||
#    a copy of the License at
 | 
			
		||||
#
 | 
			
		||||
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
#
 | 
			
		||||
#    Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
			
		||||
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
			
		||||
 | 
			
		||||
import mock
 | 
			
		||||
import testtools
 | 
			
		||||
 | 
			
		||||
from glanceclient import client
 | 
			
		||||
from glanceclient.common import utils
 | 
			
		||||
from glanceclient.v2 import shell as test_shell
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class LegacyShellV1Test(testtools.TestCase):
 | 
			
		||||
    def test_do_image_list(self):
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        class Fake():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.page_size = 18
 | 
			
		||||
                self.visibility = True
 | 
			
		||||
                self.member_status = 'Fake'
 | 
			
		||||
                self.owner = 'test'
 | 
			
		||||
 | 
			
		||||
        with mock.patch.object(gc.images, 'list') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = {}
 | 
			
		||||
            actual = test_shell.do_image_list(gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_do_image_show(self):
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
 | 
			
		||||
        class Fake():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.page_size = 18
 | 
			
		||||
                self.id = 'pass'
 | 
			
		||||
 | 
			
		||||
        with mock.patch.object(gc.images, 'get') as mocked_list:
 | 
			
		||||
            mocked_list.return_value = {}
 | 
			
		||||
            actual = test_shell.do_image_show(gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_do_explain(self):
 | 
			
		||||
        my_mocked_gc = mock.Mock()
 | 
			
		||||
        my_mocked_gc.schemas.return_value = 'test'
 | 
			
		||||
        my_mocked_gc.get.return_value = {}
 | 
			
		||||
 | 
			
		||||
        class Fake():
 | 
			
		||||
            def __init__(self):
 | 
			
		||||
                self.page_size = 18
 | 
			
		||||
                self.id = 'pass'
 | 
			
		||||
                self.schemas = 'test'
 | 
			
		||||
                self.model = 'test'
 | 
			
		||||
 | 
			
		||||
        with mock.patch.object(utils, 'print_list'):
 | 
			
		||||
            test_shell.do_explain(my_mocked_gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_image_download(self):
 | 
			
		||||
        class Fake():
 | 
			
		||||
            id = 'pass'
 | 
			
		||||
            file = 'test'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'data') as mocked_data:
 | 
			
		||||
            mocked_data.return_value = 'test_passed'
 | 
			
		||||
            test_shell.do_image_download(gc, Fake())
 | 
			
		||||
 | 
			
		||||
    def test_do_image_delete(self):
 | 
			
		||||
        class Fake():
 | 
			
		||||
            id = 'pass'
 | 
			
		||||
            file = 'test'
 | 
			
		||||
 | 
			
		||||
        gc = client.Client('1', 'http://no.where')
 | 
			
		||||
        with mock.patch.object(gc.images, 'delete') as mocked_delete:
 | 
			
		||||
            mocked_delete.return_value = 0
 | 
			
		||||
            test_shell.do_image_delete(gc, Fake())
 | 
			
		||||
@@ -3,6 +3,7 @@ distribute>=0.6.24
 | 
			
		||||
coverage
 | 
			
		||||
discover
 | 
			
		||||
mox
 | 
			
		||||
mock>=0.8.0
 | 
			
		||||
pep8==1.3.3
 | 
			
		||||
setuptools-git>=0.4
 | 
			
		||||
sphinx>=1.1.2
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user