Add FakeSnapshot class and update snapshot test in VolumeV2
Add FakeSnapshot class and update unit tests for snapshot commands with the FakeSnapshot class. Change-Id: If039a48b9d5f8430cc3d041b8c7ec30af8ff0e03
This commit is contained in:
		@@ -552,3 +552,56 @@ class FakeBackup(object):
 | 
			
		||||
            backups.append(backup)
 | 
			
		||||
 | 
			
		||||
        return backups
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FakeSnapshot(object):
 | 
			
		||||
    """Fake one or more snapshot."""
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def create_one_snapshot(attrs=None):
 | 
			
		||||
        """Create a fake snapshot.
 | 
			
		||||
 | 
			
		||||
        :param Dictionary attrs:
 | 
			
		||||
            A dictionary with all attributes
 | 
			
		||||
        :return:
 | 
			
		||||
            A FakeResource object with id, name, description, etc.
 | 
			
		||||
        """
 | 
			
		||||
        attrs = attrs or {}
 | 
			
		||||
 | 
			
		||||
        # Set default attributes.
 | 
			
		||||
        snapshot_info = {
 | 
			
		||||
            "id": 'snapshot-id-' + uuid.uuid4().hex,
 | 
			
		||||
            "name": 'snapshot-name-' + uuid.uuid4().hex,
 | 
			
		||||
            "description": 'snapshot-description-' + uuid.uuid4().hex,
 | 
			
		||||
            "size": 10,
 | 
			
		||||
            "status": "available",
 | 
			
		||||
            "metadata": {"foo": "bar"},
 | 
			
		||||
            "created_at": "2015-06-03T18:49:19.000000",
 | 
			
		||||
            "volume_id": 'vloume-id-' + uuid.uuid4().hex,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        # Overwrite default attributes.
 | 
			
		||||
        snapshot_info.update(attrs)
 | 
			
		||||
 | 
			
		||||
        snapshot = fakes.FakeResource(
 | 
			
		||||
            info=copy.deepcopy(snapshot_info),
 | 
			
		||||
            loaded=True)
 | 
			
		||||
        return snapshot
 | 
			
		||||
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def create_snapshots(attrs=None, count=2):
 | 
			
		||||
        """Create multiple fake snapshots.
 | 
			
		||||
 | 
			
		||||
        :param Dictionary attrs:
 | 
			
		||||
            A dictionary with all attributes
 | 
			
		||||
        :param int count:
 | 
			
		||||
            The number of snapshots to fake
 | 
			
		||||
        :return:
 | 
			
		||||
            A list of FakeResource objects faking the snapshots
 | 
			
		||||
        """
 | 
			
		||||
        snapshots = []
 | 
			
		||||
        for i in range(0, count):
 | 
			
		||||
            snapshot = FakeSnapshot.create_one_snapshot(attrs)
 | 
			
		||||
            snapshots.append(snapshot)
 | 
			
		||||
 | 
			
		||||
        return snapshots
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,7 @@
 | 
			
		||||
#   under the License.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
import copy
 | 
			
		||||
 | 
			
		||||
from openstackclient.tests import fakes
 | 
			
		||||
from openstackclient.common import utils
 | 
			
		||||
from openstackclient.tests.volume.v2 import fakes as volume_fakes
 | 
			
		||||
from openstackclient.volume.v2 import snapshot
 | 
			
		||||
 | 
			
		||||
@@ -32,58 +30,75 @@ class TestSnapshot(volume_fakes.TestVolume):
 | 
			
		||||
 | 
			
		||||
class TestSnapshotCreate(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    columns = (
 | 
			
		||||
        'created_at',
 | 
			
		||||
        'description',
 | 
			
		||||
        'id',
 | 
			
		||||
        'name',
 | 
			
		||||
        'properties',
 | 
			
		||||
        'size',
 | 
			
		||||
        'status',
 | 
			
		||||
        'volume_id',
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotCreate, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.volumes_mock.get.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.VOLUME),
 | 
			
		||||
            loaded=True
 | 
			
		||||
        self.volume = volume_fakes.FakeVolume.create_one_volume()
 | 
			
		||||
        self.new_snapshot = volume_fakes.FakeSnapshot.create_one_snapshot(
 | 
			
		||||
            attrs={'volume_id': self.volume.id})
 | 
			
		||||
 | 
			
		||||
        self.data = (
 | 
			
		||||
            self.new_snapshot.created_at,
 | 
			
		||||
            self.new_snapshot.description,
 | 
			
		||||
            self.new_snapshot.id,
 | 
			
		||||
            self.new_snapshot.name,
 | 
			
		||||
            utils.format_dict(self.new_snapshot.metadata),
 | 
			
		||||
            self.new_snapshot.size,
 | 
			
		||||
            self.new_snapshot.status,
 | 
			
		||||
            self.new_snapshot.volume_id,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.create.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
            loaded=True
 | 
			
		||||
        )
 | 
			
		||||
        self.volumes_mock.get.return_value = self.volume
 | 
			
		||||
        self.snapshots_mock.create.return_value = self.new_snapshot
 | 
			
		||||
        # Get the command object to test
 | 
			
		||||
        self.cmd = snapshot.CreateSnapshot(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_create(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.volume_id,
 | 
			
		||||
            "--name", volume_fakes.snapshot_name,
 | 
			
		||||
            "--description", volume_fakes.snapshot_description,
 | 
			
		||||
            "--force"
 | 
			
		||||
            "--name", self.new_snapshot.name,
 | 
			
		||||
            "--description", self.new_snapshot.description,
 | 
			
		||||
            "--force",
 | 
			
		||||
            self.new_snapshot.volume_id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("volume", volume_fakes.volume_id),
 | 
			
		||||
            ("name", volume_fakes.snapshot_name),
 | 
			
		||||
            ("description", volume_fakes.snapshot_description),
 | 
			
		||||
            ("force", True)
 | 
			
		||||
            ("name", self.new_snapshot.name),
 | 
			
		||||
            ("description", self.new_snapshot.description),
 | 
			
		||||
            ("force", True),
 | 
			
		||||
            ("volume", self.new_snapshot.volume_id),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.create.assert_called_with(
 | 
			
		||||
            volume_fakes.volume_id,
 | 
			
		||||
            self.new_snapshot.volume_id,
 | 
			
		||||
            force=True,
 | 
			
		||||
            name=volume_fakes.snapshot_name,
 | 
			
		||||
            description=volume_fakes.snapshot_description
 | 
			
		||||
            name=self.new_snapshot.name,
 | 
			
		||||
            description=self.new_snapshot.description
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(columns, volume_fakes.SNAPSHOT_columns)
 | 
			
		||||
        self.assertEqual(data, volume_fakes.SNAPSHOT_data)
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        self.assertEqual(self.data, data)
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_create_without_name(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.volume_id,
 | 
			
		||||
            "--description", volume_fakes.snapshot_description,
 | 
			
		||||
            self.new_snapshot.volume_id,
 | 
			
		||||
            "--description", self.new_snapshot.description,
 | 
			
		||||
            "--force"
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("volume", volume_fakes.volume_id),
 | 
			
		||||
            ("description", volume_fakes.snapshot_description),
 | 
			
		||||
            ("volume", self.new_snapshot.volume_id),
 | 
			
		||||
            ("description", self.new_snapshot.description),
 | 
			
		||||
            ("force", True)
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -91,24 +106,23 @@ class TestSnapshotCreate(TestSnapshot):
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.create.assert_called_with(
 | 
			
		||||
            volume_fakes.volume_id,
 | 
			
		||||
            self.new_snapshot.volume_id,
 | 
			
		||||
            force=True,
 | 
			
		||||
            name=None,
 | 
			
		||||
            description=volume_fakes.snapshot_description
 | 
			
		||||
            description=self.new_snapshot.description
 | 
			
		||||
        )
 | 
			
		||||
        self.assertEqual(columns, volume_fakes.SNAPSHOT_columns)
 | 
			
		||||
        self.assertEqual(data, volume_fakes.SNAPSHOT_data)
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        self.assertEqual(self.data, data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSnapshotDelete(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotDelete, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.get.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
            loaded=True)
 | 
			
		||||
        self.snapshots_mock.get.return_value = self.snapshot
 | 
			
		||||
        self.snapshots_mock.delete.return_value = None
 | 
			
		||||
 | 
			
		||||
        # Get the command object to mock
 | 
			
		||||
@@ -116,21 +130,25 @@ class TestSnapshotDelete(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_delete(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.snapshot_id
 | 
			
		||||
            self.snapshot.id
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("snapshots", [volume_fakes.snapshot_id])
 | 
			
		||||
            ("snapshots", [self.snapshot.id])
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.delete.assert_called_with(volume_fakes.snapshot_id)
 | 
			
		||||
        self.snapshots_mock.delete.assert_called_with(self.snapshot.id)
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSnapshotList(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    volume = volume_fakes.FakeVolume.create_one_volume()
 | 
			
		||||
    snapshots = volume_fakes.FakeSnapshot.create_snapshots(
 | 
			
		||||
        attrs={'volume_id': volume.name}, count=3)
 | 
			
		||||
 | 
			
		||||
    columns = [
 | 
			
		||||
        "ID",
 | 
			
		||||
        "Name",
 | 
			
		||||
@@ -138,24 +156,39 @@ class TestSnapshotList(TestSnapshot):
 | 
			
		||||
        "Status",
 | 
			
		||||
        "Size"
 | 
			
		||||
    ]
 | 
			
		||||
    columns_long = columns + [
 | 
			
		||||
        "Created At",
 | 
			
		||||
        "Volume",
 | 
			
		||||
        "Properties"
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    data = []
 | 
			
		||||
    for s in snapshots:
 | 
			
		||||
        data.append((
 | 
			
		||||
            s.id,
 | 
			
		||||
            s.name,
 | 
			
		||||
            s.description,
 | 
			
		||||
            s.status,
 | 
			
		||||
            s.size,
 | 
			
		||||
        ))
 | 
			
		||||
    data_long = []
 | 
			
		||||
    for s in snapshots:
 | 
			
		||||
        data_long.append((
 | 
			
		||||
            s.id,
 | 
			
		||||
            s.name,
 | 
			
		||||
            s.description,
 | 
			
		||||
            s.status,
 | 
			
		||||
            s.size,
 | 
			
		||||
            s.created_at,
 | 
			
		||||
            s.volume_id,
 | 
			
		||||
            utils.format_dict(s.metadata),
 | 
			
		||||
        ))
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotList, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.volumes_mock.list.return_value = [
 | 
			
		||||
            fakes.FakeResource(
 | 
			
		||||
                None,
 | 
			
		||||
                copy.deepcopy(volume_fakes.VOLUME),
 | 
			
		||||
                loaded=True
 | 
			
		||||
            )
 | 
			
		||||
        ]
 | 
			
		||||
        self.snapshots_mock.list.return_value = [
 | 
			
		||||
            fakes.FakeResource(
 | 
			
		||||
                None,
 | 
			
		||||
                copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
                loaded=True
 | 
			
		||||
            )
 | 
			
		||||
        ]
 | 
			
		||||
        self.volumes_mock.list.return_value = [self.volume]
 | 
			
		||||
        self.snapshots_mock.list.return_value = self.snapshots
 | 
			
		||||
        # Get the command to test
 | 
			
		||||
        self.cmd = snapshot.ListSnapshot(self.app, None)
 | 
			
		||||
 | 
			
		||||
@@ -169,14 +202,7 @@ class TestSnapshotList(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        datalist = ((
 | 
			
		||||
            volume_fakes.snapshot_id,
 | 
			
		||||
            volume_fakes.snapshot_name,
 | 
			
		||||
            volume_fakes.snapshot_description,
 | 
			
		||||
            "available",
 | 
			
		||||
            volume_fakes.snapshot_size
 | 
			
		||||
        ),)
 | 
			
		||||
        self.assertEqual(datalist, tuple(data))
 | 
			
		||||
        self.assertEqual(self.data, list(data))
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_list_with_options(self):
 | 
			
		||||
        arglist = ["--long"]
 | 
			
		||||
@@ -185,24 +211,8 @@ class TestSnapshotList(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        columns = self.columns + [
 | 
			
		||||
            "Created At",
 | 
			
		||||
            "Volume",
 | 
			
		||||
            "Properties"
 | 
			
		||||
        ]
 | 
			
		||||
        self.assertEqual(columns, columns)
 | 
			
		||||
 | 
			
		||||
        datalist = ((
 | 
			
		||||
            volume_fakes.snapshot_id,
 | 
			
		||||
            volume_fakes.snapshot_name,
 | 
			
		||||
            volume_fakes.snapshot_description,
 | 
			
		||||
            "available",
 | 
			
		||||
            volume_fakes.snapshot_size,
 | 
			
		||||
            "2015-06-03T18:49:19.000000",
 | 
			
		||||
            volume_fakes.volume_name,
 | 
			
		||||
            volume_fakes.EXPECTED_SNAPSHOT.get("properties")
 | 
			
		||||
        ),)
 | 
			
		||||
        self.assertEqual(datalist, tuple(data))
 | 
			
		||||
        self.assertEqual(self.columns_long, columns)
 | 
			
		||||
        self.assertEqual(self.data_long, list(data))
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_list_all_projects(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
@@ -217,26 +227,17 @@ class TestSnapshotList(TestSnapshot):
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        datalist = ((
 | 
			
		||||
            volume_fakes.snapshot_id,
 | 
			
		||||
            volume_fakes.snapshot_name,
 | 
			
		||||
            volume_fakes.snapshot_description,
 | 
			
		||||
            "available",
 | 
			
		||||
            volume_fakes.snapshot_size
 | 
			
		||||
        ), )
 | 
			
		||||
        self.assertEqual(datalist, tuple(data))
 | 
			
		||||
        self.assertEqual(self.data, list(data))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSnapshotSet(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotSet, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.get.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
            loaded=True
 | 
			
		||||
        )
 | 
			
		||||
        self.snapshots_mock.get.return_value = self.snapshot
 | 
			
		||||
        self.snapshots_mock.set_metadata.return_value = None
 | 
			
		||||
        self.snapshots_mock.update.return_value = None
 | 
			
		||||
        # Get the command object to mock
 | 
			
		||||
@@ -244,16 +245,16 @@ class TestSnapshotSet(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_set(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.snapshot_id,
 | 
			
		||||
            "--name", "new_snapshot",
 | 
			
		||||
            "--property", "x=y",
 | 
			
		||||
            "--property", "foo=foo"
 | 
			
		||||
            "--property", "foo=foo",
 | 
			
		||||
            self.snapshot.id,
 | 
			
		||||
        ]
 | 
			
		||||
        new_property = {"x": "y", "foo": "foo"}
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("snapshot", volume_fakes.snapshot_id),
 | 
			
		||||
            ("name", "new_snapshot"),
 | 
			
		||||
            ("property", new_property)
 | 
			
		||||
            ("property", new_property),
 | 
			
		||||
            ("snapshot", self.snapshot.id),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
@@ -263,79 +264,99 @@ class TestSnapshotSet(TestSnapshot):
 | 
			
		||||
            "name": "new_snapshot",
 | 
			
		||||
        }
 | 
			
		||||
        self.snapshots_mock.update.assert_called_with(
 | 
			
		||||
            volume_fakes.snapshot_id, **kwargs)
 | 
			
		||||
            self.snapshot.id, **kwargs)
 | 
			
		||||
        self.snapshots_mock.set_metadata.assert_called_with(
 | 
			
		||||
            volume_fakes.snapshot_id, new_property
 | 
			
		||||
            self.snapshot.id, new_property
 | 
			
		||||
        )
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_set_state_to_error(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            "--state", "error",
 | 
			
		||||
            volume_fakes.snapshot_id
 | 
			
		||||
            self.snapshot.id
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("state", "error"),
 | 
			
		||||
            ("snapshot", volume_fakes.snapshot_id)
 | 
			
		||||
            ("snapshot", self.snapshot.id)
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.reset_state.assert_called_with(
 | 
			
		||||
            volume_fakes.snapshot_id, "error")
 | 
			
		||||
            self.snapshot.id, "error")
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSnapshotShow(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    columns = (
 | 
			
		||||
        'created_at',
 | 
			
		||||
        'description',
 | 
			
		||||
        'id',
 | 
			
		||||
        'name',
 | 
			
		||||
        'properties',
 | 
			
		||||
        'size',
 | 
			
		||||
        'status',
 | 
			
		||||
        'volume_id',
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotShow, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.get.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
            loaded=True)
 | 
			
		||||
        self.snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
 | 
			
		||||
 | 
			
		||||
        self.data = (
 | 
			
		||||
            self.snapshot.created_at,
 | 
			
		||||
            self.snapshot.description,
 | 
			
		||||
            self.snapshot.id,
 | 
			
		||||
            self.snapshot.name,
 | 
			
		||||
            utils.format_dict(self.snapshot.metadata),
 | 
			
		||||
            self.snapshot.size,
 | 
			
		||||
            self.snapshot.status,
 | 
			
		||||
            self.snapshot.volume_id,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.get.return_value = self.snapshot
 | 
			
		||||
        # Get the command object to test
 | 
			
		||||
        self.cmd = snapshot.ShowSnapshot(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_show(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.snapshot_id
 | 
			
		||||
            self.snapshot.id
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("snapshot", volume_fakes.snapshot_id)
 | 
			
		||||
            ("snapshot", self.snapshot.id)
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
        self.snapshots_mock.get.assert_called_with(volume_fakes.snapshot_id)
 | 
			
		||||
        self.snapshots_mock.get.assert_called_with(self.snapshot.id)
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(volume_fakes.SNAPSHOT_columns, columns)
 | 
			
		||||
        self.assertEqual(volume_fakes.SNAPSHOT_data, data)
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        self.assertEqual(self.data, data)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestSnapshotUnset(TestSnapshot):
 | 
			
		||||
 | 
			
		||||
    snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
 | 
			
		||||
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        super(TestSnapshotUnset, self).setUp()
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.get.return_value = fakes.FakeResource(
 | 
			
		||||
            None,
 | 
			
		||||
            copy.deepcopy(volume_fakes.SNAPSHOT),
 | 
			
		||||
            loaded=True
 | 
			
		||||
        )
 | 
			
		||||
        self.snapshots_mock.get.return_value = self.snapshot
 | 
			
		||||
        self.snapshots_mock.delete_metadata.return_value = None
 | 
			
		||||
        # Get the command object to mock
 | 
			
		||||
        self.cmd = snapshot.UnsetSnapshot(self.app, None)
 | 
			
		||||
 | 
			
		||||
    def test_snapshot_unset(self):
 | 
			
		||||
        arglist = [
 | 
			
		||||
            volume_fakes.snapshot_id,
 | 
			
		||||
            "--property", "foo"
 | 
			
		||||
            "--property", "foo",
 | 
			
		||||
            self.snapshot.id,
 | 
			
		||||
        ]
 | 
			
		||||
        verifylist = [
 | 
			
		||||
            ("snapshot", volume_fakes.snapshot_id),
 | 
			
		||||
            ("property", ["foo"])
 | 
			
		||||
            ("property", ["foo"]),
 | 
			
		||||
            ("snapshot", self.snapshot.id),
 | 
			
		||||
        ]
 | 
			
		||||
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
@@ -343,6 +364,6 @@ class TestSnapshotUnset(TestSnapshot):
 | 
			
		||||
        result = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        self.snapshots_mock.delete_metadata.assert_called_with(
 | 
			
		||||
            volume_fakes.snapshot_id, ["foo"]
 | 
			
		||||
            self.snapshot.id, ["foo"]
 | 
			
		||||
        )
 | 
			
		||||
        self.assertIsNone(result)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user