コード例 #1
0
    def test_do_image_create_no_user_props(self):
        args = self._make_args({
            'name': 'IMG-01',
            'disk_format': 'vhd',
            'container_format': 'bare'
        })
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['disk_format'] = 'vhd'
            expect_image['container_format'] = 'bare'
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  disk_format='vhd',
                                                  container_format='bare')
            utils.print_dict.assert_called_once_with({
                'id': 'pass',
                'name': 'IMG-01',
                'disk_format': 'vhd',
                'container_format': 'bare'
            })
コード例 #2
0
    def test_do_image_create_with_user_props(self, mock_stdin):
        args = self._make_args({
            'name': 'IMG-01',
            'property': ['myprop=myval'],
            'file': None
        })
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['myprop'] = 'myval'
            mocked_create.return_value = expect_image

            # Ensure that the test stdin is not considered
            # to be supplying image data
            mock_stdin.isatty = lambda: True
            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  myprop='myval')
            utils.print_dict.assert_called_once_with({
                'id': 'pass',
                'name': 'IMG-01',
                'myprop': 'myval'
            })
コード例 #3
0
    def test_do_image_create_with_user_props(self):
        args = self._make_args({"name": "IMG-01", "property": ["myprop=myval"]})
        with mock.patch.object(self.gc.images, "create") as mocked_create:
            ignore_fields = ["self", "access", "file", "schema"]
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image["id"] = "pass"
            expect_image["name"] = "IMG-01"
            expect_image["myprop"] = "myval"
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name="IMG-01", myprop="myval")
            utils.print_dict.assert_called_once_with({"id": "pass", "name": "IMG-01", "myprop": "myval"})
コード例 #4
0
    def test_do_image_create_with_file(self):
        try:
            file_name = None
            with open(tempfile.mktemp(), 'w+') as f:
                f.write('Some data here')
                f.flush()
                f.seek(0)
                file_name = f.name
            temp_args = {
                'name': 'IMG-01',
                'disk_format': 'vhd',
                'container_format': 'bare',
                'file': file_name,
                'progress': False
            }
            args = self._make_args(temp_args)
            with mock.patch.object(self.gc.images, 'create') as mocked_create:
                with mock.patch.object(self.gc.images, 'get') as mocked_get:

                    ignore_fields = ['self', 'access', 'schema']
                    expect_image = dict([(field, field)
                                         for field in ignore_fields])
                    expect_image['id'] = 'pass'
                    expect_image['name'] = 'IMG-01'
                    expect_image['disk_format'] = 'vhd'
                    expect_image['container_format'] = 'bare'
                    mocked_create.return_value = expect_image
                    mocked_get.return_value = expect_image

                    test_shell.do_image_create(self.gc, args)

                    temp_args.pop('file', None)
                    mocked_create.assert_called_once_with(**temp_args)
                    mocked_get.assert_called_once_with('pass')
                    utils.print_dict.assert_called_once_with({
                        'id':
                        'pass',
                        'name':
                        'IMG-01',
                        'disk_format':
                        'vhd',
                        'container_format':
                        'bare'
                    })
        finally:
            try:
                os.remove(f.name)
            except Exception:
                pass
コード例 #5
0
    def test_do_image_create_with_user_props(self):
        args = self._make_args({'name': 'IMG-01',
                                'property': ['myprop=myval']})
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['myprop'] = 'myval'
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  myprop='myval')
            utils.print_dict.assert_called_once_with({
                'id': 'pass', 'name': 'IMG-01', 'myprop': 'myval'})
コード例 #6
0
    def test_do_image_create_with_user_props(self, mock_stdin):
        args = self._make_args({"name": "IMG-01", "property": ["myprop=myval"], "file": None})
        with mock.patch.object(self.gc.images, "create") as mocked_create:
            ignore_fields = ["self", "access", "file", "schema"]
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image["id"] = "pass"
            expect_image["name"] = "IMG-01"
            expect_image["myprop"] = "myval"
            mocked_create.return_value = expect_image

            # Ensure that the test stdin is not considered
            # to be supplying image data
            mock_stdin.isatty = lambda: True
            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name="IMG-01", myprop="myval")
            utils.print_dict.assert_called_once_with({"id": "pass", "name": "IMG-01", "myprop": "myval"})
コード例 #7
0
    def test_do_image_create_no_user_props(self):
        args = self._make_args({"name": "IMG-01", "disk_format": "vhd", "container_format": "bare"})
        with mock.patch.object(self.gc.images, "create") as mocked_create:
            ignore_fields = ["self", "access", "file", "schema"]
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image["id"] = "pass"
            expect_image["name"] = "IMG-01"
            expect_image["disk_format"] = "vhd"
            expect_image["container_format"] = "bare"
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name="IMG-01", disk_format="vhd", container_format="bare")
            utils.print_dict.assert_called_once_with(
                {"id": "pass", "name": "IMG-01", "disk_format": "vhd", "container_format": "bare"}
            )
コード例 #8
0
    def test_do_image_create_with_user_props(self):
        args = self._make_args({'name': 'IMG-01',
                                'property': ['myprop=myval']})
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['myprop'] = 'myval'
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  myprop='myval')
            utils.print_dict.assert_called_once_with({
                'id': 'pass', 'name': 'IMG-01', 'myprop': 'myval'})
コード例 #9
0
    def test_do_image_create_no_user_props(self):
        args = self._make_args({'name': 'IMG-01', 'disk_format': 'vhd',
                                'container_format': 'bare'})
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['disk_format'] = 'vhd'
            expect_image['container_format'] = 'bare'
            mocked_create.return_value = expect_image

            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  disk_format='vhd',
                                                  container_format='bare')
            utils.print_dict.assert_called_once_with({
                'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
                'container_format': 'bare'})
コード例 #10
0
    def test_do_image_create_with_file(self):
        try:
            file_name = None
            with open(tempfile.mktemp(), "w+") as f:
                f.write("Some data here")
                f.flush()
                f.seek(0)
                file_name = f.name
            temp_args = {
                "name": "IMG-01",
                "disk_format": "vhd",
                "container_format": "bare",
                "file": file_name,
                "progress": False,
            }
            args = self._make_args(temp_args)
            with mock.patch.object(self.gc.images, "create") as mocked_create:
                with mock.patch.object(self.gc.images, "get") as mocked_get:

                    ignore_fields = ["self", "access", "schema"]
                    expect_image = dict([(field, field) for field in ignore_fields])
                    expect_image["id"] = "pass"
                    expect_image["name"] = "IMG-01"
                    expect_image["disk_format"] = "vhd"
                    expect_image["container_format"] = "bare"
                    mocked_create.return_value = expect_image
                    mocked_get.return_value = expect_image

                    test_shell.do_image_create(self.gc, args)

                    temp_args.pop("file", None)
                    mocked_create.assert_called_once_with(**temp_args)
                    mocked_get.assert_called_once_with("pass")
                    utils.print_dict.assert_called_once_with(
                        {"id": "pass", "name": "IMG-01", "disk_format": "vhd", "container_format": "bare"}
                    )
        finally:
            try:
                os.remove(f.name)
            except Exception:
                pass
コード例 #11
0
    def test_do_image_create_with_user_props(self, mock_stdin):
        args = self._make_args({'name': 'IMG-01',
                                'property': ['myprop=myval'],
                                'file': None})
        with mock.patch.object(self.gc.images, 'create') as mocked_create:
            ignore_fields = ['self', 'access', 'file', 'schema']
            expect_image = dict([(field, field) for field in ignore_fields])
            expect_image['id'] = 'pass'
            expect_image['name'] = 'IMG-01'
            expect_image['myprop'] = 'myval'
            mocked_create.return_value = expect_image

            # Ensure that the test stdin is not considered
            # to be supplying image data
            mock_stdin.isatty = lambda: True
            test_shell.do_image_create(self.gc, args)

            mocked_create.assert_called_once_with(name='IMG-01',
                                                  myprop='myval')
            utils.print_dict.assert_called_once_with({
                'id': 'pass', 'name': 'IMG-01', 'myprop': 'myval'})
コード例 #12
0
    def test_do_image_create_with_file(self):
        try:
            file_name = None
            with open(tempfile.mktemp(), 'w+') as f:
                f.write('Some data here')
                f.flush()
                f.seek(0)
                file_name = f.name
            temp_args = {'name': 'IMG-01',
                         'disk_format': 'vhd',
                         'container_format': 'bare',
                         'file': file_name,
                         'progress': False}
            args = self._make_args(temp_args)
            with mock.patch.object(self.gc.images, 'create') as mocked_create:
                with mock.patch.object(self.gc.images, 'get') as mocked_get:

                    ignore_fields = ['self', 'access', 'schema']
                    expect_image = dict([(field, field) for field in
                                         ignore_fields])
                    expect_image['id'] = 'pass'
                    expect_image['name'] = 'IMG-01'
                    expect_image['disk_format'] = 'vhd'
                    expect_image['container_format'] = 'bare'
                    mocked_create.return_value = expect_image
                    mocked_get.return_value = expect_image

                    test_shell.do_image_create(self.gc, args)

                    temp_args.pop('file', None)
                    mocked_create.assert_called_once_with(**temp_args)
                    mocked_get.assert_called_once_with('pass')
                    utils.print_dict.assert_called_once_with({
                        'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
                        'container_format': 'bare'})
        finally:
            try:
                os.remove(f.name)
            except Exception:
                pass