def test_files_content(self): self.assertTableNotExists("migrations_unicodemodel") app_cache.register_model('migrations', UnicodeModel) with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "migrations", verbosity=0) init_file = os.path.join(self.migration_dir, "__init__.py") # Check for existing __init__.py file in migrations folder self.assertTrue(os.path.exists(init_file)) with open(init_file, 'r') as fp: content = force_text(fp.read()) self.assertEqual(content, '') initial_file = os.path.join(self.migration_dir, "0001_initial.py") # Check for existing 0001_initial.py file in migration folder self.assertTrue(os.path.exists(initial_file)) with codecs.open(initial_file, 'r', encoding='utf-8') as fp: content = fp.read() self.assertTrue('# encoding: utf8' in content) self.assertTrue('migrations.CreateModel' in content) if six.PY3: self.assertTrue('úñí©óðé µóðéø' in content) # Meta.verbose_name self.assertTrue('úñí©óðé µóðéøß' in content) # Meta.verbose_name_plural self.assertTrue('ÚÑÍ¢ÓÐÉ' in content) # title.verbose_name self.assertTrue('“Ðjáñgó”' in content) # title.default else: self.assertTrue('\\xfa\\xf1\\xed\\xa9\\xf3\\xf0\\xe9 \\xb5\\xf3\\xf0\\xe9\\xf8' in content) # Meta.verbose_name self.assertTrue('\\xfa\\xf1\\xed\\xa9\\xf3\\xf0\\xe9 \\xb5\\xf3\\xf0\\xe9\\xf8\\xdf' in content) # Meta.verbose_name_plural self.assertTrue('\\xda\\xd1\\xcd\\xa2\\xd3\\xd0\\xc9' in content) # title.verbose_name self.assertTrue('\\u201c\\xd0j\\xe1\\xf1g\\xf3\\u201d' in content) # title.default
def test_failing_migration(self): #21280 - If a migration fails to serialize, it shouldn't generate an empty file. app_cache.register_model('migrations', UnserializableModel) with six.assertRaisesRegex(self, ValueError, r'Cannot serialize'): with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}): call_command("makemigrations", "migrations", verbosity=0) initial_file = os.path.join(self.migration_dir, "0001_initial.py") self.assertFalse(os.path.exists(initial_file))