Changeset 73

Show
Ignore:
Timestamp:
Tue Jul 4 21:49:55 2006
Author:
jpellerin
Message:

r1342@Jason-Pellerins-Computer: jhp | 2006-05-16 22:30:00 -0500
Placeholders for needed tests, sketch out implementation

Files:

Legend:

Unmodified
Added
Removed
Modified
  • nose-django/trunk/tests.py

    r72 r73  
    108 108     plug.add_options(parser, env)  
    109 109     options, args = parser.parse_args(argv)  
      110     plug.configure(options, conf)  
      111     assert plug.test_db == 'testdb'  
      112     assert plug.test_schema is None  
    110 113      
    111 114 def test_config_test_schema():  
     
    118 121     plug.add_options(parser, env)  
    119 122     options, args = parser.parse_args(argv)  
      123     plug.configure(options, conf)     
      124     assert plug.test_db is None  
      125     assert plug.test_schema == 'testschema'  
    120 126  
    121 127 def test_config_test_db_schema():  
     
    129 135     plug.add_options(parser, env)  
    130 136     options, args = parser.parse_args(argv)  
      137     plug.configure(options, conf)  
      138     assert plug.test_db == 'testdb'  
      139     assert plug.test_schema == 'testschema'  
    131 140      
    132 141 def test_begin():  
    133 142     # using dummy driver(?), test that begin() creates the test db and  
    134 143     # disconnects from the real db, and fills the test db with models  
    135       pass  
      144     assert False, "No test"  
    135 144  
    136 145 def test_begin_name_clash():  
    137 146     # using dummy driver(?), test that begin() will error out if the test  
    138 147     # db already exists  
    139       pass  
      148     assert False, "No test"  
    139 148  
    140 149  
     
    144 153     # test that finalize() clears out the test db in a non-destructive  
    145 154     # manner (only clear a db we created)  
    146       pass  
      155     assert False, "No test"  
    146 155  
    147 156 # full tests  
     
    151 160     """setup/teardown with sqlite3 database  
    152 161     """  
    153       pass  
      162     assert False, "No test"  
    153 162  
    154 163 def test_test_db():  
    155 164     """setup/teardown with test db  
    156 165     """  
    157       pass  
      166     assert False, "No test"  
    157 166  
    158 167 def test_test_schema():  
    159 168     """setup/teardown with test schema (postgres only)  
    160 169     """  
    161       pass  
      170     assert False, "No test"  
  • nose-django/trunk/nosedjango.py

    r72 r73  
    7 7 __version__ = '0.1'  
    8 8  
      9 import atexit  
    9 10 import os  
    10 11 import re  
     
    14 15 class NoseDjango(Plugin):  
    15 16     name = 'django'  
      17     # FIXME make this a list  
    16 18     ignoreDjangoFiles = re.compile(r'^(manage\.py|.*settings\.py)$')  
    17 19     env = None  
      20     old_db = None  
      21     test_db = None  
      22     test_schema = None  
      23     created_db = None  
      24     created_schema = None  
    18 25      
    19 26     def add_options(self, parser, env=os.environ):  
     
    41 48                           'DATABASE_NAME in the active django settings '  
    42 49                           '[NOSE_DJANGO_TEST_SCHEMA]')  
      50          
    43 51     def configure(self, options, conf):  
    44 52         Plugin.configure(self, options, conf)  
     
    50 58         if options.django_settings and self.env is not None:  
    51 59             self.env['DJANGO_SETTINGS_MODULE'] = options.django_settings  
      60         if options.django_test_db:  
      61             self.test_db = options.django_test_db  
      62         if options.django_test_schema:  
      63             self.test_schema = options.django_test_schema  
      64  
      65     def begin(self):  
      66         """Create the test database and schema, if needed, and switch the  
      67         connection over to that database. Then call syncdb to install all apps  
      68         listed in the loaded settings module.  
      69         """  
      70         from django.conf import settings  
      71         from django.db import connection  
      72         from django.core import management  
      73          
      74         self.old_db = settings.DATABASE_NAME  
      75  
      76         # make sure we can clean up after ourselves  
      77         atexit.register(self.finalize)  
      78          
      79         if settings.DATABASE_ENGINE == 'sqlite3':  
      80             # always use a :memory: database for sqlite  
      81             self.test_db = ':memory:'  
      82         else:  
      83             if self.test_db:  
      84                 # create test db for others, if requested  
      85                 cursor = connection.cursor()  
      86                 connection.connection.autocommit(1)  
      87                 cursor.execute("CREATE DATABASE %s" % self.test_db)  
      88                 self.created_db = self.test_db         
      89         # connect to the test db, if desired  
      90         if self.test_db:  
      91             connection.close()  
      92             settings.DATABASE_NAME = self.test_db  
      93         # pg only: create test schema, set as default in search path  
      94         # FIXME: throw error now if not pg compat?  
      95         if self.test_schema:  
      96             cursor = connection.cursor()  
      97             cursor.execute("CREATE SCHEMA %s" % self.test_schema)  
      98             cursor.execute("SET search_path TO %s,pg_catalog" %  
      99                            self.test_schema)  
      100             self.created_schema = self.test_schema  
      101         # sync up the db  
      102         management.syncdb()  
      103              
      104  
      105     def finalize(self):  
      106         """Clean up any created database and schema  
      107         """  
      108         from django.conf import settings  
      109         from django.db import connection  
      110          
      111         if self.created_schema:  
      112             cursor = connection.cursor()  
      113             cursor.execute("DROP SCHEMA %s" % self.created_schema)  
      114             self.created_schema = None # in case run again  
      115  
      116         if self.created_db:  
      117             connection.close()  
      118             settings.DATABASE_NAME = self.old_db  
      119             cursor = connection.cursor()  
      120             connection.connection.autocommit(1)  
      121             cursor.execute("DROP DATABASE %s" % self.created_db)  
      122             self.created_db = None