mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fix state tests a little
This commit is contained in:
parent
7d041b9394
commit
38a8cf1cdc
2 changed files with 35 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from django.db import models
|
||||
from django.db.models.loading import BaseAppCache
|
||||
from django.db.migrations.state import ProjectState
|
||||
from django.db.migrations.state import ProjectState, ModelState
|
||||
|
||||
|
||||
class StateTests(TestCase):
|
||||
|
@ -13,6 +13,7 @@ class StateTests(TestCase):
|
|||
"""
|
||||
Tests making a ProjectState from an AppCache
|
||||
"""
|
||||
|
||||
new_app_cache = BaseAppCache()
|
||||
|
||||
class Author(models.Model):
|
||||
|
@ -41,3 +42,31 @@ class StateTests(TestCase):
|
|||
self.assertEqual(author_state.fields[2][1].null, False)
|
||||
self.assertEqual(author_state.fields[3][1].null, True)
|
||||
self.assertEqual(author_state.bases, (models.Model, ))
|
||||
|
||||
self.assertEqual(book_state.app_label, "migrations")
|
||||
self.assertEqual(book_state.name, "Book")
|
||||
self.assertEqual([x for x, y in book_state.fields], ["id", "title", "author"])
|
||||
self.assertEqual(book_state.fields[1][1].max_length, 1000)
|
||||
self.assertEqual(book_state.fields[2][1].null, False)
|
||||
self.assertEqual(book_state.bases, (models.Model, ))
|
||||
|
||||
def test_render(self):
|
||||
"""
|
||||
Tests rendering a ProjectState into an AppCache.
|
||||
"""
|
||||
project_state = ProjectState()
|
||||
project_state.add_model_state(ModelState(
|
||||
"migrations",
|
||||
"Tag",
|
||||
[
|
||||
("id", models.AutoField(primary_key=True)),
|
||||
("name", models.CharField(max_length=100)),
|
||||
("hidden", models.BooleanField()),
|
||||
],
|
||||
{},
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue