From 2227c3b9a4cfe1caaf2874c96d0e4b4a1179f62a Mon Sep 17 00:00:00 2001 From: Charles Short Date: Tue, 24 Apr 2018 08:27:16 -0400 Subject: [PATCH] Drop mox3 from TemplateVersionsTests Also fix traceback while running tests against newer versions of horizon. Change-Id: I1100b3856cee1d7678faf65009a60aff5ff1155b Signed-off-by: Charles Short --- heat_dashboard/test/helpers.py | 7 ++++ heat_dashboard/test/settings.py | 1 + .../tests/content/test_template_versions.py | 40 +++++++++---------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/heat_dashboard/test/helpers.py b/heat_dashboard/test/helpers.py index 5091a5f0..d85c1fcf 100644 --- a/heat_dashboard/test/helpers.py +++ b/heat_dashboard/test/helpers.py @@ -44,6 +44,7 @@ from horizon.test import helpers as horizon_helpers from openstack_dashboard import api as project_api from openstack_dashboard import context_processors +from openstack_dashboard.test import helpers from heat_dashboard import api from heat_dashboard.test.test_data import utils as test_utils @@ -51,6 +52,12 @@ from heat_dashboard.test.test_data import utils as test_utils # Makes output of failing mox tests much easier to read. wsgi.WSGIRequest.__repr__ = lambda self: "" +# Shortcuts to avoid importing openstack_dashboard.test.helper and +# for backwards compatibility. +create_mocks = helpers.create_mocks +IsA = helpers.IsA +IsHttpRequest = helpers.IsHttpRequest + def create_stubs(stubs_to_create=None): """decorator to simplify setting up multiple stubs at once via mox diff --git a/heat_dashboard/test/settings.py b/heat_dashboard/test/settings.py index 23e90938..b2671def 100644 --- a/heat_dashboard/test/settings.py +++ b/heat_dashboard/test/settings.py @@ -14,6 +14,7 @@ # Default to Horizons test settings to avoid any missing keys import heat_dashboard.enabled +import openstack_dashboard.enabled # noqa: F811 from openstack_dashboard.test.settings import * # noqa: F403,H303 from openstack_dashboard.utils import settings diff --git a/heat_dashboard/test/tests/content/test_template_versions.py b/heat_dashboard/test/tests/content/test_template_versions.py index fbc6da5c..9f29a066 100644 --- a/heat_dashboard/test/tests/content/test_template_versions.py +++ b/heat_dashboard/test/tests/content/test_template_versions.py @@ -12,70 +12,70 @@ # limitations under the License. from django.core.urlresolvers import reverse -from django import http - -from mox3.mox import IsA from heat_dashboard import api from heat_dashboard.test import helpers as test +from heat_dashboard.test.helpers import IsHttpRequest class TemplateVersionsTests(test.TestCase): INDEX_URL = reverse('horizon:project:template_versions:index') - @test.create_stubs({api.heat: ('template_version_list',)}) + @test.create_mocks({api.heat: ('template_version_list',)}) def test_index(self): - api.heat.template_version_list( - IsA(http.HttpRequest)).AndReturn(self.template_versions.list()) - self.mox.ReplayAll() + self.mock_template_version_list.return_value = \ + self.template_versions.list() res = self.client.get(self.INDEX_URL) + self.mock_template_version_list.assert_called_once_with( + IsHttpRequest()) self.assertTemplateUsed( res, 'project/template_versions/index.html') self.assertContains(res, 'HeatTemplateFormatVersion.2012-12-12') - @test.create_stubs({api.heat: ('template_version_list',)}) + @test.create_mocks({api.heat: ('template_version_list',)}) def test_index_exception(self): - api.heat.template_version_list( - IsA(http.HttpRequest)).AndRaise(self.exceptions.heat) - self.mox.ReplayAll() + self.mock_template_version_list.side_effect = \ + self.exceptions.heat res = self.client.get(self.INDEX_URL) + self.mock_template_version_list.assert_called_once_with( + IsHttpRequest()) self.assertTemplateUsed( res, 'project/template_versions/index.html') self.assertEqual(len(res.context['table'].data), 0) self.assertMessageCount(res, error=1) - @test.create_stubs({api.heat: ('template_function_list',)}) + @test.create_mocks({api.heat: ('template_function_list',)}) def test_detail_view(self): t_version = self.template_versions.first().version t_functions = self.template_functions.list() - api.heat.template_function_list( - IsA(http.HttpRequest), t_version).AndReturn(t_functions) - self.mox.ReplayAll() + self.mock_template_function_list.return_value = t_functions url = reverse('horizon:project:template_versions:details', args=[t_version]) res = self.client.get(url) + self.mock_template_function_list.assert_called_once_with( + IsHttpRequest(), t_version) self.assertTemplateUsed(res, 'horizon/common/_detail.html') self.assertNoMessages() - @test.create_stubs({api.heat: ('template_function_list',)}) + @test.create_mocks({api.heat: ('template_function_list',)}) def test_detail_view_with_exception(self): t_version = self.template_versions.first().version - api.heat.template_function_list( - IsA(http.HttpRequest), t_version).\ - AndRaise(self.exceptions.heat) - self.mox.ReplayAll() + self.mock_template_function_list.side_effect = \ + self.exceptions.heat url = reverse('horizon:project:template_versions:details', args=[t_version]) res = self.client.get(url) + self.mock_template_function_list.assert_called_once_with( + IsHttpRequest(), t_version) self.assertTemplateUsed(res, 'horizon/common/_detail.html') self.assertEqual(len(res.context['table'].data), 0) self.assertMessageCount(res, error=1)