Changeset 72

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

r961@Jason-Pellerins-Computer: jhp | 2006-05-14 13:00:35 -0500
Work on config options and tests for same

Files:

Legend:

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

    r45 r72  
    2 2 import os  
    3 3 import sys  
      4 from optparse import OptionParser  
    4 5 from nose.config import Config  
    5 6 from nosedjango import NoseDjango  
     
    64 65      
    65 66 # function/units  
      67 def test_config_basic():  
      68     # basic: enable, and inject django settings/manage files into ignoreFiles  
      69     parser = OptionParser()  
      70     conf = Config()  
      71     argv = ['proggy', '--with-django']  
      72     env = {}  
      73  
      74     plug = NoseDjango()  
      75     plug.add_options(parser, env)  
      76     options, args = parser.parse_args(argv)  
      77     assert options.enable_plugin_django     
      78     plug.configure(options, conf)  
      79     assert plug.enabled  
      80     assert plug.ignoreDjangoFiles in conf.ignoreFiles  
      81  
      82 def test_config_settings():  
      83     # settings module can be set via config  
      84  
      85     parser = OptionParser()         
      86     conf = Config()  
      87     argv = ['proggy', '--with-django', '--django-settings=some.settings']  
      88     env = {}  
      89      
      90     plug = NoseDjango()  
      91     plug.add_options(parser, env)  
      92     options, args = parser.parse_args(argv)  
      93     assert options.enable_plugin_django  
      94     assert options.django_settings == 'some.settings'  
      95     plug.configure(options, conf)  
      96     assert plug.enabled  
      97     assert plug.ignoreDjangoFiles in conf.ignoreFiles  
      98     assert env['DJANGO_SETTINGS_MODULE'] == 'some.settings'  
      99  
      100 def test_config_test_db():  
      101     # use particular test db  
      102  
      103     parser = OptionParser()         
      104     conf = Config()  
      105     env = {}     
      106     argv = ['proggy', '--with-django', '--django-test-db=testdb']  
      107     plug = NoseDjango()  
      108     plug.add_options(parser, env)  
      109     options, args = parser.parse_args(argv)  
      110      
      111 def test_config_test_schema():  
      112     # use test schema instead of test db  
      113     parser = OptionParser()         
      114     conf = Config()  
      115     env = {}  
      116     argv = ['proggy', '--with-django', '--django-test-schema=testschema']  
      117     plug = NoseDjango()  
      118     plug.add_options(parser, env)  
      119     options, args = parser.parse_args(argv)  
      120  
      121 def test_config_test_db_schema():  
      122     # use test schema in test db  
      123     parser = OptionParser()         
      124     conf = Config()  
      125     env = {}  
      126     argv = ['proggy', '--with-django', '--django-test-db=testdb',  
      127             '--django-test-schema=testschema']  
      128     plug = NoseDjango()  
      129     plug.add_options(parser, env)  
      130     options, args = parser.parse_args(argv)  
      131      
    66 132 def test_begin():  
    67 133     # using dummy driver(?), test that begin() creates the test db and  
     
    74 140     pass  
    75 141  
    76   def test_config():  
    77       # test that the config options are all what they are supposed to be  
    78       pass  
    79 142  
    80 143 def test_finalize():  
  • nose-django/trunk/nosedjango.py

    r45 r72  
    7 7 __version__ = '0.1'  
    8 8  
      9 import os  
      10 import re  
      11  
    9 12 from nose.plugins import Plugin  
    10 13  
    11 14 class NoseDjango(Plugin):  
    12       pass  
      15     name = 'django'  
      16     ignoreDjangoFiles = re.compile(r'^(manage\.py|.*settings\.py)$')  
      17     env = None  
      18      
      19     def add_options(self, parser, env=os.environ):  
      20         # keep copy so we can make our setting in the env we were passed  
      21         self.env = env  
      22         Plugin.add_options(self, parser, env)  
      23         parser.add_option('--django-settings', action='store',  
      24                           dest='django_settings', default=None,  
      25                           help="Set module as the DJANGO_SETTINGS_MODULE"  
      26                           " environment variable")  
      27         parser.add_option('--django-test-db', action='store',  
      28                           dest='django_test_db',  
      29                           default=env.get('NOSE_DJANGO_TEST_DB'),  
      30                           help='Create this database for use in tests and '  
      31                           'drop it after tests have run. May be combined '  
      32                           'with --django-test-schema option for databases '  
      33                           'that support schemas [NOSE_DJANGO_TEST_DB]')  
      34         parser.add_option('--django-test-schema', action='store',  
      35                           dest='django_test_schema',  
      36                           default=env.get('NOSE_DJANGO_TEST_SCHEMA'),  
      37                           help='Create this schema for use in tests and '  
      38                           'drop it after tests have run. May be combined '  
      39                           'with --django-test-db; otherwise, test schema '  
      40                           'will be created in the database named by '  
      41                           'DATABASE_NAME in the active django settings '  
      42                           '[NOSE_DJANGO_TEST_SCHEMA]')  
      43     def configure(self, options, conf):  
      44         Plugin.configure(self, options, conf)  
      45         if self.enabled:  
      46             # insert my ignores into conf.ignoreFiles, to force main  
      47             # system to ignore django scripts and settings files, no  
      48             # matter what other plugins say  
      49             conf.ignoreFiles.append(self.ignoreDjangoFiles)  
      50         if options.django_settings and self.env is not None:  
      51             self.env['DJANGO_SETTINGS_MODULE'] = options.django_settings