From 4985bfa010b4a9d5627306b275b5b502461eacc5 Mon Sep 17 00:00:00 2001 From: zhurong Date: Thu, 30 Aug 2018 17:24:03 +0800 Subject: [PATCH] Switch test runner to django default runner nose is not actively maintained now and Django default test runner seems to have enough features. Horizon test setting no longer depends on nose and related stuffs. This commit cleans up nose related dependencies. The change was made in horizon Rocky-3, so horizon 14.0.0.0b3 is required at least. And murano-dashboard using unittest instead of testtools. Co-Authored-By: Akihiro Motoki Change-Id: I419e0e166ea88c3ab1203f35ffa00928cf94acb1 Depends-On: https://review.openstack.org/599156/ --- lower-constraints.txt | 4 -- muranodashboard/tests/settings.py | 9 ---- muranodashboard/tests/test_utils.py | 4 +- .../tests/unit/catalog/test_views.py | 24 ++++++---- .../tests/unit/categories/test_views.py | 4 +- muranodashboard/tests/unit/common/test_net.py | 4 +- .../tests/unit/common/test_utils.py | 13 ++--- .../tests/unit/dynamic_ui/test_fields.py | 48 +++++++++++-------- .../tests/unit/dynamic_ui/test_forms.py | 17 +++---- .../tests/unit/dynamic_ui/test_helpers.py | 4 +- .../tests/unit/dynamic_ui/test_versions.py | 4 +- .../unit/dynamic_ui/test_yaql_expression.py | 4 +- .../unit/dynamic_ui/test_yaql_functions.py | 4 +- .../tests/unit/environments/test_forms.py | 4 +- .../tests/unit/environments/test_tables.py | 30 +++++++----- .../tests/unit/environments/test_tabs.py | 24 +++++----- .../tests/unit/environments/test_views.py | 22 ++++----- .../tests/unit/images/test_forms.py | 6 +-- .../tests/unit/images/test_views.py | 8 ++-- .../tests/unit/packages/test_tables.py | 14 +++--- test-requirements.txt | 5 -- tox.ini | 7 +-- 22 files changed, 130 insertions(+), 133 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 86fb9363e..0cc1f5090 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -22,7 +22,6 @@ django-babel==0.6.2 django-compressor==2.0 django-floppyforms==1.7.0 django-formtools==2.0 -django-nose==1.4.4 django-pyscss==2.0.2 docutils==0.14 dogpile.cache==0.6.5 @@ -54,9 +53,6 @@ murano-pkg-check==0.3.0 netaddr==0.7.19 netifaces==0.10.6 nodeenv==0.9.4 -nose==1.3.7 -nosehtmloutput==0.0.3 -openstack.nose-plugin==0.7 openstackdocstheme==1.18.1 openstacksdk==0.12.0 os-client-config==1.29.0 diff --git a/muranodashboard/tests/settings.py b/muranodashboard/tests/settings.py index 37d8f3567..20af5b048 100644 --- a/muranodashboard/tests/settings.py +++ b/muranodashboard/tests/settings.py @@ -29,11 +29,6 @@ TESTSERVER = 'http://testserver' MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' -NOSE_ARGS = ['--nocapture', - '--nologcapture', - '--cover-package=muranodashboard'] - EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' SESSION_ENGINE = 'django.contrib.sessions.backends.cache' @@ -74,9 +69,5 @@ LOGGING = { 'handlers': ['null'], 'propagate': False, }, - 'nose.plugins.manager': { - 'handlers': ['null'], - 'propagate': False, - } } } diff --git a/muranodashboard/tests/test_utils.py b/muranodashboard/tests/test_utils.py index df144959b..ee4cb8ab1 100644 --- a/muranodashboard/tests/test_utils.py +++ b/muranodashboard/tests/test_utils.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools +import unittest from muranodashboard.common import utils -class BunchTests(testtools.TestCase): +class TestBunch(unittest.TestCase): def test_get_attr(self): obj = utils.Bunch(one=10) diff --git a/muranodashboard/tests/unit/catalog/test_views.py b/muranodashboard/tests/unit/catalog/test_views.py index 17958838e..0ac18e578 100644 --- a/muranodashboard/tests/unit/catalog/test_views.py +++ b/muranodashboard/tests/unit/catalog/test_views.py @@ -14,7 +14,7 @@ import collections import mock -import testtools +import unittest from django.conf import settings from django.forms import formsets @@ -34,7 +34,7 @@ except ImportError: from urllib.parse import urlparse -class TestCatalogViews(testtools.TestCase): +class TestCatalogViews(unittest.TestCase): def setUp(self): super(TestCatalogViews, self).setUp() self.mock_request = mock.MagicMock(session={}) @@ -177,7 +177,7 @@ class TestCatalogViews(testtools.TestCase): **expected_params) -class TestLazyWizard(testtools.TestCase): +class TestLazyWizard(unittest.TestCase): @mock.patch.object(views.LazyWizard, 'http_method_names', new_callable=mock.PropertyMock) @@ -189,16 +189,20 @@ class TestLazyWizard(testtools.TestCase): expected_error_msg = "You tried to pass in the {0} method name as a "\ "keyword argument to LazyWizard(). "\ "Don't do that.".format("patch") - e = self.assertRaises(TypeError, views.LazyWizard.as_view, - None, **kwargs) + + with self.assertRaises(TypeError) as cm: + views.LazyWizard.as_view(None, **kwargs) + e = cm.exception self.assertEqual(expected_error_msg, str(e)) # Test that second occurrence of type error is thrown. kwargs = {'foobar': ''} expected_error_msg = "LazyWizard() received an invalid keyword "\ "'foobar'" - e = self.assertRaises(TypeError, views.LazyWizard.as_view, - None, **kwargs) + + with self.assertRaises(TypeError) as cm: + views.LazyWizard.as_view(None, **kwargs) + e = cm.exception self.assertEqual(expected_error_msg, str(e)) @mock.patch.object(views.LazyWizard, 'dispatch') @@ -220,7 +224,7 @@ class TestLazyWizard(testtools.TestCase): mock_dispatch.assert_called_once_with(mock_request, **kwargs) -class TestWizard(testtools.TestCase): +class TestWizard(unittest.TestCase): def setUp(self): super(TestWizard, self).setUp() @@ -488,7 +492,7 @@ class TestWizard(testtools.TestCase): mock_nova.flavor_list.assert_called_once_with(self.wizard.request) -class TestIndexView(testtools.TestCase): +class TestIndexView(unittest.TestCase): def setUp(self): super(TestIndexView, self).setUp() @@ -669,7 +673,7 @@ class TestIndexView(testtools.TestCase): 'horizon:app-catalog:packages:index') -class TestAppDetailsView(testtools.TestCase): +class TestAppDetailsView(unittest.TestCase): def setUp(self): super(TestAppDetailsView, self).setUp() diff --git a/muranodashboard/tests/unit/categories/test_views.py b/muranodashboard/tests/unit/categories/test_views.py index efe114418..584efe3b4 100644 --- a/muranodashboard/tests/unit/categories/test_views.py +++ b/muranodashboard/tests/unit/categories/test_views.py @@ -13,13 +13,13 @@ # under the License. import mock -import testtools +import unittest from muranodashboard.categories import tables from muranodashboard.categories import views -class TestCategoriesView(testtools.TestCase): +class TestCategoriesView(unittest.TestCase): def setUp(self): super(TestCategoriesView, self).setUp() diff --git a/muranodashboard/tests/unit/common/test_net.py b/muranodashboard/tests/unit/common/test_net.py index 5115c968a..6e698dc42 100644 --- a/muranodashboard/tests/unit/common/test_net.py +++ b/muranodashboard/tests/unit/common/test_net.py @@ -13,14 +13,14 @@ # under the License. import mock -import testtools +import unittest from horizon import exceptions from muranodashboard.common import net -class TestNet(testtools.TestCase): +class TestNet(unittest.TestCase): def setUp(self): super(TestNet, self).setUp() diff --git a/muranodashboard/tests/unit/common/test_utils.py b/muranodashboard/tests/unit/common/test_utils.py index 273f62176..416ae2207 100644 --- a/muranodashboard/tests/unit/common/test_utils.py +++ b/muranodashboard/tests/unit/common/test_utils.py @@ -18,14 +18,14 @@ except ImportError: import pickle import mock -import testtools +import unittest import yaql from muranodashboard.common import utils from muranodashboard.dynamic_ui import yaql_expression -class TestUtils(testtools.TestCase): +class TestUtils(unittest.TestCase): def test_parse_api_error(self): test_html = '

Foo Header

Foo Error ' @@ -36,7 +36,7 @@ class TestUtils(testtools.TestCase): self.assertIsNone(utils.parse_api_error(test_html)) -class TestCustomPickler(testtools.TestCase): +class TestCustomPickler(unittest.TestCase): def setUp(self): super(TestCustomPickler, self).setUp() @@ -53,7 +53,7 @@ class TestCustomPickler(testtools.TestCase): self.assertIsNone(self.custom_pickler.persistent_id(None)) -class TestCustomUnpickler(testtools.TestCase): +class TestCustomUnpickler(unittest.TestCase): def setUp(self): super(TestCustomUnpickler, self).setUp() @@ -67,6 +67,7 @@ class TestCustomUnpickler(testtools.TestCase): self.assertEqual(yaql_expression.YAQL, result) def test_persistent_load_with_wrong_obj_type(self): - e = self.assertRaises(pickle.UnpicklingError, - self.custom_unpickler.persistent_load, None) + with self.assertRaises(pickle.UnpicklingError) as cm: + self.custom_unpickler.persistent_load(None) + e = cm.exception self.assertEqual('Invalid persistent id', str(e)) diff --git a/muranodashboard/tests/unit/dynamic_ui/test_fields.py b/muranodashboard/tests/unit/dynamic_ui/test_fields.py index 84ef171a6..95d30a160 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_fields.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_fields.py @@ -18,12 +18,12 @@ from django import forms from django.utils.translation import ugettext_lazy as _ import mock -import testtools +import unittest from muranodashboard.dynamic_ui import fields -class TestFields(testtools.TestCase): +class TestFields(unittest.TestCase): def setUp(self): super(TestFields, self).setUp() @@ -62,9 +62,10 @@ class TestFields(testtools.TestCase): @mock.patch.object(fields, 'LOG') def test_fields_except_validation_error(self, mock_log): - with self.assertRaisesRegex(forms.ValidationError, - "Can't get a request information"): + with self.assertRaises(forms.ValidationError) as cm: self._test_fields_decorator_with_validation_error({}, request=None) + e = cm.exception + self.assertEqual("Can't get a request information", e.message) mock_log.error.assert_called_once_with( "No 'request' value passed neither via initial dictionary, nor " "directly") @@ -92,7 +93,9 @@ class TestFields(testtools.TestCase): validator_func = fields.make_yaql_validator(mock_validator_property) self.assertTrue(hasattr(validator_func, '__call__')) - e = self.assertRaises(forms.ValidationError, validator_func, 'bar') + with self.assertRaises(forms.ValidationError) as cm: + validator_func('bar') + e = cm.exception self.assertEqual('foo_message', e.message) def test_get_regex_validator(self): @@ -124,9 +127,11 @@ class TestFields(testtools.TestCase): def _validator(value): raise forms.ValidationError(None) - with self.assertRaisesRegex(forms.ValidationError, 'foo'): + with self.assertRaises(forms.ValidationError) as cm: func = fields.wrap_regex_validator(_validator, 'foo') func(None) + e = cm.exception + self.assertEqual('foo', e.message) @mock.patch.object(fields, 'glance') def test_get_murano_images(self, mock_glance): @@ -328,7 +333,7 @@ class TestFields(testtools.TestCase): self.assertEqual('value', dynamic_select.clean('value')) -class TestRawProperty(testtools.TestCase): +class TestRawProperty(unittest.TestCase): def test_finalize(self): class Control(object): @@ -366,7 +371,7 @@ class TestRawProperty(testtools.TestCase): self.assertNotIn('prop', ctl.__dict__) -class TestCustomPropertiesField(testtools.TestCase): +class TestCustomPropertiesField(unittest.TestCase): def setUp(self): super(TestCustomPropertiesField, self).setUp() @@ -421,7 +426,7 @@ class TestCustomPropertiesField(testtools.TestCase): self.assertIsNotNone(result) -class TestPasswordField(testtools.TestCase): +class TestPasswordField(unittest.TestCase): def setUp(self): super(TestPasswordField, self).setUp() @@ -470,7 +475,7 @@ class TestPasswordField(testtools.TestCase): self.assertEqual('Retype your password', result.help_text) -class TestFlavorChoiceField(testtools.TestCase): +class TestFlavorChoiceField(unittest.TestCase): def setUp(self): super(TestFlavorChoiceField, self).setUp() @@ -551,7 +556,7 @@ class TestFlavorChoiceField(testtools.TestCase): self.assertEqual('id3', self.flavor_choice_field.initial) -class TestKeyPairChoiceField(testtools.TestCase): +class TestKeyPairChoiceField(unittest.TestCase): def setUp(self): super(TestKeyPairChoiceField, self).setUp() @@ -578,7 +583,7 @@ class TestKeyPairChoiceField(testtools.TestCase): sorted(key_pair_choice_field.choices)) -class TestSecurityGroupChoiceField(testtools.TestCase): +class TestSecurityGroupChoiceField(unittest.TestCase): def setUp(self): super(TestSecurityGroupChoiceField, self).setUp() @@ -603,7 +608,7 @@ class TestSecurityGroupChoiceField(testtools.TestCase): sorted(security_group_choice_field.choices)) -class TestImageChoiceField(testtools.TestCase): +class TestImageChoiceField(unittest.TestCase): def setUp(self): super(TestImageChoiceField, self).setUp() @@ -645,7 +650,7 @@ class TestImageChoiceField(testtools.TestCase): self.assertEqual(expected_choices, image_choice_field.choices) -class TestNetworkChoiceField(testtools.TestCase): +class TestNetworkChoiceField(unittest.TestCase): def setUp(self): super(TestNetworkChoiceField, self).setUp() @@ -677,7 +682,7 @@ class TestNetworkChoiceField(testtools.TestCase): self.network_choice_field.to_python(None)) -class TestVolumeChoiceField(testtools.TestCase): +class TestVolumeChoiceField(unittest.TestCase): def setUp(self): super(TestVolumeChoiceField, self).setUp() @@ -818,7 +823,7 @@ class TestVolumeChoiceField(testtools.TestCase): mock_exceptions.handle.assert_has_calls(expected_calls) -class TestAZoneChoiceField(testtools.TestCase): +class TestAZoneChoiceField(unittest.TestCase): @mock.patch.object(fields, 'nova') def test_update(self, mock_nova): @@ -852,7 +857,7 @@ class TestAZoneChoiceField(testtools.TestCase): mock_exc.handle.assert_called_once_with(request['request'], mock.ANY) -class TestBooleanField(testtools.TestCase): +class TestBooleanField(unittest.TestCase): def test_boolean_field(self): class Widget(object): @@ -870,7 +875,7 @@ class TestBooleanField(testtools.TestCase): self.assertFalse(boolean_field.required) -class TestDatabaseListField(testtools.TestCase): +class TestDatabaseListField(unittest.TestCase): def setUp(self): super(TestDatabaseListField, self).setUp() @@ -893,12 +898,13 @@ class TestDatabaseListField(testtools.TestCase): expected_error = "First symbol should be latin letter or underscore. "\ "Subsequent symbols can be latin letter, numeric, "\ "underscore, at sign, number sign or dollar sign" - e = self.assertRaises(exceptions.ValidationError, - self.database_list_field.validate, invalid_value) + with self.assertRaises(exceptions.ValidationError) as cm: + self.database_list_field.validate(invalid_value) + e = cm.exception self.assertEqual(expected_error, e.message) -class TestErrorWidget(testtools.TestCase): +class TestErrorWidget(unittest.TestCase): def test_render(self): error_widget = fields.ErrorWidget() diff --git a/muranodashboard/tests/unit/dynamic_ui/test_forms.py b/muranodashboard/tests/unit/dynamic_ui/test_forms.py index d8f81ee07..41cbc8a50 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_forms.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_forms.py @@ -14,7 +14,7 @@ import collections import mock -import testtools +import unittest from yaql.language import contexts as yaql_contexts from django import forms as django_forms @@ -24,7 +24,7 @@ from muranodashboard.dynamic_ui import forms from muranodashboard.dynamic_ui import yaql_expression -class TestAnyFieldDict(testtools.TestCase): +class TestAnyFieldDict(unittest.TestCase): def test_missing(self): any_field_dict = forms.AnyFieldDict() @@ -32,7 +32,7 @@ class TestAnyFieldDict(testtools.TestCase): self.assertEqual('DynamicSelect', result.__name__) -class TestDynamicUiForm(testtools.TestCase): +class TestDynamicUiForm(unittest.TestCase): def test_collect_fields_process_widget(self): test_spec = { @@ -84,7 +84,7 @@ class TestDynamicUiForm(testtools.TestCase): self.assertEqual(mock_yaql, field.validators[0]['expr'].spec) -class TestDynamicFormMetaclass(testtools.TestCase): +class TestDynamicFormMetaclass(unittest.TestCase): def test_new(self): test_dict = { @@ -102,7 +102,7 @@ class TestDynamicFormMetaclass(testtools.TestCase): fields.CharField) -class TestUpdatableFieldsForm(testtools.TestCase): +class TestUpdatableFieldsForm(unittest.TestCase): def setUp(self): super(TestUpdatableFieldsForm, self).setUp() @@ -141,7 +141,7 @@ class TestUpdatableFieldsForm(testtools.TestCase): self.assertTrue(mock_password_field.update.called) -class TestServiceConfigurationForm(testtools.TestCase): +class TestServiceConfigurationForm(unittest.TestCase): def setUp(self): super(TestServiceConfigurationForm, self).setUp() @@ -194,9 +194,10 @@ class TestServiceConfigurationForm(testtools.TestCase): test_validator = {'expr': mock_expr, 'message': 'Foo Error'} self.form.validators = [test_validator] - with self.assertRaisesRegex(django_forms.ValidationError, - 'Foo Error'): + with self.assertRaises(django_forms.ValidationError) as cm: self.form.clean() + e = cm.exception + self.assertIn('Foo Error', e.messages) self.form.service.update_cleaned_data.assert_called_once_with( {'foo': 'bar', 'baz': 'qux'}, form=self.form) diff --git a/muranodashboard/tests/unit/dynamic_ui/test_helpers.py b/muranodashboard/tests/unit/dynamic_ui/test_helpers.py index 4cf365143..142131942 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_helpers.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_helpers.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools +import unittest from muranodashboard.dynamic_ui import helpers -class TestHelper(testtools.TestCase): +class TestHelper(unittest.TestCase): def test_to_str(self): names = ['string', b'ascii', u'ascii', u'\u043d\u0435 \u0430\u0441\u043a\u0438'] diff --git a/muranodashboard/tests/unit/dynamic_ui/test_versions.py b/muranodashboard/tests/unit/dynamic_ui/test_versions.py index b46d02a1e..27fe24577 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_versions.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_versions.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools +import unittest from muranodashboard.dynamic_ui import version -class TestVersions(testtools.TestCase): +class TestVersions(unittest.TestCase): def setUp(self): super(TestVersions, self).setUp() self.original = version.LATEST_FORMAT_VERSION diff --git a/muranodashboard/tests/unit/dynamic_ui/test_yaql_expression.py b/muranodashboard/tests/unit/dynamic_ui/test_yaql_expression.py index abab0714b..4a7593160 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_yaql_expression.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_yaql_expression.py @@ -12,12 +12,12 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools +import unittest from muranodashboard.dynamic_ui import yaql_expression -class TestYaqlExpression(testtools.TestCase): +class TestYaqlExpression(unittest.TestCase): def setUp(self): super(TestYaqlExpression, self).setUp() diff --git a/muranodashboard/tests/unit/dynamic_ui/test_yaql_functions.py b/muranodashboard/tests/unit/dynamic_ui/test_yaql_functions.py index cf8f02cfc..7d8eaad61 100644 --- a/muranodashboard/tests/unit/dynamic_ui/test_yaql_functions.py +++ b/muranodashboard/tests/unit/dynamic_ui/test_yaql_functions.py @@ -14,7 +14,7 @@ import mock import re -import testtools +import unittest from castellan.common import exception as castellan_exception from castellan.common.objects import opaque_data @@ -23,7 +23,7 @@ from muranodashboard.dynamic_ui import helpers from muranodashboard.dynamic_ui import yaql_functions -class TestYAQLFunctions(testtools.TestCase): +class TestYAQLFunctions(unittest.TestCase): def test_generate_hostname(self): self.assertEqual( diff --git a/muranodashboard/tests/unit/environments/test_forms.py b/muranodashboard/tests/unit/environments/test_forms.py index b25316c2e..826800722 100644 --- a/muranodashboard/tests/unit/environments/test_forms.py +++ b/muranodashboard/tests/unit/environments/test_forms.py @@ -13,7 +13,7 @@ # under the License. import mock -import testtools +import unittest from django.utils.translation import ugettext_lazy as _ @@ -21,7 +21,7 @@ from muranoclient.common import exceptions as exc from muranodashboard.environments import forms as env_forms -class TestCreateEnvForm(testtools.TestCase): +class TestCreateEnvForm(unittest.TestCase): def setUp(self): super(TestCreateEnvForm, self).setUp() self.mock_request = mock.MagicMock() diff --git a/muranodashboard/tests/unit/environments/test_tables.py b/muranodashboard/tests/unit/environments/test_tables.py index 8c6b6eced..bfdb78abb 100644 --- a/muranodashboard/tests/unit/environments/test_tables.py +++ b/muranodashboard/tests/unit/environments/test_tables.py @@ -15,7 +15,7 @@ import ast from django import http as django_http import mock -import testtools +import unittest from horizon import tables as hz_tables @@ -25,7 +25,7 @@ from muranodashboard.environments import tables from muranodashboard.packages import consts as pkg_consts -class TestEnvironmentTables(testtools.TestCase): +class TestEnvironmentTables(unittest.TestCase): def test_check_row_actions_allowed(self): actions = mock.Mock() actions.table.data = None @@ -359,7 +359,7 @@ class TestEnvironmentTables(testtools.TestCase): self.assertEqual('foo_name', tables.get_service_type(test_datum)) -class TestUpdateEnvironmentRow(testtools.TestCase): +class TestUpdateEnvironmentRow(unittest.TestCase): def setUp(self): super(TestUpdateEnvironmentRow, self).setUp() @@ -403,8 +403,10 @@ class TestUpdateEnvironmentRow(testtools.TestCase): data_table = tables.UpdateEnvironmentRow(self.mock_data_table) - with self.assertRaisesRegex(django_http.Http404, None): + with self.assertRaises(django_http.Http404) as cm: data_table.get_data(None, 'foo_environment_id') + e = cm.exception + self.assertEqual('', str(e)) @mock.patch.object(tables, 'api') def test_get_data_except_exception(self, mock_api): @@ -412,11 +414,13 @@ class TestUpdateEnvironmentRow(testtools.TestCase): data_table = tables.UpdateEnvironmentRow(self.mock_data_table) - with self.assertRaisesRegex(Exception, 'foo_error'): + with self.assertRaises(Exception) as cm: data_table.get_data(None, 'foo_environment_id') + e = cm.exception + self.assertEqual('foo_error', str(e)) -class TestUpdateServiceRow(testtools.TestCase): +class TestUpdateServiceRow(unittest.TestCase): def setUp(self): super(TestUpdateServiceRow, self).setUp() @@ -437,7 +441,7 @@ class TestUpdateServiceRow(testtools.TestCase): None, 'foo_env_id', 'foo_service_id') -class TestUpdateEnvMetadata(testtools.TestCase): +class TestUpdateEnvMetadata(unittest.TestCase): def test_update_env_meta_data(self): kwargs = {'datum': 'foo_datum'} @@ -508,7 +512,7 @@ class TestUpdateEnvMetadata(testtools.TestCase): None, 'foo_env_id') -class TestEnvironmentsTable(testtools.TestCase): +class TestEnvironmentsTable(unittest.TestCase): @mock.patch.object(tables, 'reverse') @mock.patch.object(tables, 'policy') @@ -531,7 +535,7 @@ class TestEnvironmentsTable(testtools.TestCase): "horizon:app-catalog:environments:services", args=('foo_env_id',)) -class TestUpdateMetadata(testtools.TestCase): +class TestUpdateMetadata(unittest.TestCase): def setUp(self): super(TestUpdateMetadata, self).setUp() @@ -610,7 +614,7 @@ class TestUpdateMetadata(testtools.TestCase): None, 'foo_env_id') -class TestServicesTable(testtools.TestCase): +class TestServicesTable(unittest.TestCase): def test_get_object_id(self): test_datum = {'?': {'id': 'foo'}} @@ -728,7 +732,7 @@ class TestServicesTable(testtools.TestCase): 'horizon:app-catalog:packages:index') -class TestShowDeploymentDetails(testtools.TestCase): +class TestShowDeploymentDetails(unittest.TestCase): @mock.patch.object(tables, 'reverse') def test_get_link_url(self, mock_reverse): @@ -750,7 +754,7 @@ class TestShowDeploymentDetails(testtools.TestCase): self.assertTrue(show_deployment_details.allowed(None, None)) -class TestEnvConfigTable(testtools.TestCase): +class TestEnvConfigTable(unittest.TestCase): def test_get_object_id(self): env_config_table = tables.EnvConfigTable(None) @@ -758,7 +762,7 @@ class TestEnvConfigTable(testtools.TestCase): '?': {'id': 'foo'}})) -class TestDeploymentHistoryTable(testtools.TestCase): +class TestDeploymentHistoryTable(unittest.TestCase): def setUp(self): super(TestDeploymentHistoryTable, self).setUp() diff --git a/muranodashboard/tests/unit/environments/test_tabs.py b/muranodashboard/tests/unit/environments/test_tabs.py index e891f4093..17e37ac90 100644 --- a/muranodashboard/tests/unit/environments/test_tabs.py +++ b/muranodashboard/tests/unit/environments/test_tabs.py @@ -14,7 +14,7 @@ import collections import mock -import testtools +import unittest from django.conf import settings from django.utils.translation import ugettext_lazy as _ @@ -24,7 +24,7 @@ from muranodashboard.environments import tables from muranodashboard.environments import tabs -class TestOverviewTab(testtools.TestCase): +class TestOverviewTab(unittest.TestCase): def setUp(self): super(TestOverviewTab, self).setUp() @@ -223,7 +223,7 @@ class TestOverviewTab(testtools.TestCase): mock_heat_api.stacks_list.mock_calls) -class TestServiceLogsTab(testtools.TestCase): +class TestServiceLogsTab(unittest.TestCase): def setUp(self): super(TestServiceLogsTab, self).setUp() @@ -253,7 +253,7 @@ class TestServiceLogsTab(testtools.TestCase): mock_request, 'foo_service_id', 'foo_environment_id') -class TestEnvLogsTab(testtools.TestCase): +class TestEnvLogsTab(unittest.TestCase): def setUp(self): super(TestEnvLogsTab, self).setUp() @@ -280,7 +280,7 @@ class TestEnvLogsTab(testtools.TestCase): self.assertEqual({'reports': [mock_report]}, reports) -class TestLatestLogTab(testtools.TestCase): +class TestLatestLogTab(unittest.TestCase): def test_allowed(self): mock_request = mock.MagicMock() @@ -295,7 +295,7 @@ class TestLatestLogTab(testtools.TestCase): self.assertEqual([mock_report], latest_logs_tab.allowed(mock_request)) -class TestEnvConfigTab(testtools.TestCase): +class TestEnvConfigTab(unittest.TestCase): def setUp(self): super(TestEnvConfigTab, self).setUp() @@ -322,7 +322,7 @@ class TestEnvConfigTab(testtools.TestCase): self.assertEqual(['foo_service'], result) -class TestEnvironmentTopologyTab(testtools.TestCase): +class TestEnvironmentTopologyTab(unittest.TestCase): def setUp(self): super(TestEnvironmentTopologyTab, self).setUp() @@ -360,7 +360,7 @@ class TestEnvironmentTopologyTab(testtools.TestCase): @mock.patch.object(tabs, 'api') -class TestEnvironmentServicesTab(testtools.TestCase): +class TestEnvironmentServicesTab(unittest.TestCase): def setUp(self): super(TestEnvironmentServicesTab, self).setUp() @@ -446,7 +446,7 @@ class TestEnvironmentServicesTab(testtools.TestCase): @mock.patch.object(tabs, 'api') -class TestDeploymentTab(testtools.TestCase): +class TestDeploymentTab(unittest.TestCase): def setUp(self): super(TestDeploymentTab, self).setUp() @@ -511,7 +511,7 @@ class TestDeploymentTab(testtools.TestCase): "horizon:app-catalog:environments:index") -class TestEnvironmentDetailsTabs(testtools.TestCase): +class TestEnvironmentDetailsTabs(unittest.TestCase): @mock.patch.object(tabs, 'api') def test_init(self, mock_api): @@ -533,7 +533,7 @@ class TestEnvironmentDetailsTabs(testtools.TestCase): self.assertTrue(env_details_tabs.sticky) -class TestServicesTabs(testtools.TestCase): +class TestServicesTabs(unittest.TestCase): def test_init(self): mock_request = mock.Mock(GET={}) @@ -546,7 +546,7 @@ class TestServicesTabs(testtools.TestCase): self.assertTrue(services_tabs.sticky) -class TestDeploymentDetailsTabs(testtools.TestCase): +class TestDeploymentDetailsTabs(unittest.TestCase): def test_init(self): mock_request = mock.Mock(GET={}) diff --git a/muranodashboard/tests/unit/environments/test_views.py b/muranodashboard/tests/unit/environments/test_views.py index 2fa73c9c6..8e14dd78d 100644 --- a/muranodashboard/tests/unit/environments/test_views.py +++ b/muranodashboard/tests/unit/environments/test_views.py @@ -18,7 +18,7 @@ from django import http from django.utils.translation import ugettext_lazy as _ import mock import sys -import testtools +import unittest from horizon import conf @@ -31,7 +31,7 @@ from muranodashboard.environments import views @mock.patch.object(views, 'exceptions') @mock.patch.object(views, 'api') -class TestIndexView(testtools.TestCase): +class TestIndexView(unittest.TestCase): def setUp(self): super(TestIndexView, self).setUp() @@ -72,7 +72,7 @@ class TestIndexView(testtools.TestCase): self.index_view.request, ignore=True, escalate=True) -class TestEnvironmentDetails(testtools.TestCase): +class TestEnvironmentDetails(unittest.TestCase): def setUp(self): super(TestEnvironmentDetails, self).setUp() @@ -159,7 +159,7 @@ class TestEnvironmentDetails(testtools.TestCase): @mock.patch.object(views, 'api') -class TestDetailServiceView(testtools.TestCase): +class TestDetailServiceView(unittest.TestCase): def setUp(self): super(TestDetailServiceView, self).setUp() @@ -240,7 +240,7 @@ class TestDetailServiceView(testtools.TestCase): self.assertIsInstance(result, env_tabs.ServicesTabs) -class TestCreateEnvironmentView(testtools.TestCase): +class TestCreateEnvironmentView(unittest.TestCase): def setUp(self): super(TestCreateEnvironmentView, self).setUp() @@ -303,7 +303,7 @@ class TestCreateEnvironmentView(testtools.TestCase): @mock.patch.object(views, 'reverse') @mock.patch.object(views, 'api') -class TestDeploymentDetailsView(testtools.TestCase): +class TestDeploymentDetailsView(unittest.TestCase): def setUp(self): super(TestDeploymentDetailsView, self).setUp() @@ -422,7 +422,7 @@ class TestDeploymentDetailsView(testtools.TestCase): self.assertIsInstance(result, env_tabs.DeploymentDetailsTabs) -class TestJSONView(testtools.TestCase): +class TestJSONView(unittest.TestCase): @mock.patch.object(views, 'api') def test_get(self, mock_api): @@ -438,7 +438,7 @@ class TestJSONView(testtools.TestCase): 'foo_env_id') -class TestJSONResponse(testtools.TestCase): +class TestJSONResponse(unittest.TestCase): def test_init(self): kwargs = {'content_type': 'json'} @@ -451,7 +451,7 @@ class TestJSONResponse(testtools.TestCase): self.assertEqual(b'"foo"', json_response.content) -class TestStartActionView(testtools.TestCase): +class TestStartActionView(unittest.TestCase): @mock.patch.object(views, 'reverse') @mock.patch.object(views, 'api') @@ -475,7 +475,7 @@ class TestStartActionView(testtools.TestCase): mock_api.action_allowed.assert_called_with(mock_request, 'foo_env_id') -class TestActionResultView(testtools.TestCase): +class TestActionResultView(unittest.TestCase): def test_is_file_returned(self): test_result = {'result': {'?': {'type': 'io.murano.File'}}} @@ -568,7 +568,7 @@ class TestActionResultView(testtools.TestCase): assert_called_once_with('foo_env_id', 'foo_task_id') -class TestDeploymentHistoryView(testtools.TestCase): +class TestDeploymentHistoryView(unittest.TestCase): def setUp(self): super(TestDeploymentHistoryView, self).setUp() diff --git a/muranodashboard/tests/unit/images/test_forms.py b/muranodashboard/tests/unit/images/test_forms.py index 09d4faff2..bfa647504 100644 --- a/muranodashboard/tests/unit/images/test_forms.py +++ b/muranodashboard/tests/unit/images/test_forms.py @@ -13,14 +13,14 @@ # under the License. import mock -import testtools +import unittest from django.utils.translation import ugettext_lazy as _ from muranodashboard.images import forms -class TestImagesForms(testtools.TestCase): +class TestImagesForms(unittest.TestCase): def setUp(self): super(TestImagesForms, self).setUp() metadata = '{"title": "title", "type": "type"}' @@ -49,7 +49,7 @@ class TestImagesForms(testtools.TestCase): forms.filter_murano_images(images, self.mock_request)) -class TestMarkImageForm(testtools.TestCase): +class TestMarkImageForm(unittest.TestCase): def setUp(self): super(TestMarkImageForm, self).setUp() self.mock_request = mock.MagicMock() diff --git a/muranodashboard/tests/unit/images/test_views.py b/muranodashboard/tests/unit/images/test_views.py index b9826bc64..1cc040788 100644 --- a/muranodashboard/tests/unit/images/test_views.py +++ b/muranodashboard/tests/unit/images/test_views.py @@ -14,7 +14,7 @@ import json import mock -import testtools +import unittest from horizon import exceptions @@ -22,7 +22,7 @@ from muranodashboard.images import tables from muranodashboard.images import views -class TestMarkedImagesView(testtools.TestCase): +class TestMarkedImagesView(unittest.TestCase): def setUp(self): super(TestMarkedImagesView, self).setUp() @@ -170,7 +170,9 @@ class TestMarkedImagesView(testtools.TestCase): mock_reverse.return_value = 'foo_reverse_url' self.images_view.request.GET.get.return_value = None - e = self.assertRaises(exceptions.Http302, self.images_view.get_data) + with self.assertRaises(exceptions.Http302) as cm: + self.images_view.get_data() + e = cm.exception self.assertEqual('foo_reverse_url', e.location) mock_glance.glanceclient.assert_called_once_with( diff --git a/muranodashboard/tests/unit/packages/test_tables.py b/muranodashboard/tests/unit/packages/test_tables.py index edb617f27..b4f939236 100644 --- a/muranodashboard/tests/unit/packages/test_tables.py +++ b/muranodashboard/tests/unit/packages/test_tables.py @@ -13,7 +13,7 @@ # under the License. import mock -import testtools +import unittest from django.utils.translation import ugettext_lazy as _ @@ -21,7 +21,7 @@ from muranoclient.common import exceptions as exc from muranodashboard.packages import tables -class TestImportPackage(testtools.TestCase): +class TestImportPackage(unittest.TestCase): def setUp(self): super(TestImportPackage, self).setUp() @@ -47,7 +47,7 @@ class TestImportPackage(testtools.TestCase): self.assertFalse(self.import_package.allowed(None, None)) -class TestDownloadPackage(testtools.TestCase): +class TestDownloadPackage(unittest.TestCase): def setUp(self): super(TestDownloadPackage, self).setUp() @@ -79,7 +79,7 @@ class TestDownloadPackage(testtools.TestCase): args=('foo-app', 'foo_app_id')) -class TestToggleEnabled(testtools.TestCase): +class TestToggleEnabled(unittest.TestCase): def setUp(self): super(TestToggleEnabled, self).setUp() @@ -142,7 +142,7 @@ class TestToggleEnabled(testtools.TestCase): 'horizon:app-catalog:packages:index') -class TestTogglePublicEnabled(testtools.TestCase): +class TestTogglePublicEnabled(unittest.TestCase): def setUp(self): super(TestTogglePublicEnabled, self).setUp() @@ -231,7 +231,7 @@ class TestTogglePublicEnabled(testtools.TestCase): 'horizon:app-catalog:packages:index') -class TestDeletePackage(testtools.TestCase): +class TestDeletePackage(unittest.TestCase): def setUp(self): super(TestDeletePackage, self).setUp() @@ -330,7 +330,7 @@ class TestDeletePackage(testtools.TestCase): 'horizon:app-catalog:packages:index') -class TestModifyPackage(testtools.TestCase): +class TestModifyPackage(unittest.TestCase): def setUp(self): super(TestModifyPackage, self).setUp() diff --git a/test-requirements.txt b/test-requirements.txt index 5499352c6..47bf4d628 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -4,14 +4,9 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 -django-nose>=1.4.4 # BSD -nose>=1.3.7 # LGPL oslo.config>=5.2.0 # Apache-2.0 -openstack.nose-plugin>=0.7 # Apache-2.0 -nosehtmloutput>=0.0.3 # Apache-2.0 selenium>=2.50.1 # Apache-2.0 -testtools>=2.2.0 # MIT mock>=2.0.0 # BSD # Docs Requirements diff --git a/tox.ini b/tox.ini index 42908d05b..1564970e0 100644 --- a/tox.ini +++ b/tox.ini @@ -6,11 +6,6 @@ skipsdist = True [testenv] usedevelop = True setenv = VIRTUAL_ENV={envdir} - NOSE_WITH_OPENSTACK=1 - NOSE_OPENSTACK_COLOR=1 - NOSE_OPENSTACK_RED=0.05 - NOSE_OPENSTACK_YELLOW=0.025 - NOSE_OPENSTACK_SHOW_ELAPSED=1 DJANGO_SETTINGS_MODULE=muranodashboard.tests.settings passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY deps = -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} @@ -68,6 +63,8 @@ commands = pybabel extract -F babel-djangojs.cfg -o muranodashboard/locale/djangojs.pot -k gettext_noop -k gettext_lazy -k ngettext_lazy:1,2 -k ugettext_noop -k ugettext_lazy -k ungettext_lazy:1,2 -k npgettext:1c,2,3 -k pgettext_lazy:1c,2 -k npgettext_lazy:1c,2,3 muranodashboard [flake8] +# H202: assertRaises Exception too broad +ignore = H202 show-source = true builtins = _ exclude=build,.git,.tox,dist,doc,*lib/python*,*egg,tools,horizon,settings.py,*/local/*,functional_tests,node_modules