summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_apps.py
blob: cc907b891343b57027543e19a60aa8d92b8a3077 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)