Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix some small errors in the tests

  • Loading branch information...
commit ac45f9c9c5b5f64556c95d458368185298d21042 1 parent beefac8
Andrew Godwin authored
6  tests/migrations/test_base.py
... ...
@@ -1,12 +1,14 @@
1  
-from django.test import TestCase
  1
+from django.test import TransactionTestCase
2 2
 from django.db import connection
3 3
 
4 4
 
5  
-class MigrationTestBase(TestCase):
  5
+class MigrationTestBase(TransactionTestCase):
6 6
     """
7 7
     Contains an extended set of asserts for testing migrations and schema operations.
8 8
     """
9 9
 
  10
+    available_apps = ["migrations"]
  11
+
10 12
     def assertTableExists(self, table):
11 13
         self.assertIn(table, connection.introspection.get_table_list(connection.cursor()))
12 14
 
5  tests/migrations/test_executor.py
@@ -38,6 +38,11 @@ def test_run(self):
38 38
         # Are the tables there now?
39 39
         self.assertIn("migrations_author", connection.introspection.get_table_list(connection.cursor()))
40 40
         self.assertIn("migrations_book", connection.introspection.get_table_list(connection.cursor()))
  41
+        # Alright, let's undo what we did
  42
+        executor.migrate([("migrations", None)])
  43
+        # Are the tables gone?
  44
+        self.assertNotIn("migrations_author", connection.introspection.get_table_list(connection.cursor()))
  45
+        self.assertNotIn("migrations_book", connection.introspection.get_table_list(connection.cursor()))
41 46
 
42 47
     @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations", "sessions": "migrations.test_migrations_2"})
43 48
     def test_empty_plan(self):
13  tests/migrations/test_operations.py
@@ -127,12 +127,13 @@ def test_add_field_m2m(self):
127 127
         self.assertTableExists("test_adflmm_pony_stables")
128 128
         self.assertColumnNotExists("test_adflmm_pony", "stables")
129 129
         # Make sure the M2M field actually works
130  
-        app_cache = new_state.render()
131  
-        Pony = app_cache.get_model("test_adflmm", "Pony")
132  
-        p = Pony.objects.create(pink=False, weight=4.55)
133  
-        p.stables.create()
134  
-        self.assertEqual(p.stables.count(), 1)
135  
-        p.stables.all().delete()
  130
+        with atomic():
  131
+            app_cache = new_state.render()
  132
+            Pony = app_cache.get_model("test_adflmm", "Pony")
  133
+            p = Pony.objects.create(pink=False, weight=4.55)
  134
+            p.stables.create()
  135
+            self.assertEqual(p.stables.count(), 1)
  136
+            p.stables.all().delete()
136 137
         # And test reversal
137 138
         with connection.schema_editor() as editor:
138 139
             operation.database_backwards("test_adflmm", editor, new_state, project_state)
4  tests/schema/tests.py
@@ -195,7 +195,7 @@ def test_alter(self):
195 195
         # Ensure the field is right afterwards
196 196
         columns = self.column_classes(Author)
197 197
         self.assertEqual(columns['name'][0], "TextField")
198  
-        self.assertEqual(columns['name'][1][6], bool(connection.features.interprets_empty_strings_as_nulls))
  198
+        self.assertEqual(bool(columns['name'][1][6]), False)
199 199
 
200 200
     def test_rename(self):
201 201
         """
@@ -230,7 +230,7 @@ def test_m2m_create(self):
230 230
         # Create the tables
231 231
         with connection.schema_editor() as editor:
232 232
             editor.create_model(Author)
233  
-            editor.create_model(Tag)
  233
+            editor.create_model(TagM2MTest)
234 234
             editor.create_model(BookWithM2M)
235 235
         # Ensure there is now an m2m table there
236 236
         columns = self.column_classes(BookWithM2M._meta.get_field_by_name("tags")[0].rel.through)

0 notes on commit ac45f9c

Please sign in to comment.
Something went wrong with that request. Please try again.