From ee78e6486a8b8649c78d487cc469225d656d1037 Mon Sep 17 00:00:00 2001 From: Victoria Martinez de la Cruz Date: Mon, 27 Jan 2020 22:09:18 +0000 Subject: [PATCH] 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 --- manilaclient/tests/osc/unit/v2/fakes.py | 34 ++++++++++++++++++++ manilaclient/tests/osc/unit/v2/test_share.py | 16 ++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/manilaclient/tests/osc/unit/v2/fakes.py b/manilaclient/tests/osc/unit/v2/fakes.py index a436fa091..04370178c 100644 --- a/manilaclient/tests/osc/unit/v2/fakes.py +++ b/manilaclient/tests/osc/unit/v2/fakes.py @@ -30,6 +30,9 @@ class FakeShareClient(object): self.management_url = kwargs['endpoint'] self.shares = mock.Mock() 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): @@ -227,3 +230,34 @@ class FakeShareType(object): share_type_info), loaded=True) 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 diff --git a/manilaclient/tests/osc/unit/v2/test_share.py b/manilaclient/tests/osc/unit/v2/test_share.py index 0a4f4f468..3a9ceb263 100644 --- a/manilaclient/tests/osc/unit/v2/test_share.py +++ b/manilaclient/tests/osc/unit/v2/test_share.py @@ -20,6 +20,7 @@ from mock import call 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.tests.osc.unit import osc_utils 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) 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) def test_share_delete_many(self): @@ -187,7 +188,7 @@ class TestShareDelete(TestShare): 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.assertIsNone(result) @@ -207,7 +208,7 @@ class TestShareDelete(TestShare): 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) def test_share_delete_wrong_name(self): @@ -831,8 +832,11 @@ class TestShareShow(TestShare): self._share = manila_fakes.FakeShare.create_one_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) def test_share_show(self): @@ -844,6 +848,10 @@ class TestShareShow(TestShare): ] 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) self.shares_mock.get.assert_called_with(self._share.id)