Login

Testserver: --noinput option, sending a signal

Author:
mpasternacki
Posted:
June 18, 2010
Language:
Python
Version:
1.1
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. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.