1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Remove AppCache state handling, replace with swappable caches

This commit is contained in:
Andrew Godwin
2012-09-22 00:47:04 +01:00
parent dbc17d035b
commit 49d1e6b0e2
6 changed files with 72 additions and 83 deletions

View File

@@ -10,14 +10,14 @@ class Author(models.Model):
height = models.PositiveIntegerField(null=True, blank=True)
class Meta:
managed = False
auto_register = False
class AuthorWithM2M(models.Model):
name = models.CharField(max_length=255)
class Meta:
managed = False
auto_register = False
class Book(models.Model):
@@ -27,7 +27,7 @@ class Book(models.Model):
#tags = models.ManyToManyField("Tag", related_name="books")
class Meta:
managed = False
auto_register = False
class BookWithM2M(models.Model):
@@ -37,7 +37,7 @@ class BookWithM2M(models.Model):
tags = models.ManyToManyField("Tag", related_name="books")
class Meta:
managed = False
auto_register = False
class BookWithSlug(models.Model):
@@ -47,7 +47,7 @@ class BookWithSlug(models.Model):
slug = models.CharField(max_length=20, unique=True)
class Meta:
managed = False
auto_register = False
db_table = "schema_book"
@@ -56,7 +56,7 @@ class Tag(models.Model):
slug = models.SlugField(unique=True)
class Meta:
managed = False
auto_register = False
class TagUniqueRename(models.Model):
@@ -64,7 +64,7 @@ class TagUniqueRename(models.Model):
slug2 = models.SlugField(unique=True)
class Meta:
managed = False
auto_register = False
db_table = "schema_tag"
@@ -73,5 +73,5 @@ class UniqueTest(models.Model):
slug = models.SlugField(unique=False)
class Meta:
managed = False
auto_register = False
unique_together = ["year", "slug"]

View File

@@ -6,7 +6,7 @@ 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, ForeignKey
from django.db.models.loading import cache
from django.db.models.loading import cache, default_cache, AppCache
from .models import Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagUniqueRename, UniqueTest
@@ -30,9 +30,12 @@ class SchemaTests(TestCase):
connection.managed(True)
# The unmanaged models need to be removed after the test in order to
# prevent bad interactions with the flush operation in other tests.
self.cache_state = cache.save_state()
self.app_cache = AppCache()
cache.set_cache(self.app_cache)
cache.copy_from(default_cache)
for model in self.models:
model._meta.managed = True
cache.register_models("schema", model)
model._prepare()
def tearDown(self):
# Delete any tables made for our models
@@ -40,10 +43,8 @@ class SchemaTests(TestCase):
# Rollback anything that may have happened
connection.rollback()
connection.leave_transaction_management()
# Unhook our models
for model in self.models:
model._meta.managed = False
cache.restore_state(self.cache_state)
cache.set_cache(default_cache)
cache.app_models['schema'] = {} # One M2M gets left in the old cache
def delete_tables(self):
"Deletes all model tables for our models for a clean test environment"