0
0
mirror of https://github.com/django/django.git synced 2024-11-29 22:56:46 +01:00
django/tests/auth_tests/test_apps.py
2016-09-12 20:03:31 -04:00

63 lines
1.7 KiB
Python

import os
import shutil
import subprocess
import sys
import tempfile
import unittest
from django.db import ConnectionHandler
SETTINGS = """
SECRET_KEY = 'django_auth_tests_secret_key'
INSTALLED_APPS = [
'django.contrib.auth.apps.BaseAuthConfig',
'django.contrib.contenttypes',
]
MIGRATION_MODULES = {'auth': None}
DATABASES = %(databases)r
"""
class AppConfigTests(unittest.TestCase):
def test_no_migrations(self):
project_path = tempfile.mkdtemp()
try:
databases = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(project_path, 'db.sqlite3'),
}
}
with open(os.path.join(project_path, 'no_migrations.py'), 'w') as fp:
fp.write(SETTINGS % {'databases': databases})
with open(os.devnull, 'wb') as devnull:
cmd = [
sys.executable,
'-m', 'django',
'migrate',
'--settings', 'no_migrations',
'--pythonpath', project_path,
]
returncode = subprocess.call(cmd, stdout=devnull, stderr=devnull)
# Migrate command ran without errors.
self.assertEqual(returncode, 0)
# Auth tables weren't created.
conns = ConnectionHandler(databases)
try:
self.assertEqual(
set(conns['default'].introspection.table_names()),
{'django_content_type', 'django_migrations'},
)
finally:
conns.close_all()
finally:
shutil.rmtree(project_path)