Updated gis_migrations tests

This commit is contained in:
Claude Paroz 2014-10-11 16:30:45 +02:00
parent e50e0ee27b
commit 1bdf1cb1c0
2 changed files with 12 additions and 17 deletions

View File

@ -22,7 +22,7 @@ class Migration(migrations.Migration):
name='Household', name='Household',
fields=[ fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('neighborhood', models.ForeignKey(to='gis.Neighborhood', to_field='id', null=True)), ('neighborhood', models.ForeignKey(to='gis_migrations.Neighborhood', to_field='id', null=True)),
('address', models.CharField(max_length=100)), ('address', models.CharField(max_length=100)),
('zip_code', models.IntegerField(null=True, blank=True)), ('zip_code', models.IntegerField(null=True, blank=True)),
('geom', django.contrib.gis.db.models.fields.PointField(srid=4326, geography=True)), ('geom', django.contrib.gis.db.models.fields.PointField(srid=4326, geography=True)),
@ -44,7 +44,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='household', model_name='household',
name='family', name='family',
field=models.ForeignKey(blank=True, to='gis.Family', null=True), field=models.ForeignKey(blank=True, to='gis_migrations.Family', null=True),
preserve_default=True, preserve_default=True,
), ),
] ]

View File

@ -12,7 +12,7 @@ class MigrateTests(TransactionTestCase):
""" """
Tests running the migrate command in Geodjango. Tests running the migrate command in Geodjango.
""" """
available_apps = ["django.contrib.gis"] available_apps = ["django.contrib.gis.tests.gis_migrations"]
def get_table_description(self, table): def get_table_description(self, table):
with connection.cursor() as cursor: with connection.cursor() as cursor:
@ -26,7 +26,6 @@ class MigrateTests(TransactionTestCase):
with connection.cursor() as cursor: with connection.cursor() as cursor:
self.assertNotIn(table, connection.introspection.table_names(cursor)) self.assertNotIn(table, connection.introspection.table_names(cursor))
@override_settings(MIGRATION_MODULES={"gis": "django.contrib.gis.tests.gis_migrations.migrations"})
def test_migrate_gis(self): def test_migrate_gis(self):
""" """
Tests basic usage of the migrate command when a model uses Geodjango Tests basic usage of the migrate command when a model uses Geodjango
@ -38,22 +37,16 @@ class MigrateTests(TransactionTestCase):
failure on geometry_columns. Regression for ticket #23030: failure on geometry_columns. Regression for ticket #23030:
https://code.djangoproject.com/ticket/23030 https://code.djangoproject.com/ticket/23030
""" """
# Make sure no tables are created
self.assertTableNotExists("migrations_neighborhood")
self.assertTableNotExists("migrations_household")
self.assertTableNotExists("migrations_family")
# Run the migrations to 0001 only
call_command("migrate", "gis", "0001", verbosity=0)
# Make sure the right tables exist # Make sure the right tables exist
self.assertTableExists("gis_neighborhood") self.assertTableExists("gis_migrations_neighborhood")
self.assertTableExists("gis_household") self.assertTableExists("gis_migrations_household")
self.assertTableExists("gis_family") self.assertTableExists("gis_migrations_family")
# Unmigrate everything # Unmigrate everything
call_command("migrate", "gis", "zero", verbosity=0) call_command("migrate", "gis_migrations", "zero", verbosity=0)
# Make sure it's all gone # Make sure it's all gone
self.assertTableNotExists("gis_neighborhood") self.assertTableNotExists("gis_migrations_neighborhood")
self.assertTableNotExists("gis_household") self.assertTableNotExists("gis_migrations_household")
self.assertTableNotExists("gis_family") self.assertTableNotExists("gis_migrations_family")
# Even geometry columns metadata # Even geometry columns metadata
try: try:
GeoColumn = connection.ops.geometry_columns() GeoColumn = connection.ops.geometry_columns()
@ -66,3 +59,5 @@ class MigrateTests(TransactionTestCase):
**{'%s__in' % GeoColumn.table_name_col(): ["gis_neighborhood", "gis_household"]} **{'%s__in' % GeoColumn.table_name_col(): ["gis_neighborhood", "gis_household"]}
).count(), ).count(),
0) 0)
# Revert the "unmigration"
call_command("migrate", "gis_migrations", verbosity=0)