summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2012-09-07 12:51:11 -0400
committerAndrew Godwin <andrew@aeracode.org>2012-09-07 12:51:11 -0400
commitd683263f97aedd67f17f4b78ac65d915f4e70d36 (patch)
treeef7c4176814ffd35f12fd355444c099e3b3a54b5 /tests
parent7e81213b5a4570926afbd67eff7f2675f636d720 (diff)
Added SQLite backend which passes all current tests
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/schema/models.py11
-rw-r--r--tests/modeltests/schema/tests.py24
2 files changed, 27 insertions, 8 deletions
diff --git a/tests/modeltests/schema/models.py b/tests/modeltests/schema/models.py
index 9d0a8a2074..b18d2a9c16 100644
--- a/tests/modeltests/schema/models.py
+++ b/tests/modeltests/schema/models.py
@@ -29,6 +29,17 @@ class Book(models.Model):
managed = False
+class BookWithSlug(models.Model):
+ author = models.ForeignKey(Author)
+ title = models.CharField(max_length=100, db_index=True)
+ pub_date = models.DateTimeField()
+ slug = models.CharField(max_length=20, unique=True)
+
+ class Meta:
+ managed = False
+ db_table = "schema_book"
+
+
class Tag(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(unique=True)
diff --git a/tests/modeltests/schema/tests.py b/tests/modeltests/schema/tests.py
index db374dc7ad..c76ca8ca16 100644
--- a/tests/modeltests/schema/tests.py
+++ b/tests/modeltests/schema/tests.py
@@ -2,11 +2,12 @@ from __future__ import absolute_import
import copy
import datetime
from django.test import TestCase
+from django.utils.unittest import skipUnless
from django.db import connection, DatabaseError, IntegrityError
from django.db.models.fields import IntegerField, TextField, CharField, SlugField
from django.db.models.fields.related import ManyToManyField
from django.db.models.loading import cache
-from .models import Author, Book, AuthorWithM2M, Tag, TagUniqueRename, UniqueTest
+from .models import Author, Book, BookWithSlug, AuthorWithM2M, Tag, TagUniqueRename, UniqueTest
class SchemaTests(TestCase):
@@ -18,7 +19,7 @@ class SchemaTests(TestCase):
as the code it is testing.
"""
- models = [Author, Book, AuthorWithM2M, Tag, UniqueTest]
+ models = [Author, Book, BookWithSlug, AuthorWithM2M, Tag, TagUniqueRename, UniqueTest]
# Utility functions
@@ -70,13 +71,21 @@ class SchemaTests(TestCase):
def column_classes(self, model):
cursor = connection.cursor()
- return dict(
+ columns = dict(
(d[0], (connection.introspection.get_field_type(d[1], d), d))
for d in connection.introspection.get_table_description(
cursor,
model._meta.db_table,
)
)
+ # SQLite has a different format for field_type
+ for name, (type, desc) in columns.items():
+ if isinstance(type, tuple):
+ columns[name] = (type[0], desc)
+ # SQLite also doesn't error properly
+ if not columns:
+ raise DatabaseError("Table does not exist (empty pragma)")
+ return columns
# Tests
@@ -104,6 +113,7 @@ class SchemaTests(TestCase):
lambda: list(Author.objects.all()),
)
+ @skipUnless(connection.features.supports_foreign_keys, "No FK support")
def test_creation_fk(self):
"Tests that creating tables out of FK order works"
# Create the table
@@ -449,13 +459,11 @@ class SchemaTests(TestCase):
connection.introspection.get_indexes(connection.cursor(), Book._meta.db_table),
)
# Add a unique column, verify that creates an implicit index
- new_field = CharField(max_length=20, unique=True)
- new_field.set_attributes_from_name("slug")
editor = connection.schema_editor()
editor.start()
editor.create_field(
Book,
- new_field,
+ BookWithSlug._meta.get_field_by_name("slug")[0],
)
editor.commit()
self.assertIn(
@@ -468,8 +476,8 @@ class SchemaTests(TestCase):
editor = connection.schema_editor()
editor.start()
editor.alter_field(
- Book,
- new_field,
+ BookWithSlug,
+ BookWithSlug._meta.get_field_by_name("slug")[0],
new_field2,
strict = True,
)