From 0b8cf970dc8326b34470ba91b7469702964dbf52 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Fri, 1 Nov 2024 08:45:01 -0700 Subject: [PATCH] Update apps.py for 7.6. latest (#39) * Update apps.py for 7.6. latest * Use the arches test runner instead of base test * Formatting --- disco/apps.py | 4 ++- tests/base_test.py | 81 ------------------------------------------ tests/test_settings.py | 2 +- 3 files changed, 4 insertions(+), 83 deletions(-) delete mode 100644 tests/base_test.py diff --git a/disco/apps.py b/disco/apps.py index e20ca95..6f4a90b 100644 --- a/disco/apps.py +++ b/disco/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig +from django.conf import settings from arches.settings_utils import generate_frontend_configuration @@ -9,4 +10,5 @@ class DiscoConfig(AppConfig): is_arches_application = True def ready(self): - generate_frontend_configuration() + if settings.APP_NAME.lower() == self.name: + generate_frontend_configuration() diff --git a/tests/base_test.py b/tests/base_test.py deleted file mode 100644 index 7207443..0000000 --- a/tests/base_test.py +++ /dev/null @@ -1,81 +0,0 @@ -""" -ARCHES - a program developed to inventory and manage immovable cultural heritage. -Copyright (C) 2013 J. Paul Getty Trust and World Monuments Fund - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see . -""" - -from contextlib import contextmanager - -from arches.app.models.system_settings import settings -from arches.app.utils.context_processors import app_settings -from django.test.runner import DiscoverRunner - -from arches.app.search.mappings import ( - prepare_terms_index, - delete_terms_index, - prepare_concepts_index, - delete_concepts_index, - prepare_search_index, - delete_search_index, -) - -# these tests can be run from the command line via -# python manage.py test tests --pattern="*.py" --settings="tests.test_settings" - - -class ArchesTestRunner(DiscoverRunner): - def __init__(self, *args, **kwargs) -> None: - kwargs["debug_mode"] = True - # Unless the user has something other than the Django default, give them - # what they probably want. - if kwargs["pattern"] == "test*.py": - kwargs["pattern"] = "*.py" - super().__init__(*args, **kwargs) - - def setup_databases(self, **kwargs): - ret = super().setup_databases(**kwargs) - - # Some tests don't use the database. - if kwargs.get("aliases", None): - app_settings() # adds languages to system - prepare_terms_index(create=True) - prepare_concepts_index(create=True) - prepare_search_index(create=True) - - return ret - - def teardown_databases(self, old_config, **kwargs): - delete_terms_index() - delete_concepts_index() - delete_search_index() - - super().teardown_databases(old_config, **kwargs) - - -@contextmanager -def sync_overridden_test_settings_to_arches(): - """Django's @override_settings test util acts on django.conf.settings, - which is not enough for us, because we use SystemSettings at runtime. - - This context manager swaps in the overridden django.conf.settings for SystemSettings. - """ - from django.conf import settings as patched_settings - - original_settings_wrapped = settings._wrapped - try: - settings._wrapped = patched_settings._wrapped - yield - finally: - settings._wrapped = original_settings_wrapped diff --git a/tests/test_settings.py b/tests/test_settings.py index c2d19ee..03ab71e 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -63,7 +63,7 @@ ELASTICSEARCH_PREFIX = "test" -TEST_RUNNER = "tests.base_test.ArchesTestRunner" +TEST_RUNNER = "arches.test.runner.ArchesTestRunner" SILENCED_SYSTEM_CHECKS.append( "arches.W001", # Cache backend does not support rate-limiting )