Python django.apps.apps.clear_cache() Examples

The following are 20 code examples of django.apps.apps.clear_cache(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.apps.apps , or try the search function .
Example #1
Source File: signals.py    From bioforum with MIT License 6 votes vote down vote up
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        apps.clear_cache()
        try:
            from django.contrib.auth import get_user_model
            UserModel = get_user_model()
        except ImproperlyConfigured:
            # Some tests set an invalid AUTH_USER_MODEL.
            pass
        else:
            from django.contrib.auth import backends
            backends.UserModel = UserModel

            from django.contrib.auth import forms
            forms.UserModel = UserModel

            from django.contrib.auth.handlers import modwsgi
            modwsgi.UserModel = UserModel

            from django.contrib.auth.management.commands import changepassword
            changepassword.UserModel = UserModel

            from django.contrib.auth import views
            views.UserModel = UserModel 
Example #2
Source File: signals.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        apps.clear_cache()
        try:
            from django.contrib.auth import get_user_model
            UserModel = get_user_model()
        except ImproperlyConfigured:
            # Some tests set an invalid AUTH_USER_MODEL.
            pass
        else:
            from django.contrib.auth import backends
            backends.UserModel = UserModel

            from django.contrib.auth import forms
            forms.UserModel = UserModel

            from django.contrib.auth.handlers import modwsgi
            modwsgi.UserModel = UserModel

            from django.contrib.auth.management.commands import changepassword
            changepassword.UserModel = UserModel

            from django.contrib.auth import views
            views.UserModel = UserModel 
Example #3
Source File: signals.py    From python with Apache License 2.0 6 votes vote down vote up
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        apps.clear_cache()
        try:
            from django.contrib.auth import get_user_model
            UserModel = get_user_model()
        except ImproperlyConfigured:
            # Some tests set an invalid AUTH_USER_MODEL.
            pass
        else:
            from django.contrib.auth import backends
            backends.UserModel = UserModel

            from django.contrib.auth import forms
            forms.UserModel = UserModel

            from django.contrib.auth.handlers import modwsgi
            modwsgi.UserModel = UserModel

            from django.contrib.auth.management.commands import changepassword
            changepassword.UserModel = UserModel

            from django.contrib.auth import views
            views.UserModel = UserModel 
Example #4
Source File: signals.py    From python2017 with MIT License 6 votes vote down vote up
def user_model_swapped(**kwargs):
    if kwargs['setting'] == 'AUTH_USER_MODEL':
        apps.clear_cache()
        try:
            from django.contrib.auth import get_user_model
            UserModel = get_user_model()
        except ImproperlyConfigured:
            # Some tests set an invalid AUTH_USER_MODEL.
            pass
        else:
            from django.contrib.auth import backends
            backends.UserModel = UserModel

            from django.contrib.auth import forms
            forms.UserModel = UserModel

            from django.contrib.auth.handlers import modwsgi
            modwsgi.UserModel = UserModel

            from django.contrib.auth.management.commands import changepassword
            changepassword.UserModel = UserModel

            from django.contrib.auth import views
            views.UserModel = UserModel 
Example #5
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_clear_cache_clears_relation_tree(self):
        # The apps.clear_cache is setUp() should have deleted all trees.
        # Exclude abstract models that are not included in the Apps registry
        # and have no cache.
        all_models_with_cache = (m for m in self.all_models if not m._meta.abstract)
        for m in all_models_with_cache:
            self.assertNotIn('_relation_tree', m._meta.__dict__) 
Example #6
Source File: test_fields.py    From resolwe with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super().setUp()

        apps.clear_cache()
        call_command("migrate", verbosity=0, interactive=False)
        # NOTE: Models must be imported after migrations are run. 
Example #7
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        apps.clear_cache() 
Example #8
Source File: test_tablespaces.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        for model in Article, Authors, Reviewers, Scientist:
            model._meta.managed = False

        apps.app_configs['model_options'].models = self._old_models
        apps.all_models['model_options'] = self._old_models
        apps.clear_cache() 
Example #9
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        apps.clear_cache() 
Example #10
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_clear_cache_clears_relation_tree(self):
        # The apps.clear_cache is setUp() should have deleted all trees.
        # Exclude abstract models that are not included in the Apps registry
        # and have no cache.
        all_models_with_cache = (m for m in self.all_models if not m._meta.abstract)
        for m in all_models_with_cache:
            self.assertNotIn('_relation_tree', m._meta.__dict__) 
Example #11
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        apps.clear_cache() 
Example #12
Source File: test_commands.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        apps.app_configs['migrations'].models = self._old_models
        apps.all_models['migrations'] = self._old_models
        apps.clear_cache()
        super().tearDown() 
Example #13
Source File: test_commands.py    From django-sqlserver with MIT License 5 votes vote down vote up
def tearDown(self):
        apps.app_configs['migrations'].models = self._old_models
        apps.all_models['migrations'] = self._old_models
        apps.clear_cache()
        super(MakeMigrationsTests, self).tearDown() 
Example #14
Source File: models.py    From django-collaborative with MIT License 5 votes vote down vote up
def model_cleanup(self):
        create_models()
        importlib.reload(import_module(settings.ROOT_URLCONF))
        app_config = apps.get_app_config("django_models_from_csv")
        hydrate_models_and_permissions(app_config)
        apps.clear_cache()
        clear_url_caches() 
Example #15
Source File: test_streamfield.py    From wagtail with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def tearDown(self):
        # unregister InvalidStreamModel from the overall model registry
        # so that it doesn't break tests elsewhere
        for package in ('wagtailcore', 'wagtail.core.tests'):
            try:
                del apps.all_models[package]['invalidstreammodel']
            except KeyError:
                pass
        apps.clear_cache() 
Example #16
Source File: tests.py    From django-cassandra-engine with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def test_clear_cache_clears_relation_tree(self):
        # The apps.clear_cache is setUp() should have deleted all trees.
        # Exclude abstract models that are not included in the Apps registry
        # and have no cache.
        all_models_with_cache = (m for m in self.all_models if not m._meta.abstract)
        for m in all_models_with_cache:
            self.assertNotIn('_relation_tree', m._meta.__dict__) 
Example #17
Source File: tests.py    From django-cassandra-engine with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def setUp(self):
        apps.clear_cache() 
Example #18
Source File: test_fields.py    From django-osm-field with MIT License 5 votes vote down vote up
def tearDown(self):
        # Taken from IsolatedModelsTestCase in
        # django/tests/invalid_models_tests/base.py
        from django.apps import apps

        apps.app_configs["tests"].models = self._old_models
        apps.all_models["tests"] = self._old_models
        apps.clear_cache() 
Example #19
Source File: test_index.py    From resolwe with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        apps.clear_cache()
        call_command("migrate", verbosity=0, interactive=False)

        super().setUp() 
Example #20
Source File: test_viewsets.py    From resolwe with Apache License 2.0 4 votes vote down vote up
def setUp(self):
        from .test_app.models import TestModel
        from .test_app.elastic_indexes import TestSearchIndex
        from .test_app.viewsets import TestViewSet

        super().setUp()

        apps.clear_cache()
        call_command("migrate", verbosity=0, interactive=False)

        index_builder.indexes = [TestSearchIndex()]
        index_builder.register_signals()

        # Prepare users and groups
        user_model = get_user_model()
        self.user_1 = user_model.objects.create(username="user_one")
        self.user_2 = user_model.objects.create(username="user_two")
        group = Group.objects.create(name="group")
        group.user_set.add(self.user_2)

        tzone = get_current_timezone()
        # Prepare test data
        test_obj_1 = TestModel.objects.create(
            name="Object name 1",
            number=43,
            date=datetime.datetime(2018, 1, 1, 0, 0, tzinfo=tzone),
        )
        test_obj_2 = TestModel.objects.create(
            name="Object name 2",
            number=44,
            date=datetime.datetime(2017, 1, 1, 0, 0, tzinfo=tzone),
        )
        test_obj_3 = TestModel.objects.create(
            name="Object name 3",
            number=45,
            date=datetime.datetime(2016, 1, 1, 0, 0, tzinfo=tzone),
        )

        # Assing permissions
        assign_perm("view_testmodel", self.user_1, test_obj_1)
        assign_perm("view_testmodel", group, test_obj_2)
        assign_perm("view_testmodel", AnonymousUser(), test_obj_3)

        # Prepare test viewset
        self.test_viewset = TestViewSet.as_view(actions={"post": "list_with_post",})