From 1ca91e7ec5d59c6551b67e2d0783129cdc18a7ee Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 31 Oct 2019 12:57:40 -0400 Subject: [PATCH] Add cache invalidation test case mixins Add PermissionTestCaseMixin and SmartSettingTestCaseMixin to better organize cache invalidation of both apps for tests. Signed-off-by: Roberto Rosario --- HISTORY.rst | 2 ++ mayan/apps/common/tests/base.py | 14 +++++--------- mayan/apps/permissions/tests/mixins.py | 8 +++++++- mayan/apps/smart_settings/tests/mixins.py | 6 ++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index adb5b1bb37..340e5bacf6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -31,6 +31,8 @@ - Improve duplicated document list view logic to not show documents with trashed duplicates. - Backport Docker composer makefile targets. +- Add PermissionTestCaseMixin and SmartSettingTestCaseMixin to better + organize cache invalidation of both apps for tests. 3.2.8 (2019-10-01) ================== diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index 3c352df9df..1a49c23867 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -5,8 +5,8 @@ from django.test import TestCase from django_downloadview import assert_download_response from mayan.apps.acls.tests.mixins import ACLTestCaseMixin -from mayan.apps.permissions.classes import Permission -from mayan.apps.smart_settings.classes import Namespace +from mayan.apps.permissions.tests.mixins import PermissionTestCaseMixin +from mayan.apps.smart_settings.tests.mixins import SmartSettingsTestCaseMixin from mayan.apps.user_management.tests.mixins import UserTestMixin from .mixins import ( @@ -21,19 +21,15 @@ from .mixins import ( class BaseTestCase( SilenceLoggerTestCaseMixin, ConnectionsCheckTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, ACLTestCaseMixin, - ModelTestCaseMixin, OpenFileCheckTestCaseMixin, - TempfileCheckTestCasekMixin, UserTestMixin, TestCase + ModelTestCaseMixin, OpenFileCheckTestCaseMixin, PermissionTestCaseMixin, + SmartSettingsTestCaseMixin, TempfileCheckTestCasekMixin, UserTestMixin, + TestCase ): """ This is the most basic test case class any test in the project should use. """ assert_download_response = assert_download_response - def setUp(self): - super(BaseTestCase, self).setUp() - Namespace.invalidate_cache_all() - Permission.invalidate_cache() - class GenericViewTestCase( ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin, diff --git a/mayan/apps/permissions/tests/mixins.py b/mayan/apps/permissions/tests/mixins.py index 146746e44a..4270626c0c 100644 --- a/mayan/apps/permissions/tests/mixins.py +++ b/mayan/apps/permissions/tests/mixins.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from ..classes import PermissionNamespace +from ..classes import Permission, PermissionNamespace from ..models import Role from .literals import ( @@ -45,6 +45,12 @@ class PermissionTestMixin(object): ) +class PermissionTestCaseMixin(object): + def setUp(self): + super(PermissionTestCaseMixin, self).setUp() + Permission.invalidate_cache() + + class RoleAPIViewTestMixin(object): def _request_test_role_create_api_view(self, extra_data=None): data = { diff --git a/mayan/apps/smart_settings/tests/mixins.py b/mayan/apps/smart_settings/tests/mixins.py index 83cadcb4c3..2991121903 100644 --- a/mayan/apps/smart_settings/tests/mixins.py +++ b/mayan/apps/smart_settings/tests/mixins.py @@ -5,6 +5,12 @@ from ..classes import Namespace from .literals import TEST_NAMESPACE_LABEL, TEST_NAMESPACE_NAME +class SmartSettingsTestCaseMixin(object): + def setUp(self): + super(SmartSettingsTestCaseMixin, self).setUp() + Namespace.invalidate_cache_all() + + class SmartSettingTestMixin(object): def _create_test_settings_namespace(self): try: