File: test_apps.py

package info (click to toggle)
python-django-debug-toolbar 1%3A6.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: python: 7,661; javascript: 636; makefile: 67; sh: 16
file content (47 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download
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
from unittest.mock import patch

from django.apps import apps
from django.test import SimpleTestCase, override_settings

from debug_toolbar.apps import _manage_migrations_visibility


class AppsTestCase(SimpleTestCase):
    @override_settings(
        DEBUG_TOOLBAR_CONFIG={
            "TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore"
        }
    )
    @patch("debug_toolbar.apps.settings.MIGRATION_MODULES")
    def test_migrations_are_visible(self, mocked_migration_modules):
        _manage_migrations_visibility("debug_toolbar")
        self.assertFalse(mocked_migration_modules.setdefault.called)

    @override_settings(
        DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"}
    )
    @patch("debug_toolbar.apps.settings.MIGRATION_MODULES")
    def test_migrations_are_hidden(self, mocked_migration_modules):
        _manage_migrations_visibility("debug_toolbar")
        mocked_migration_modules.setdefault.assert_called_once_with(
            "debug_toolbar", None
        )

    @override_settings(
        DEBUG_TOOLBAR_CONFIG={
            "TOOLBAR_STORE_CLASS": "debug_toolbar.store.DatabaseStore"
        }
    )
    def test_models_are_visible(self):
        app_config = apps.get_app_config("debug_toolbar")
        app_config.import_models()
        apps.get_model("debug_toolbar", "HistoryEntry")

    @override_settings(
        DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "debug_toolbar.store.MemoryStore"}
    )
    def test_models_are_hidden(self):
        app_config = apps.get_app_config("debug_toolbar")
        app_config.import_models()
        with self.assertRaises(LookupError):
            apps.get_model("debug_toolbar", "HistoryEntry")