Login

Testserver: --noinput option, sending a signal

Author:
mpasternacki
Posted:
June 18, 2010
Language:
Python
Version:
1.1
Tags:
django patch testserver
Score:
0 (after 0 ratings)

Makes manage.py testserver accept a --noinput argument to delete test database without asking if it already exists; makes it emit django.core.management.commands.testserver.testserver_setup signal after fixtures are loaded and before server itself is started to allow custom postprocessing.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--- Django-1.1.1_orig/django/core/management/commands/testserver.py	2008-10-02 14:57:13.000000000 +0200
+++ Django-1.1.1/django/core/management/commands/testserver.py	2010-06-17 19:31:39.000000000 +0200
@@ -1,12 +1,17 @@
 from django.core.management.base import BaseCommand
+from django.dispatch import Signal
 
 from optparse import make_option
 
+testserver_setup = Signal(providing_args=('db_name',))
+
 class Command(BaseCommand):
     option_list = BaseCommand.option_list + (
         make_option('--addrport', action='store', dest='addrport',
             type='string', default='',
             help='port number or ipaddr:port to run the server on'),
+        make_option('--noinput', action='store_false', dest='interactive', default=True,
+            help='Tells Django to NOT prompt the user for input of any kind.'),
     )
     help = 'Runs a development server with data from the given fixture(s).'
     args = '[fixture ...]'
@@ -21,11 +26,14 @@
         addrport = options.get('addrport')
 
         # Create a test database.
-        db_name = connection.creation.create_test_db(verbosity=verbosity)
+        db_name = connection.creation.create_test_db(
+            verbosity=verbosity, autoclobber=not options.get('interactive'))
 
         # Import the fixture data into the test database.
         call_command('loaddata', *fixture_labels, **{'verbosity': verbosity})
 
+        testserver_setup.send(self, db_name=db_name)
+
         # Run the development server. Turn off auto-reloading because it causes
         # a strange error -- it causes this handle() method to be called
         # multiple times.

More like this

  1. Signal to notify new saved comments by arthurfurlan 5 years, 10 months ago
  2. Generic Recievers For Signals by ericmoritz 6 years, 9 months ago
  3. Create permissions for proxy models by charettes 3 years, 1 month ago
  4. Callable object as signal receiver by diverman 5 years, 12 months ago
  5. Binding signals to abstract models by andreterra 2 years, 10 months ago

Comments

Please login first before commenting.