Fix osc delete share and show share tests
Delete one share, force delete one share, delete many shares and show share unit tests were broken. Those failures were not caught up because we were not running tests on our gate. This patch set fix those tests. The dependeny will add osc unit tests to main python jobs Change-Id: I14fe8601b0a9b82d55473a38916b13ded38f4bc5
This commit is contained in:
parent
cb6d195988
commit
ee78e6486a
@ -30,6 +30,9 @@ class FakeShareClient(object):
|
|||||||
self.management_url = kwargs['endpoint']
|
self.management_url = kwargs['endpoint']
|
||||||
self.shares = mock.Mock()
|
self.shares = mock.Mock()
|
||||||
self.shares.resource_class = osc_fakes.FakeResource(None, {})
|
self.shares.resource_class = osc_fakes.FakeResource(None, {})
|
||||||
|
self.share_export_locations = mock.Mock()
|
||||||
|
self.share_export_locations.resource_class = (
|
||||||
|
osc_fakes.FakeResource(None, {}))
|
||||||
|
|
||||||
|
|
||||||
class ManilaParseException(Exception):
|
class ManilaParseException(Exception):
|
||||||
@ -227,3 +230,34 @@ class FakeShareType(object):
|
|||||||
share_type_info),
|
share_type_info),
|
||||||
loaded=True)
|
loaded=True)
|
||||||
return share_type
|
return share_type
|
||||||
|
|
||||||
|
|
||||||
|
class FakeShareExportLocation(object):
|
||||||
|
"""Fake one or more export locations"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_one_export_location(attrs=None):
|
||||||
|
"""Create a fake share export location
|
||||||
|
|
||||||
|
:param Dictionary attrs:
|
||||||
|
A dictionary with all attributes
|
||||||
|
:return:
|
||||||
|
A FakeResource object, with project_id, resource and so on
|
||||||
|
"""
|
||||||
|
|
||||||
|
attrs = attrs or {}
|
||||||
|
|
||||||
|
share_export_location_info = {
|
||||||
|
"fake_uuid": "foo_el_uuid",
|
||||||
|
"fake_path": "/foo/el/path",
|
||||||
|
"fake_share_instance_id": 'share-instance-id' + uuid.uuid4().hex,
|
||||||
|
"is_admin_only": False,
|
||||||
|
"created_at": 'time-' + uuid.uuid4().hex,
|
||||||
|
"updated_at": 'time-' + uuid.uuid4().hex,
|
||||||
|
}
|
||||||
|
|
||||||
|
share_export_location_info.update(attrs)
|
||||||
|
share_export_location = osc_fakes.FakeResource(info=copy.deepcopy(
|
||||||
|
share_export_location_info),
|
||||||
|
loaded=True)
|
||||||
|
return share_export_location
|
||||||
|
@ -20,6 +20,7 @@ from mock import call
|
|||||||
|
|
||||||
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||||
|
|
||||||
|
from manilaclient.common import cliutils
|
||||||
from manilaclient.osc.v2 import share as osc_shares
|
from manilaclient.osc.v2 import share as osc_shares
|
||||||
from manilaclient.tests.osc.unit import osc_utils
|
from manilaclient.tests.osc.unit import osc_utils
|
||||||
from manilaclient.tests.osc.unit.v2 import fakes as manila_fakes
|
from manilaclient.tests.osc.unit.v2 import fakes as manila_fakes
|
||||||
@ -171,7 +172,7 @@ class TestShareDelete(TestShare):
|
|||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
self.shares_mock.delete.assert_called_with(shares[0].name, None)
|
self.shares_mock.delete.assert_called_with(shares[0], None)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_share_delete_many(self):
|
def test_share_delete_many(self):
|
||||||
@ -187,7 +188,7 @@ class TestShareDelete(TestShare):
|
|||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
calls = [call(s.name, None) for s in shares]
|
calls = [call(s, None) for s in shares]
|
||||||
self.shares_mock.delete.assert_has_calls(calls)
|
self.shares_mock.delete.assert_has_calls(calls)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
@ -207,7 +208,7 @@ class TestShareDelete(TestShare):
|
|||||||
|
|
||||||
result = self.cmd.take_action(parsed_args)
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.shares_mock.force_delete.assert_called_once_with(shares[0].name)
|
self.shares_mock.force_delete.assert_called_once_with(shares[0])
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_share_delete_wrong_name(self):
|
def test_share_delete_wrong_name(self):
|
||||||
@ -831,8 +832,11 @@ class TestShareShow(TestShare):
|
|||||||
|
|
||||||
self._share = manila_fakes.FakeShare.create_one_share()
|
self._share = manila_fakes.FakeShare.create_one_share()
|
||||||
self.shares_mock.get.return_value = self._share
|
self.shares_mock.get.return_value = self._share
|
||||||
# Get the command object to test
|
|
||||||
|
|
||||||
|
self._export_location = (
|
||||||
|
manila_fakes.FakeShareExportLocation.create_one_export_location())
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
self.cmd = osc_shares.ShowShare(self.app, None)
|
self.cmd = osc_shares.ShowShare(self.app, None)
|
||||||
|
|
||||||
def test_share_show(self):
|
def test_share_show(self):
|
||||||
@ -844,6 +848,10 @@ class TestShareShow(TestShare):
|
|||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
cliutils.transform_export_locations_to_string_view = mock.Mock()
|
||||||
|
cliutils.transform_export_locations_to_string_view.return_value = dict(
|
||||||
|
self._export_location)
|
||||||
|
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
self.shares_mock.get.assert_called_with(self._share.id)
|
self.shares_mock.get.assert_called_with(self._share.id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user