From 7cf8cd2f28b4e1cc0ef216df34661a35dc79f401 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 10 May 2019 19:30:33 -0400 Subject: [PATCH] Add test mixin to convert instances to dicts Signed-off-by: Roberto Rosario --- mayan/apps/common/tests/base.py | 19 ++++++++++++++----- mayan/apps/common/tests/mixins.py | 7 +++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index 1d005a2769..f4c8ed4961 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -10,13 +10,19 @@ from mayan.apps.smart_settings.classes import Namespace from .mixins import ( ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin, - DatabaseConversionMixin, OpenFileCheckTestCaseMixin, - RandomPrimaryKeyModelMonkeyPatchMixin, SilenceLoggerTestCaseMixin, - TempfileCheckTestCasekMixin, TestViewTestCaseMixin + DatabaseConversionMixin, ModelTestCaseMixin, + OpenFileCheckTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, + SilenceLoggerTestCaseMixin, TempfileCheckTestCasekMixin, + TestViewTestCaseMixin ) -class BaseTestCase(SilenceLoggerTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, TestCase): +class BaseTestCase( + SilenceLoggerTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, + DatabaseConversionMixin, ACLTestCaseMixin, + ModelTestCaseMixin, OpenFileCheckTestCaseMixin, + TempfileCheckTestCasekMixin, TestCase +): """ This is the most basic test case class any test in the project should use. """ @@ -28,7 +34,10 @@ class BaseTestCase(SilenceLoggerTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchM Permission.invalidate_cache() -class GenericViewTestCase(ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin, TestViewTestCaseMixin, BaseTestCase): +class GenericViewTestCase( + ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin, + TestViewTestCaseMixin, BaseTestCase +): """ A generic view test case built on top of the base test case providing a single, user customizable view to test object resolution and shorthand diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index 03aa0260da..c6ac79fcb6 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -113,6 +113,13 @@ class DatabaseConversionMixin(object): ) +class ModelTestCaseMixin(object): + def _model_instance_to_dictionary(self, instance): + return instance._meta.model._default_manager.filter( + pk=instance.pk + ).values()[0] + + class OpenFileCheckTestCaseMixin(object): def _get_descriptor_count(self): process = psutil.Process()