adamv avatar adamv committed c652878

Comments (0)

Files changed (6)

Add a comment to this file

tests/test_main/__init__.py

Empty file added.

tests/test_main/manage.py

+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
Add a comment to this file

tests/test_main/myapp/__init__.py

Empty file added.

tests/test_main/myapp/models.py

+import datetime
+import decimal
+from django.db import models
+
+class BaseModel(models.Model):
+    def __unicode__(self):
+        return u'id: ' + unicode(self.id) + ' Amount: ' + unicode(self.val)
+
+    class Meta:
+        abstract = True
+
+
+class TableNullChar(BaseModel):
+    """
+    >>> obj = TableNullChar(val=None)
+    >>> obj.save()
+    >>> obj = TableNullChar(val="This is my string value.")
+    >>> obj.save()
+    >>> len(list(TableNullChar.objects.all()))
+    2
+    """
+    val = models.CharField(null=True, max_length=100)
+    
+class TableNullText(BaseModel):
+    """
+    >>> obj = TableNullText(val=None)
+    >>> obj.save()
+    >>> obj = TableNullText(val="This is my string value.")
+    >>> obj.save()
+    >>> len(list(TableNullText.objects.all()))
+    2
+    """
+    val = models.TextField(null=True)
+
+class TableNullInteger(BaseModel):
+    """
+    >>> obj = TableNullInteger(val=None)
+    >>> obj.save()
+    >>> obj = TableNullInteger(val=39482)
+    >>> obj.save()
+    >>> len(list(TableNullInteger.objects.all()))
+    2
+    """
+    val = models.IntegerField(null=True)
+
+class TableNullDateTime(BaseModel):
+    """
+    >>> obj = TableNullDateTime(val=None)
+    >>> obj.save()
+    >>> obj = TableNullDateTime(val=datetime.datetime(2009,1,1,4,3,5))
+    >>> obj.save()
+    >>> len(list(TableNullDateTime.objects.all()))
+    2
+    """
+    val = models.DateTimeField(null=True)
+
+class TableNullDate(BaseModel):
+    """
+    >>> obj = TableNullDate(val=None)
+    >>> obj.save()
+    >>> obj = TableNullDate(val=datetime.date(2009,1,1))
+    >>> obj.save()
+    >>> len(list(TableNullDate.objects.all()))
+    2
+    """
+    val = models.DateField(null=True)
+
+class TableNullTime(BaseModel):
+    """
+    This test isn't expected to work on SQL Server 2005,
+    as there is no bare "time" type.
+    
+    obj = TableNullTime(val=None)
+    obj.save()
+    obj = TableNullTime(val=datetime.time(2,34,2))
+    obj.save()
+    len(list(TableNullTime.objects.all()))
+    2
+    """
+    val = models.TimeField(null=True)
+
+class TableNullBoolean(BaseModel):
+    """
+    >>> obj = TableNullBoolean(val=None)
+    >>> obj.save()
+    >>> obj = TableNullBoolean(val=True)
+    >>> obj.save()
+    >>> obj = TableNullBoolean(val=False)
+    >>> obj.save()
+    >>> len(list(TableNullBoolean.objects.all()))
+    3
+    """
+    val = models.BooleanField(null=True)
+
+class TableNullNullBoolean(BaseModel):
+    """
+    >>> obj = TableNullNullBoolean(val=None)
+    >>> obj.save()
+    >>> obj = TableNullNullBoolean(val=True)
+    >>> obj.save()
+    >>> obj = TableNullNullBoolean(val=False)
+    >>> obj.save()
+    >>> len(list(TableNullNullBoolean.objects.all()))
+    3
+    """
+    val = models.NullBooleanField(null=True)
+
+class TableNullDecimal(BaseModel):
+    """
+    >>> obj = TableNullDecimal(val=None)
+    >>> obj.save()
+    
+    Try a value at the top end of the specified precision/scale
+    >>> obj = TableNullDecimal(val=decimal.Decimal('99.99'))
+    >>> obj.save()
+    
+    >>> len(list(TableNullDecimal.objects.all()))
+    2
+    """
+    val = models.DecimalField(null=True, max_digits=4, decimal_places=2)
+
+class TableNullFloat(BaseModel):
+    """
+    >>> obj = TableNullFloat(val=None)
+    >>> obj.save()
+    >>> obj = TableNullFloat(val=34.3)
+    >>> obj.save()
+    >>> len(list(TableNullFloat.objects.all()))
+    2
+    """
+    val = models.FloatField(null=True)
+
+
+class Bug19Table(models.Model):
+    """ A simple model for testing string comparisons.
+    
+    >>> choices = (
+    ...     "no_slashes", "no_slashes_2",
+    ...     r"C:\some_folder\somefile.ext", r"\some_folder",
+    ...     "some_folder"+'\',
+    ...     "[brackets]",
+    ...     )
+    >>> for c in choices:
+    ...     Bug19Table.objects.create(choice=c).save()
+    >>> len(Bug19Table.objects.all())
+    6    
+
+    >>> len(Bug19Table.objects.filter(choice__contains="shes"))
+    2
+    
+    >>> len(Bug19Table.objects.filter(choice__endswith="shes"))
+    1
+    
+    >>> len(Bug19Table.objects.filter(choice__contains=r"der\som"))
+    1
+    
+    >>> len(Bug19Table.objects.filter(choice__endswith=r"der\somefile.ext"))
+    1
+    
+    >>> len(Bug19Table.objects.filter(choice__contains="["))
+    1
+    
+    """
+    choice = models.TextField(max_length=200)
+    
+    def __unicode__(self):
+        return self.choice
+
+
+class Bug23Table(models.Model):
+    """
+    Test inserting mixed NULL and non-NULL values.
+    
+    >>> obj = Bug23Table(mycharfield1=None, mycharfield2="text2", myintfield=1)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1="text1", mycharfield2=None, myintfield=1)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1="text1", mycharfield2="text2", myintfield=None)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1=None, mycharfield2=None, myintfield=1)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1=None, mycharfield2="text2", myintfield=None)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1="text1", mycharfield2=None, myintfield=None)
+    >>> obj.save()
+    >>> obj = Bug23Table(mycharfield1=None, mycharfield2=None, myintfield=None)
+    >>> obj.save()
+    >>> objs = list(Bug23Table.objects.all())
+    >>> len(objs)
+    7
+    >>> len([obj for obj in objs if obj.mycharfield1=="text1"])
+    3
+    >>> len([obj for obj in objs if obj.mycharfield2=="text2"])
+    3
+    >>> len([obj for obj in objs if obj.myintfield==1])
+    3
+    """
+    mycharfield1 = models.CharField(max_length=100, null=True)
+    mycharfield2 = models.CharField(max_length=50, null=True)
+    myintfield = models.IntegerField(null=True)
+
+class Bug21Table(models.Model):
+    """
+    Test adding decimals as actual types or as strings.
+    
+    >>> obj = Bug21Table(a='decimal as decimal', d=decimal.Decimal('12.34'))
+    >>> obj.save()
+    >>> obj = Bug21Table(a='decimal as string', d=u'56.78')
+    >>> obj.save()
+    >>> len(list(Bug21Table.objects.all()))
+    2
+    """
+    a = models.CharField(max_length=50)
+    d = models.DecimalField(max_digits=5, decimal_places=2)
+
+class Bug27Table(models.Model):
+    """
+    Test that extra/select works, and doesn't interfere with the 
+    limit/offset implementation.
+    
+    >>> Bug27Table(a=100).save()
+    >>> Bug27Table(a=101).save()
+    >>> len(list(Bug27Table.objects.all()))
+    2
+    
+    >>> objs = list(Bug27Table.objects.extra(select={'alias_for_a':'a'}).order_by('a'))
+    >>> objs[0].alias_for_a
+    100
+
+    >>> objs[1].alias_for_a
+    101
+    """
+    
+    a = models.IntegerField()

tests/test_main/settings.py

+# Django settings for testbackend project.
+def hack_path():
+	import os, sys
+	common_path = os.path.join(os.path.abspath(os.path.dirname(".")), "..")
+	sys.path.append(common_path)
+	
+hack_path()
+from dbsettings import *
+
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/New York'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = ''
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '%(u8uds4xsy0+95cj3o&k49*u@&--yp0t&e&0$!@s2fvea#u4j'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.middleware.doc.XViewMiddleware',
+)
+
+ROOT_URLCONF = 'urls'
+
+TEMPLATE_DIRS = (
+    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+	'myapp',
+)

tests/test_main/urls.py

+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^test_models/', include('test_models.foo.urls')),
+
+    # Uncomment this for admin:
+     (r'^admin/', include('django.contrib.admin.urls')),
+)
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.