Commits

adamv  committed 7a31d81

Added the beginnings of some tests.
- create_database.sql creates a test databaes with:
-- Spaces in a table name
-- Spaces in a column name

- testbackend is a Django project that uses (via a relative path) the current backend code
This lets management tools be run against the test schema.

  • Participants
  • Parent commits 074cc28

Comments (0)

Files changed (7)

File src/sqlserver_ado/introspection.py

 JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE PK_COLS 
 	ON PK.CONSTRAINT_NAME = PK_COLS.CONSTRAINT_NAME
 where
-	FK.TABLE_NAME = [%s]'''
+	FK.TABLE_NAME = %s'''
     cursor.execute(sql,[table_name])
     relations = cursor.fetchall()
     relation_map = dict()
 	join sys.columns C on C.object_id = T.object_id and C.column_id = IC.column_id
 	join sys.indexes Ix on Ix.object_id = T.object_id and Ix.index_id = IC.index_id
 where
-	T.name = [%s]
+	T.name = %s
 	and (Ix.is_unique=1 or Ix.is_primary_key=1)
     -- Omit multi-column keys
 	and not exists (

File tests/create_database.sql

+IF  EXISTS (SELECT name FROM sys.databases WHERE name = N'django_test_backend')
+DROP DATABASE [django_test_backend]
+go
+
+create database [django_test_backend]
+go
+
+use [django_test_backend]
+GO
+
+create table [table has spaces] (
+	[Create User] [nvarchar](30) NULL DEFAULT (''),
+	[Create Timestamp] [datetime] NOT NULL DEFAULT (getdate())
+)
+go
+
+use [master]
+go

File tests/runsql.cmd

+sqlcmd.exe -S localhost\ss2005 -E -V11 -i %1

File tests/testbackend/__init__.py

Empty file added.

File tests/testbackend/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)

File tests/testbackend/settings.py

+# Django settings for testbackend project.
+def hack_backend_path():
+	import os, sys
+	backend_path = os.path.join(os.path.abspath(os.path.dirname(".")), "../../src")
+	sys.path.append(backend_path)
+	
+hack_backend_path()
+
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlserver_ado'
+DATABASE_MSSQL_REGEX = True
+
+DATABASE_HOST = r'localhost\ss2005'
+DATABASE_PORT = ''
+DATABASE_NAME = r'django_test_backend'
+
+# Use integrated auth.
+DATABASE_USER = ''
+DATABASE_PASSWORD = ''
+
+
+# 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 = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+)

File tests/testbackend/urls.py

+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^testbackend/', include('testbackend.foo.urls')),
+
+    # Uncomment this for admin:
+#     (r'^admin/', include('django.contrib.admin.urls')),
+)