APITestCase is replaced with APIMockTestCase
Update Murano dashboard gate tests to use the class, APIMockTestCase, instead of the class, APITestCase, which is deprecated. Change-Id: Ic3bd6ca292807d0ce3b123ab2f468ee0d79f790e
This commit is contained in:
parent
4dea571014
commit
a7a35fec38
|
@ -17,34 +17,29 @@ from django.core import exceptions
|
|||
from muranodashboard.dynamic_ui import fields
|
||||
from openstack_dashboard.test import helpers
|
||||
|
||||
import mock
|
||||
|
||||
class TestFlavorField(helpers.APITestCase):
|
||||
def setUp(self):
|
||||
"""Set up the Flavor Class and novaclient."""
|
||||
super(TestFlavorField, self).setUp()
|
||||
|
||||
class FlavorFlave(object):
|
||||
def __init__(self, id, name, vcpus, disk, ram):
|
||||
self.name = name
|
||||
self.vcpus = vcpus
|
||||
self.disk = disk
|
||||
self.ram = ram
|
||||
self.id = id
|
||||
class FlavorFlave(object):
|
||||
def __init__(self, id, name, vcpus, disk, ram):
|
||||
self.name = name
|
||||
self.vcpus = vcpus
|
||||
self.disk = disk
|
||||
self.ram = ram
|
||||
self.id = id
|
||||
|
||||
novaclient = self.stub_novaclient()
|
||||
novaclient.flavors = self.mox.CreateMockAnything()
|
||||
# Set up the Flavor list
|
||||
novaclient.flavors.list().MultipleTimes().AndReturn(
|
||||
[FlavorFlave('id1', 'small', vcpus=1, disk=50, ram=1000),
|
||||
FlavorFlave('id2', 'medium', vcpus=2, disk=100, ram=2000),
|
||||
FlavorFlave('id3', 'large', vcpus=3, disk=750, ram=4000)])
|
||||
|
||||
def test_no_filter(self):
|
||||
"""Check that all flavors are returned."""
|
||||
class TestFlavorField(helpers.APIMockTestCase):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
@mock.patch('muranodashboard.dynamic_ui.fields.nova')
|
||||
def test_no_filter(self, mock_nova):
|
||||
|
||||
# No requirements, should return all flavors
|
||||
mock_nova.novaclient().flavors.list.return_value = [
|
||||
FlavorFlave('id1', 'small', vcpus=1, disk=50, ram=1000),
|
||||
FlavorFlave('id2', 'medium', vcpus=2, disk=100, ram=2000),
|
||||
FlavorFlave('id3', 'large', vcpus=3, disk=750, ram=4000)]
|
||||
|
||||
f = fields.FlavorChoiceField()
|
||||
initial_request = {}
|
||||
f.update(initial_request, self.request)
|
||||
|
@ -54,30 +49,35 @@ class TestFlavorField(helpers.APITestCase):
|
|||
('id1', 'small')
|
||||
], f.choices)
|
||||
|
||||
def test_multiple_filter(self):
|
||||
"""Check that 2 flavors are returned."""
|
||||
@mock.patch('muranodashboard.dynamic_ui.fields.nova')
|
||||
def test_multiple_filter(self, mock_nova):
|
||||
|
||||
self.mox.ReplayAll()
|
||||
mock_nova.novaclient().flavors.list.return_value = [
|
||||
FlavorFlave('id2', 'medium', vcpus=2, disk=100, ram=2000),
|
||||
FlavorFlave('id3', 'large', vcpus=3, disk=750, ram=4000)]
|
||||
|
||||
# Fake a requirement for 2 CPUs, should return medium and large
|
||||
f = fields.FlavorChoiceField(requirements={'min_vcpus': 2})
|
||||
f.update({}, self.request)
|
||||
self.assertEqual([('id3', 'large'), ('id2', 'medium')], f.choices)
|
||||
|
||||
def test_single_filter(self):
|
||||
"""Check that one flavor is returned."""
|
||||
self.mox.ReplayAll()
|
||||
@mock.patch('muranodashboard.dynamic_ui.fields.nova')
|
||||
def test_single_filter(self, mock_nova):
|
||||
|
||||
# Fake a requirement for 2 CPUs and 200 GB disk, should return medium
|
||||
"""Check that one flavor is returned."""
|
||||
mock_nova.novaclient().flavors.list.return_value = [
|
||||
FlavorFlave('id3', 'large', vcpus=3, disk=750, ram=4000)]
|
||||
|
||||
# Fake a requirement for 2 CPUs and 200 GB disk, should return large
|
||||
f = fields.FlavorChoiceField(
|
||||
requirements={'min_vcpus': 2, 'min_disk': 200})
|
||||
initial_request = {}
|
||||
f.update(initial_request, self.request)
|
||||
self.assertEqual([('id3', 'large')], f.choices)
|
||||
|
||||
def test_no_matches_filter(self):
|
||||
"""Check that no flavors are returned."""
|
||||
self.mox.ReplayAll()
|
||||
@mock.patch('muranodashboard.dynamic_ui.fields.nova')
|
||||
def test_no_matches_filter(self, mock_nova):
|
||||
|
||||
mock_nova.novaclient().flavors.list.return_value = []
|
||||
|
||||
# Fake a requirement for 4 CPUs, should return no flavors
|
||||
f = fields.FlavorChoiceField(requirements={'min_vcpus': 4})
|
||||
|
|
|
@ -18,7 +18,7 @@ from muranodashboard.catalog import tabs
|
|||
from openstack_dashboard.test import helpers
|
||||
|
||||
|
||||
class TestLicenseTab(helpers.APITestCase):
|
||||
class TestLicenseTab(helpers.APIMockTestCase):
|
||||
@mock.patch('muranodashboard.catalog.tabs.services')
|
||||
def test_license(self, mock_services):
|
||||
"""Check that a license is returned."""
|
||||
|
@ -66,7 +66,7 @@ class TestLicenseTab(helpers.APITestCase):
|
|||
self.assertEqual('', l.app.license)
|
||||
|
||||
|
||||
class TestRequirementsTab(helpers.APITestCase):
|
||||
class TestRequirementsTab(helpers.APIMockTestCase):
|
||||
@mock.patch('muranodashboard.catalog.tabs.services')
|
||||
def test_requirements(self, mock_services):
|
||||
"""Check that requirements are returned."""
|
||||
|
|
|
@ -29,7 +29,7 @@ from muranodashboard.packages import views
|
|||
from openstack_dashboard.test import helpers
|
||||
|
||||
|
||||
class TestPackageView(helpers.APITestCase):
|
||||
class TestPackageView(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPackageView, self).setUp()
|
||||
|
@ -87,7 +87,7 @@ class TestPackageView(helpers.APITestCase):
|
|||
self.assertFalse(views.is_app(mock_wizard))
|
||||
|
||||
|
||||
class TestDetailView(helpers.APITestCase):
|
||||
class TestDetailView(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDetailView, self).setUp()
|
||||
|
@ -129,7 +129,7 @@ class TestDetailView(helpers.APITestCase):
|
|||
redirect='test_redirect')
|
||||
|
||||
|
||||
class TestModifyPackageView(helpers.APITestCase):
|
||||
class TestModifyPackageView(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestModifyPackageView, self).setUp()
|
||||
|
@ -188,7 +188,7 @@ class TestModifyPackageView(helpers.APITestCase):
|
|||
self.modify_pkg_view.get_form.assert_called_once_with()
|
||||
|
||||
|
||||
class TestImportPackageWizard(helpers.APITestCase):
|
||||
class TestImportPackageWizard(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestImportPackageWizard, self).setUp()
|
||||
|
@ -276,10 +276,10 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
self.assertEqual(val, result[key])
|
||||
|
||||
@mock.patch.object(views, 'exceptions')
|
||||
@mock.patch.object(views, 'glance')
|
||||
@mock.patch.object(views, 'reverse')
|
||||
@mock.patch.object(views, 'glance')
|
||||
@mock.patch.object(views, 'api')
|
||||
def test_done(self, mock_api, mock_reverse, mock_glance, mock_exc):
|
||||
def test_done(self, mock_api, mock_glance, mock_reverse, mock_exc):
|
||||
mock_storage = mock.MagicMock()
|
||||
mock_storage.get_step_data().__getitem__.return_value =\
|
||||
mock.Mock(id='test_package_id')
|
||||
|
@ -580,9 +580,10 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_package_create_exception(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_reverse,
|
||||
mock_messages, mock_exc):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_reverse, mock_messages, mock_exc):
|
||||
mock_murano_utils.Package.from_file.side_effect = None
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
mock_package = mock.Mock()
|
||||
|
@ -637,9 +638,10 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_http_conflict(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_reverse,
|
||||
mock_messages, mock_exc):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_reverse, mock_messages, mock_exc):
|
||||
mock_murano_utils.Package.from_file.side_effect = None
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
|
||||
|
@ -690,9 +692,10 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_http_internal_server_error(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_reverse,
|
||||
mock_exc):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_reverse, mock_exc):
|
||||
mock_murano_utils.Package.from_file.side_effect = None
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
mock_package = mock.Mock()
|
||||
|
@ -732,9 +735,10 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_http_exception(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_dashboard_utils,
|
||||
mock_reverse, mock_exc):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_dashboard_utils, mock_reverse, mock_exc):
|
||||
mock_murano_utils.Package.from_file.side_effect = None
|
||||
mock_reverse.return_value = 'test_redirect'
|
||||
mock_package = mock.Mock()
|
||||
|
@ -778,7 +782,7 @@ class TestImportPackageWizard(helpers.APITestCase):
|
|||
'package': 'test_package'}, kwargs)
|
||||
|
||||
|
||||
class TestImportBundleWizard(helpers.APITestCase):
|
||||
class TestImportBundleWizard(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestImportBundleWizard, self).setUp()
|
||||
|
@ -848,7 +852,8 @@ class TestImportBundleWizard(helpers.APITestCase):
|
|||
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
def test_process_step(self, mock_murano_utils, mock_api):
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step(self, mock_glance, mock_murano_utils, mock_api):
|
||||
mock_bundle = mock.Mock()
|
||||
mock_bundle.package_specs.return_value = [
|
||||
{'Name': 'foo_spec', 'Version': '1.0.0', 'Url': 'www.foo.com'},
|
||||
|
@ -956,8 +961,10 @@ class TestImportBundleWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_http_conflict(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_messages):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_messages):
|
||||
mock_form = mock.Mock(
|
||||
cleaned_data={'import_type': 'by_url', 'url': 'foo_url'})
|
||||
mock_bundle = mock.Mock()
|
||||
|
@ -991,9 +998,10 @@ class TestImportBundleWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranodashboard_utils')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_http_exception(
|
||||
self, mock_murano_utils, mock_dashboard_utils, mock_api, mock_log,
|
||||
mock_messages):
|
||||
self, mock_glance, mock_murano_utils, mock_dashboard_utils,
|
||||
mock_api, mock_log, mock_messages):
|
||||
mock_form = mock.Mock(
|
||||
cleaned_data={'import_type': 'by_url', 'url': 'foo_url'})
|
||||
mock_bundle = mock.Mock()
|
||||
|
@ -1028,8 +1036,10 @@ class TestImportBundleWizard(helpers.APITestCase):
|
|||
@mock.patch.object(views, 'LOG')
|
||||
@mock.patch.object(views, 'api')
|
||||
@mock.patch.object(views, 'muranoclient_utils')
|
||||
@mock.patch.object(views, 'glance')
|
||||
def test_process_step_except_package_create_exception(
|
||||
self, mock_murano_utils, mock_api, mock_log, mock_messages):
|
||||
self, mock_glance, mock_murano_utils, mock_api, mock_log,
|
||||
mock_messages):
|
||||
mock_form = mock.Mock(
|
||||
cleaned_data={'import_type': 'by_url', 'url': 'foo_url'})
|
||||
mock_bundle = mock.Mock()
|
||||
|
@ -1076,7 +1086,7 @@ class TestImportBundleWizard(helpers.APITestCase):
|
|||
'horizon:app-catalog:packages:index')
|
||||
|
||||
|
||||
class TestPackageDefinitionsView(helpers.APITestCase):
|
||||
class TestPackageDefinitionsView(helpers.APIMockTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestPackageDefinitionsView, self).setUp()
|
||||
|
|
Loading…
Reference in New Issue