mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Start adding operations that work and tests for them
This commit is contained in:
parent
264f8650e3
commit
d0ecefc2c9
16 changed files with 221 additions and 56 deletions
|
@ -1,11 +1,12 @@
|
|||
from django.test import TestCase
|
||||
from django.test import TestCase, TransactionTestCase
|
||||
from django.db import connection
|
||||
from django.db.migrations.loader import MigrationLoader
|
||||
from django.db.migrations.recorder import MigrationRecorder
|
||||
|
||||
|
||||
class RecorderTests(TestCase):
|
||||
"""
|
||||
Tests the disk and database loader.
|
||||
Tests recording migrations as applied or not.
|
||||
"""
|
||||
|
||||
def test_apply(self):
|
||||
|
@ -27,3 +28,37 @@ class RecorderTests(TestCase):
|
|||
recorder.applied_migrations(),
|
||||
set(),
|
||||
)
|
||||
|
||||
|
||||
class LoaderTests(TransactionTestCase):
|
||||
"""
|
||||
Tests the disk and database loader, and running through migrations
|
||||
in memory.
|
||||
"""
|
||||
|
||||
def test_load(self):
|
||||
"""
|
||||
Makes sure the loader can load the migrations for the test apps,
|
||||
and then render them out to a new AppCache.
|
||||
"""
|
||||
# Load and test the plan
|
||||
migration_loader = MigrationLoader(connection)
|
||||
self.assertEqual(
|
||||
migration_loader.graph.forwards_plan(("migrations", "0002_second")),
|
||||
[("migrations", "0001_initial"), ("migrations", "0002_second")],
|
||||
)
|
||||
# Now render it out!
|
||||
project_state = migration_loader.graph.project_state(("migrations", "0002_second"))
|
||||
self.assertEqual(len(project_state.models), 2)
|
||||
|
||||
author_state = project_state.models["migrations", "author"]
|
||||
self.assertEqual(
|
||||
[x for x, y in author_state.fields],
|
||||
["id", "name", "slug", "age", "important"]
|
||||
)
|
||||
|
||||
book_state = project_state.models["migrations", "book"]
|
||||
self.assertEqual(
|
||||
[x for x, y in book_state.fields],
|
||||
["id", "author"]
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue