Debian Codegraph @

tests/contenttypes_tests/test_migrations.py

raw
1 from importlib import import_module
2
3 from django.apps import apps
4 from django.contrib.auth.models import Permission
5 from django.contrib.contenttypes.models import ContentType
6 from django.db import DEFAULT_DB_ALIAS, connections
7 from django.test import TransactionTestCase
8
9 remove_content_type_name = import_module(
10 "django.contrib.contenttypes.migrations.0002_remove_content_type_name"
11 )
12
13
14 class MultiDBRemoveContentTypeNameTests(TransactionTestCase):
15 databases = {"default", "other"}
16 available_apps = ["django.contrib.auth", "django.contrib.contenttypes"]
17
18 def test_add_legacy_name_other_database(self):
19 # add_legacy_name() should update ContentType objects in the specified
20 # database. Remove ContentTypes from the default database to distinct
21 # from which database they are fetched.
22 Permission.objects.all().delete()
23 ContentType.objects.all().delete()
24 # ContentType.name in the current version is a property and cannot be
25 # set, so an AttributeError is raised with the other database.
26 with self.assertRaises(AttributeError):
27 with connections["other"].schema_editor() as editor:
28 remove_content_type_name.add_legacy_name(apps, editor)
29 # ContentType were removed from the default database.
30 with connections[DEFAULT_DB_ALIAS].schema_editor() as editor:
31 remove_content_type_name.add_legacy_name(apps, editor)