Skip to content

Commit

Permalink
Add @unregistered_django_model decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
millerdev committed Mar 24, 2022
1 parent ea91b87 commit b4f0b6b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
24 changes: 11 additions & 13 deletions corehq/messaging/scheduling/tests/test_content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import Mock

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

from corehq.apps.domain.shortcuts import create_domain
Expand All @@ -22,6 +21,7 @@
CaseAlertScheduleInstance,
CaseTimedScheduleInstance,
)
from corehq.util.test_utils import unregistered_django_model


AVAILABLE_CUSTOM_SCHEDULING_CONTENT = {
Expand All @@ -46,18 +46,6 @@ def setUpClass(cls):
cls.sms_translations.set_translations('es', {})
cls.sms_translations.save()

global Content, Schedule

class Content(AbstractContent):
pass

class Schedule(AbstractSchedule):
pass

# unregister test models to prevent other test failures
del apps.get_app_config("scheduling").models["content"]
del apps.get_app_config("scheduling").models["schedule"]

@classmethod
def tearDownClass(cls):
cls.sms_translations.delete()
Expand Down Expand Up @@ -223,3 +211,13 @@ def test_sms_language_fallback(self):
content.get_translation_from_message_dict(self.domain_obj, message_dict, user_lang),
message_dict['*']
)


@unregistered_django_model
class Content(AbstractContent):
pass


@unregistered_django_model
class Schedule(AbstractSchedule):
pass
20 changes: 10 additions & 10 deletions corehq/messaging/scheduling/tests/test_recipients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import uuid
from datetime import time

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

from unittest.mock import patch
Expand Down Expand Up @@ -39,7 +38,11 @@
ScheduleInstance as AbstractScheduleInstance,
)
from corehq.messaging.scheduling.tests.util import delete_timed_schedules
from corehq.util.test_utils import create_test_case, set_parent_case
from corehq.util.test_utils import (
create_test_case,
set_parent_case,
unregistered_django_model,
)
from testapps.test_pillowtop.utils import process_pillow_changes


Expand Down Expand Up @@ -129,14 +132,6 @@ def setUpClass(cls):
cls.process_pillow_changes = process_pillow_changes('DefaultChangeFeedPillow')
cls.process_pillow_changes.add_pillow(get_case_messaging_sync_pillow())

global ScheduleInstance

class ScheduleInstance(AbstractScheduleInstance):
pass

# unregister test model to prevent other test failures
del apps.get_app_config("scheduling").models["scheduleinstance"]

@classmethod
def tearDownClass(cls):
cls.domain_obj.delete()
Expand Down Expand Up @@ -853,3 +848,8 @@ def test_phone_number_preference(self):
self.assertPhoneEntryCount(3)
self.assertPhoneEntryCount(1, only_count_two_way=True)
self.assertTwoWayEntry(Content.get_two_way_entry_or_phone_number(user), '23456')


@unregistered_django_model
class ScheduleInstance(AbstractScheduleInstance):
pass
7 changes: 7 additions & 0 deletions corehq/util/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from time import sleep, time
from unittest import SkipTest, TestCase

from django.apps import apps
from django.conf import settings
from django.db import connections
from django.db.backends import utils
Expand Down Expand Up @@ -347,6 +348,12 @@ def get_output(self):
return self.output.getvalue()


def unregistered_django_model(model_class):
app_config = apps.get_app_config(model_class._meta.app_label)
del app_config.models[model_class.__name__.lower()]
return model_class


def generate_cases(argsets, cls=None):
"""Make a decorator to generate a set of parameterized test cases
Expand Down

0 comments on commit b4f0b6b

Please sign in to comment.