|
| 1 | +from unittest.mock import patch |
| 2 | + |
| 3 | +from django.apps import apps |
| 4 | +from django.test import SimpleTestCase, override_settings |
| 5 | + |
| 6 | +from debug_toolbar.apps import _manage_migrations_visibility |
| 7 | + |
| 8 | + |
| 9 | +class AppsTestCase(SimpleTestCase): |
| 10 | + @override_settings( |
| 11 | + DEBUG_TOOLBAR_CONFIG={ |
| 12 | + "TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore" |
| 13 | + } |
| 14 | + ) |
| 15 | + @patch("debug_toolbar.apps.settings.MIGRATION_MODULES") |
| 16 | + def test_migrations_are_visible(self, mocked_migration_modules): |
| 17 | + _manage_migrations_visibility("debug_toolbar") |
| 18 | + self.assertFalse(mocked_migration_modules.setdefault.called) |
| 19 | + |
| 20 | + @override_settings( |
| 21 | + DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"} |
| 22 | + ) |
| 23 | + @patch("debug_toolbar.apps.settings.MIGRATION_MODULES") |
| 24 | + def test_migrations_are_hidden(self, mocked_migration_modules): |
| 25 | + _manage_migrations_visibility("debug_toolbar") |
| 26 | + mocked_migration_modules.setdefault.assert_called_once_with( |
| 27 | + "debug_toolbar", None |
| 28 | + ) |
| 29 | + |
| 30 | + @override_settings( |
| 31 | + DEBUG_TOOLBAR_CONFIG={ |
| 32 | + "TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore" |
| 33 | + } |
| 34 | + ) |
| 35 | + def test_models_are_visible(self): |
| 36 | + app_config = apps.get_app_config("debug_toolbar") |
| 37 | + app_config.import_models() |
| 38 | + apps.get_model("debug_toolbar", "HistoryEntry") |
| 39 | + |
| 40 | + @override_settings( |
| 41 | + DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"} |
| 42 | + ) |
| 43 | + def test_models_are_hidden(self): |
| 44 | + app_config = apps.get_app_config("debug_toolbar") |
| 45 | + app_config.import_models() |
| 46 | + with self.assertRaises(LookupError): |
| 47 | + apps.get_model("debug_toolbar", "HistoryEntry") |
0 commit comments