1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Used CommandError in createcachetable command.

Raising CommandError whenever a management command meets an error
condition is the standard way to handle errors in commands.
This commit is contained in:
Claude Paroz
2012-05-27 23:03:21 +02:00
parent f2b6763ad7
commit cc4b4d9fd3
2 changed files with 14 additions and 11 deletions

View File

@@ -7,7 +7,6 @@ from __future__ import absolute_import
import hashlib
import os
import re
import StringIO
import tempfile
import time
import warnings
@@ -820,9 +819,14 @@ class DBCacheTests(BaseCacheTests, TransactionTestCase):
self.perform_cull_test(50, 18)
def test_second_call_doesnt_crash(self):
err = StringIO.StringIO()
management.call_command('createcachetable', self._table_name, verbosity=0, interactive=False, stderr=err)
self.assertTrue(b"Cache table 'test cache table' could not be created" in err.getvalue())
with self.assertRaisesRegexp(management.CommandError,
"Cache table 'test cache table' could not be created"):
management.call_command(
'createcachetable',
self._table_name,
verbosity=0,
interactive=False
)
@override_settings(USE_TZ=True)