From ad9f5fa949381875151a5329a170a57ebac1790b Mon Sep 17 00:00:00 2001 From: erikvw Date: Mon, 9 Sep 2024 20:12:22 -0500 Subject: [PATCH] update test settings --- edc_pharmacy/tests/__init__.py | 1 - edc_pharmacy/tests/consents.py | 2 - edc_pharmacy/tests/test_settings.py | 67 +++++++++++++++++ edc_pharmacy/tests/tests/test_stock.py | 6 ++ .../tests/tests/test_study_medication_crf.py | 6 ++ runtests.py | 74 +------------------ 6 files changed, 81 insertions(+), 75 deletions(-) create mode 100644 edc_pharmacy/tests/test_settings.py diff --git a/edc_pharmacy/tests/__init__.py b/edc_pharmacy/tests/__init__.py index f775c07..e69de29 100644 --- a/edc_pharmacy/tests/__init__.py +++ b/edc_pharmacy/tests/__init__.py @@ -1 +0,0 @@ -from .models import OffSchedule, OnSchedule, StudyMedication diff --git a/edc_pharmacy/tests/consents.py b/edc_pharmacy/tests/consents.py index 61c686b..c78dbf4 100644 --- a/edc_pharmacy/tests/consents.py +++ b/edc_pharmacy/tests/consents.py @@ -1,5 +1,4 @@ from edc_consent.consent_definition import ConsentDefinition -from edc_consent.site_consents import site_consents from edc_constants.constants import FEMALE, MALE from edc_protocol.research_protocol_config import ResearchProtocolConfig @@ -13,4 +12,3 @@ age_max=64, gender=[MALE, FEMALE], ) -site_consents.register(consent_v1) diff --git a/edc_pharmacy/tests/test_settings.py b/edc_pharmacy/tests/test_settings.py new file mode 100644 index 0000000..cc44081 --- /dev/null +++ b/edc_pharmacy/tests/test_settings.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +import sys +from pathlib import Path + +from dateutil.relativedelta import relativedelta +from edc_test_settings.default_test_settings import DefaultTestSettings +from edc_utils import get_utcnow + +app_name = "edc_pharmacy" +base_dir = Path(__file__).absolute().parent.parent.parent + +project_settings = DefaultTestSettings( + calling_file=__file__, + SILENCED_SYSTEM_CHECKS=["sites.E101", "edc_navbar.E002", "edc_navbar.E003"], + EDC_AUTH_CODENAMES_WARN_ONLY=True, + EDC_AUTH_SKIP_SITE_AUTHS=True, + EDC_AUTH_SKIP_AUTH_UPDATER=True, + BASE_DIR=base_dir, + APP_NAME=app_name, + EDC_SITES_REGISTER_DEFAULT=True, + EDC_PROTOCOL_STUDY_OPEN_DATETIME=( + get_utcnow().replace(microsecond=0, second=0, minute=0, hour=0) + - relativedelta(years=6) + ), + EDC_PROTOCOL_STUDY_CLOSE_DATETIME=( + get_utcnow().replace(microsecond=999999, second=59, minute=59, hour=11) + + relativedelta(years=6) + ), + INSTALLED_APPS=[ + "django.contrib.admin", + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.messages", + "django.contrib.staticfiles", + "django.contrib.sites", + "django_crypto_fields.apps.AppConfig", + "multisite", + "edc_action_item.apps.AppConfig", + "edc_adverse_event.apps.AppConfig", + "adverse_event_app.apps.AppConfig", + "edc_appointment.apps.AppConfig", + "edc_device.apps.AppConfig", + "edc_facility.apps.AppConfig", + "edc_identifier.apps.AppConfig", + "edc_list_data.apps.AppConfig", + "edc_metadata.apps.AppConfig", + "edc_notification.apps.AppConfig", + "edc_offstudy.apps.AppConfig", + "edc_randomization.apps.AppConfig", + "edc_registration.apps.AppConfig", + "edc_sites.apps.AppConfig", + "edc_timepoint.apps.AppConfig", + "edc_visit_schedule.apps.AppConfig", + "edc_visit_tracking.apps.AppConfig", + "edc_dashboard.apps.AppConfig", + "edc_subject_dashboard.apps.AppConfig", + "edc_review_dashboard.apps.AppConfig", + "edc_pharmacy.apps.AppConfig", + "edc_appconfig.apps.AppConfig", + ], + add_dashboard_middleware=True, +).settings + + +for k, v in project_settings.items(): + setattr(sys.modules[__name__], k, v) diff --git a/edc_pharmacy/tests/tests/test_stock.py b/edc_pharmacy/tests/tests/test_stock.py index f52148b..a3e0835 100644 --- a/edc_pharmacy/tests/tests/test_stock.py +++ b/edc_pharmacy/tests/tests/test_stock.py @@ -1,5 +1,6 @@ from dateutil.relativedelta import relativedelta from django.test import TestCase +from edc_consent import site_consents from edc_list_data import site_list_data from edc_utils import get_utcnow @@ -22,11 +23,16 @@ get_shelf, ) +from ..consents import consent_v1 + class TestPrescription(TestCase): def setUp(self): site_list_data.initialize() site_list_data.autodiscover() + site_consents.registry = {} + site_consents.loaded = False + site_consents.register(consent_v1) self.medication = Medication.objects.create( name="METFORMIN", diff --git a/edc_pharmacy/tests/tests/test_study_medication_crf.py b/edc_pharmacy/tests/tests/test_study_medication_crf.py index 1054380..d15710c 100644 --- a/edc_pharmacy/tests/tests/test_study_medication_crf.py +++ b/edc_pharmacy/tests/tests/test_study_medication_crf.py @@ -11,6 +11,7 @@ from edc_appointment.models import Appointment from edc_appointment.tests.helper import Helper from edc_appointment.utils import get_next_appointment +from edc_consent import site_consents from edc_constants.constants import YES from edc_facility import import_holidays from edc_protocol.research_protocol_config import ResearchProtocolConfig @@ -32,6 +33,7 @@ Units, ) +from ..consents import consent_v1 from ..forms import StudyMedicationForm from ..models import StudyMedication, SubjectVisit from ..visit_schedule import visit_schedule @@ -47,6 +49,10 @@ def setUpTestData(cls): pre_save.disconnect(dispatch_uid="requires_consent_on_pre_save") def setUp(self) -> None: + site_consents.registry = {} + site_consents.loaded = False + site_consents.register(consent_v1) + site_visit_schedules._registry = {} site_visit_schedules.loaded = False site_visit_schedules.register(visit_schedule) diff --git a/runtests.py b/runtests.py index 4c65344..6d3e754 100644 --- a/runtests.py +++ b/runtests.py @@ -1,75 +1,5 @@ #!/usr/bin/env python -import logging -from pathlib import Path - -from dateutil.relativedelta import relativedelta -from edc_test_utils import DefaultTestSettings, func_main -from edc_utils import get_utcnow - -app_name = "edc_pharmacy" -base_dir = Path(__file__).absolute().parent - -project_settings = DefaultTestSettings( - calling_file=__file__, - SILENCED_SYSTEM_CHECKS=["sites.E101", "edc_navbar.E002", "edc_navbar.E003"], - EDC_AUTH_CODENAMES_WARN_ONLY=True, - EDC_AUTH_SKIP_SITE_AUTHS=True, - EDC_AUTH_SKIP_AUTH_UPDATER=True, - BASE_DIR=base_dir, - APP_NAME=app_name, - EDC_SITES_REGISTER_DEFAULT=True, - EDC_PROTOCOL_STUDY_OPEN_DATETIME=( - get_utcnow().replace(microsecond=0, second=0, minute=0, hour=0) - - relativedelta(years=6) - ), - EDC_PROTOCOL_STUDY_CLOSE_DATETIME=( - get_utcnow().replace(microsecond=999999, second=59, minute=59, hour=11) - + relativedelta(years=6) - ), - INSTALLED_APPS=[ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "django.contrib.sites", - "django_crypto_fields.apps.AppConfig", - "multisite", - "edc_action_item.apps.AppConfig", - "edc_appointment.apps.AppConfig", - "edc_auth.apps.AppConfig", - "edc_data_manager.apps.AppConfig", - "edc_device.apps.AppConfig", - "edc_facility.apps.AppConfig", - "edc_form_runners.apps.AppConfig", - "edc_identifier.apps.AppConfig", - "edc_lab.apps.AppConfig", - "edc_label.apps.AppConfig", - "edc_locator.apps.AppConfig", - "edc_metadata.apps.AppConfig", - "edc_notification.apps.AppConfig", - "edc_offstudy.apps.AppConfig", - "edc_randomization.apps.AppConfig", - "edc_registration.apps.AppConfig", - "edc_sites.apps.AppConfig", - "edc_timepoint.apps.AppConfig", - "edc_visit_schedule.apps.AppConfig", - "edc_visit_tracking.apps.AppConfig", - "edc_prn.apps.AppConfig", - "edc_pdf_reports.apps.AppConfig", - "edc_pharmacy.apps.AppConfig", - "edc_appconfig.apps.AppConfig", - ], - add_dashboard_middleware=True, - add_lab_dashboard_middleware=True, -).settings - - -def main(): - func_main(project_settings, f"{app_name}.tests") - +from edc_test_settings.func_main import func_main2 if __name__ == "__main__": - logging.basicConfig() - main() + func_main2("edc_pharmacy.tests.test_settings", "edc_pharmacy.tests")