From bb7da7844ff9f11286509c22a2549bbd4553d58d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 26 Sep 2012 15:07:11 +0200 Subject: Fixed #18845 -- Do not swallow AttributeErrors when running commands --- tests/regressiontests/admin_scripts/tests.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 6028eac846..6f524bea29 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -982,13 +982,11 @@ class ManageMultipleSettings(AdminScriptTestCase): self.assertNoOutput(err) self.assertOutput(out, "EXECUTE:NoArgsCommand") + class ManageSettingsWithImportError(AdminScriptTestCase): """Tests for manage.py when using the default settings.py file with an import error. Ticket #14130. """ - def setUp(self): - self.write_settings_with_import_error('settings.py') - def tearDown(self): self.remove_settings('settings.py') @@ -1004,12 +1002,27 @@ class ManageSettingsWithImportError(AdminScriptTestCase): settings_file.write('# The next line will cause an import error:\nimport foo42bar\n') def test_builtin_command(self): - "import error: manage.py builtin commands shows useful diagnostic info when settings with import errors is provided" + """ + import error: manage.py builtin commands shows useful diagnostic info + when settings with import errors is provided + """ + self.write_settings_with_import_error('settings.py') args = ['sqlall', 'admin_scripts'] out, err = self.run_manage(args) self.assertNoOutput(out) self.assertOutput(err, "No module named foo42bar") + def test_builtin_command_with_attribute_error(self): + """ + manage.py builtin commands does not swallow attribute errors from bad settings (#18845) + """ + self.write_settings('settings.py', sdict={'BAD_VAR': 'INSTALLED_APPS.crash'}) + args = ['collectstatic', 'admin_scripts'] + out, err = self.run_manage(args) + self.assertNoOutput(out) + self.assertOutput(err, "AttributeError: 'list' object has no attribute 'crash'") + + class ManageValidate(AdminScriptTestCase): def tearDown(self): self.remove_settings('settings.py') -- cgit v1.3 From 3541a10d492db6d1f509f3a50a024568c16c5229 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 22 Oct 2012 18:13:59 -0600 Subject: Fixed #19164 -- Fixed diffsettings command broken in fix for #18545. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Mario César for the report and draft patch. --- django/conf/__init__.py | 7 ++++--- tests/regressiontests/admin_scripts/tests.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 7452013671..1804c851bf 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -25,7 +25,7 @@ class LazySettings(LazyObject): The user can manually configure settings prior to using them. Otherwise, Django uses the settings module pointed to by DJANGO_SETTINGS_MODULE. """ - def _setup(self, name): + def _setup(self, name=None): """ Load the settings module pointed to by the environment variable. This is used the first time we need any settings at all, if the user has not @@ -36,11 +36,12 @@ class LazySettings(LazyObject): if not settings_module: # If it's set but is an empty string. raise KeyError except KeyError: + desc = ("setting %s" % name) if name else "settings" raise ImproperlyConfigured( - "Requested setting %s, but settings are not configured. " + "Requested %s, but settings are not configured. " "You must either define the environment variable %s " "or call settings.configure() before accessing settings." - % (name, ENVIRONMENT_VARIABLE)) + % (desc, ENVIRONMENT_VARIABLE)) self._wrapped = Settings(settings_module) self._configure_logging() diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 6f524bea29..a5deba7fe1 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -1603,3 +1603,15 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): with codecs.open(path, 'r', 'utf-8') as f: self.assertEqual(f.read(), 'Some non-ASCII text for testing ticket #18091:\nüäö €\n') + + +class DiffSettings(AdminScriptTestCase): + """Tests for diffsettings management command.""" + def test_basic(self): + "Runs without error and emits settings diff." + self.write_settings('settings_to_diff.py', sdict={'FOO': '"bar"'}) + args = ['diffsettings', '--settings=settings_to_diff'] + out, err = self.run_manage(args) + self.remove_settings('settings_to_diff.py') + self.assertNoOutput(err) + self.assertOutput(out, "FOO = 'bar' ###") -- cgit v1.3 From bdcd2f6b105fffea0b8438625a29a1ccb2962680 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 28 Sep 2012 10:17:40 -0700 Subject: Avoid dependence on exact Python exception messages --- tests/modeltests/basic/tests.py | 3 +-- tests/regressiontests/admin_scripts/tests.py | 6 ++++-- tests/regressiontests/file_storage/tests.py | 2 +- tests/regressiontests/fixtures_regress/tests.py | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py index 6ec9ca03af..ebd70d14d9 100644 --- a/tests/modeltests/basic/tests.py +++ b/tests/modeltests/basic/tests.py @@ -259,9 +259,8 @@ class ModelTest(TestCase): "datetime.datetime(2005, 7, 28, 0, 0)"]) # dates() requires valid arguments. - six.assertRaisesRegex(self, + self.assertRaises( TypeError, - "dates\(\) takes at least 3 arguments \(1 given\)", Article.objects.dates, ) diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index a5deba7fe1..3bb8bb0b50 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -1010,7 +1010,8 @@ class ManageSettingsWithImportError(AdminScriptTestCase): args = ['sqlall', 'admin_scripts'] out, err = self.run_manage(args) self.assertNoOutput(out) - self.assertOutput(err, "No module named foo42bar") + self.assertOutput(err, "No module named") + self.assertOutput(err, "foo42bar") def test_builtin_command_with_attribute_error(self): """ @@ -1033,7 +1034,8 @@ class ManageValidate(AdminScriptTestCase): args = ['validate'] out, err = self.run_manage(args) self.assertNoOutput(out) - self.assertOutput(err, 'No module named admin_scriptz') + self.assertOutput(err, 'No module named') + self.assertOutput(err, 'admin_scriptz') def test_broken_app(self): "manage.py validate reports an ImportError if an app's models.py raises one on import" diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index 6b57ad6160..595b65d9f1 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -78,7 +78,7 @@ class GetStorageClassTests(SimpleTestCase): six.assertRaisesRegex(self, ImproperlyConfigured, ('Error importing storage module django.core.files.non_existing_' - 'storage: "No module named .*non_existing_storage"'), + 'storage: "No module named .*non_existing_storage'), get_storage_class, 'django.core.files.non_existing_storage.NonExistingStorage' ) diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py index 678db4a9cc..55363bc5b7 100644 --- a/tests/regressiontests/fixtures_regress/tests.py +++ b/tests/regressiontests/fixtures_regress/tests.py @@ -159,7 +159,7 @@ class TestFixtures(TestCase): Test that failing serializer import raises the proper error """ with six.assertRaisesRegex(self, ImportError, - "No module named unexistent.path"): + r"No module named.*unexistent"): management.call_command( 'loaddata', 'bad_fixture1.unkn', -- cgit v1.3