Anonymous avatar Anonymous committed 22ae9aa

excercise more bits of the django 1.0b1 test framework

Comments (0)

Files changed (12)

 
 *.orig
 *.pyc
+*.swp
+*.db
 *.egg-info
 build
 dist

examples/project/settings.py

 MANAGERS = ADMINS
 
 DATABASE_ENGINE = 'sqlite3'           # 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.
-DATABASE_NAME = ':memory:'             # Or path to database file if using sqlite3.
+DATABASE_NAME = 'zoo.db'             # Or path to database file if using sqlite3.
 #DATABASE_USER = ''             # Not used with sqlite3.
 #DATABASE_PASSWORD = ''         # Not used with sqlite3.
 #DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.

examples/project/zoo/__init__.py

+# place holder

examples/project/zoo/fixtures/f1.json

+[{"pk": 1, "model": "zoo.zoo", "fields": {"name": "f1"}}]

examples/project/zoo/fixtures/f2.json

+[{"pk": 1, "model": "zoo.zoo", "fields": {"name": "f2"}}]

examples/project/zoo/test_doctest_modules.py

+
+def test_regular_test_method():
+    ''' This is just a stub for a regular test method'''
+    pass
+
+def blah():
+    '''
+    This is a doctest that might get skipped
+
+    >>> 5 + 5 
+    10
+    '''
+

examples/project/zoo/test_fixtures.py

+from project.zoo.models import *
+
+class TestFixture1(object):
+    fixtures = ['f1.json']
+
+    def test_count(self):
+        assert Zoo.objects.count() == 1
+        assert Zoo.objects.get(id=1).name == 'f1'
+
+
+class TestFixture2(object):
+    fixtures = ['f2.json']
+    def test_count(self):
+        assert Zoo.objects.count() == 1
+        assert Zoo.objects.get(id=1).name == 'f2'

examples/project/zoo/test_foo.py

-
-def test_regular_test_method():
-    ''' This is just a stub for a regular test method'''
-    pass
-
-def blah():
-    '''
-    This is a doctest that might get skipped
-
-    >>> 5 + 5 
-    10
-    '''

examples/project/zoo/test_race.py

+# We have two test classes because we want to induce a race condition
+# and ensure that the database is always reset between test methods
+
+from zoo.models import *
+
+class TestDBRace1(object):
+    def setup(self):
+        assert Zoo.objects.count() == 0
+
+    def test1(self):
+        obj = Zoo.objects.create(name='sample1')
+        assert Zoo.objects.count() == 1
+        assert Zoo.objects.all()[0].name == 'sample1'
+
+
+class TestDBRace2(object):
+    def setup(self):
+        assert Zoo.objects.count() == 0
+
+    def test1(self):
+        obj = Zoo.objects.create(name='sample2')
+        assert Zoo.objects.count() == 1
+        assert Zoo.objects.all()[0].name == 'sample2'

nosedjango/__init__.py

+# Just a place holder for Windows.

nosedjango/nosedjango.py

 are run, and tears the test database (or schema) down after all tests are run.
 """
 
-import logging
 import os, sys
 import re
 
 # the settings file
 from nose.importer import add_path
 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+import re
+NT_ROOT = re.compile(r"^[a-zA-Z]:\\$")
 def get_SETTINGS_PATH():
+    '''
+    Hunt down the settings.py module by going up the FS path
+    '''
     cwd = os.getcwd()
     while cwd:
         if 'settings.py' in os.listdir(cwd):
             break
         cwd = os.path.split(cwd)[0]
-        if cwd == '/':
+        if os.name == 'nt' and NT_ROOT.match(cwd):
+            return None
+        elif cwd == '/':
             return None
     return cwd
+
 SETTINGS_PATH = get_SETTINGS_PATH()
 
-log = logging.getLogger('nose.plugins.nosedjango')
 
 class NoseDjango(Plugin):
     """
     install_requires='nose>=0.10',
     url = "http://www.assembla.com/spaces/nosedjango",
     license = 'GNU LGPL',
-    packages = find_packages(exclude=['tests']),
+    packages = find_packages(),
     zip_safe = False,
     include_package_data = True,
     entry_points = {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.