mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Renamed AppCache to Apps.
Also renamed app_cache to apps and "app cache" to "app registry". Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from django.apps.cache import AppCache
|
||||
from django.apps.registry import Apps
|
||||
from django.db import models
|
||||
from django.db.migrations.state import ProjectState, ModelState, InvalidBasesError
|
||||
from django.test import TestCase
|
||||
@@ -11,10 +11,10 @@ class StateTests(TestCase):
|
||||
|
||||
def test_create(self):
|
||||
"""
|
||||
Tests making a ProjectState from an AppCache
|
||||
Tests making a ProjectState from an Apps
|
||||
"""
|
||||
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
@@ -23,13 +23,13 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
unique_together = ["name", "bio"]
|
||||
|
||||
class AuthorProxy(Author):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
ordering = ["name"]
|
||||
|
||||
@@ -40,11 +40,11 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
verbose_name = "tome"
|
||||
db_table = "test_tome"
|
||||
|
||||
project_state = ProjectState.from_app_cache(new_app_cache)
|
||||
project_state = ProjectState.from_apps(new_apps)
|
||||
author_state = project_state.models['migrations', 'author']
|
||||
author_proxy_state = project_state.models['migrations', 'authorproxy']
|
||||
book_state = project_state.models['migrations', 'book']
|
||||
@@ -75,7 +75,7 @@ class StateTests(TestCase):
|
||||
|
||||
def test_render(self):
|
||||
"""
|
||||
Tests rendering a ProjectState into an AppCache.
|
||||
Tests rendering a ProjectState into an Apps.
|
||||
"""
|
||||
project_state = ProjectState()
|
||||
project_state.add_model_state(ModelState(
|
||||
@@ -90,9 +90,9 @@ class StateTests(TestCase):
|
||||
None,
|
||||
))
|
||||
|
||||
new_app_cache = project_state.render()
|
||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
||||
self.assertEqual(new_app_cache.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
||||
new_apps = project_state.render()
|
||||
self.assertEqual(new_apps.get_model("migrations", "Tag")._meta.get_field_by_name("name")[0].max_length, 100)
|
||||
self.assertEqual(new_apps.get_model("migrations", "Tag")._meta.get_field_by_name("hidden")[0].null, False)
|
||||
|
||||
def test_render_model_inheritance(self):
|
||||
class Book(models.Model):
|
||||
@@ -100,90 +100,90 @@ class StateTests(TestCase):
|
||||
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class Novel(Book):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# First, test rendering individually
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# We shouldn't be able to render yet
|
||||
ms = ModelState.from_model(Novel)
|
||||
with self.assertRaises(InvalidBasesError):
|
||||
ms.render(app_cache)
|
||||
ms.render(apps)
|
||||
|
||||
# Once the parent model is in the app cache, it should be fine
|
||||
ModelState.from_model(Book).render(app_cache)
|
||||
ModelState.from_model(Novel).render(app_cache)
|
||||
# Once the parent model is in the app registry, it should be fine
|
||||
ModelState.from_model(Book).render(apps)
|
||||
ModelState.from_model(Novel).render(apps)
|
||||
|
||||
def test_render_model_with_multiple_inheritance(self):
|
||||
class Foo(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class Bar(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
class FooBar(Foo, Bar):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
app_cache = AppCache()
|
||||
apps = Apps()
|
||||
|
||||
# We shouldn't be able to render yet
|
||||
ms = ModelState.from_model(FooBar)
|
||||
with self.assertRaises(InvalidBasesError):
|
||||
ms.render(app_cache)
|
||||
ms.render(apps)
|
||||
|
||||
# Once the parent models are in the app cache, it should be fine
|
||||
ModelState.from_model(Foo).render(app_cache)
|
||||
ModelState.from_model(Bar).render(app_cache)
|
||||
ModelState.from_model(FooBar).render(app_cache)
|
||||
# Once the parent models are in the app registry, it should be fine
|
||||
ModelState.from_model(Foo).render(apps)
|
||||
ModelState.from_model(Bar).render(apps)
|
||||
ModelState.from_model(FooBar).render(apps)
|
||||
|
||||
def test_render_project_dependencies(self):
|
||||
"""
|
||||
Tests that the ProjectState render method correctly renders models
|
||||
to account for inter-model base dependencies.
|
||||
"""
|
||||
new_app_cache = AppCache()
|
||||
new_apps = Apps()
|
||||
|
||||
class A(models.Model):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class B(A):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class C(B):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class D(A):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
|
||||
class E(B):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
|
||||
class F(D):
|
||||
class Meta:
|
||||
app_label = "migrations"
|
||||
app_cache = new_app_cache
|
||||
apps = new_apps
|
||||
proxy = True
|
||||
|
||||
# Make a ProjectState and render it
|
||||
@@ -194,8 +194,8 @@ class StateTests(TestCase):
|
||||
project_state.add_model_state(ModelState.from_model(D))
|
||||
project_state.add_model_state(ModelState.from_model(E))
|
||||
project_state.add_model_state(ModelState.from_model(F))
|
||||
final_app_cache = project_state.render()
|
||||
self.assertEqual(len(final_app_cache.get_models()), 6)
|
||||
final_apps = project_state.render()
|
||||
self.assertEqual(len(final_apps.get_models()), 6)
|
||||
|
||||
# Now make an invalid ProjectState and make sure it fails
|
||||
project_state = ProjectState()
|
||||
|
||||
Reference in New Issue
Block a user