From 8ccdfc9810ca3e060b183b08867ec535fadf10e2 Mon Sep 17 00:00:00 2001 From: erikvw Date: Thu, 18 Apr 2024 18:14:07 -0500 Subject: [PATCH] fix tests for changes in edc-consent --- edc_action_item/tests/test_case_mixin.py | 5 ++-- .../tests/tests/test_action_item.py | 27 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/edc_action_item/tests/test_case_mixin.py b/edc_action_item/tests/test_case_mixin.py index 32edbd9..5685936 100644 --- a/edc_action_item/tests/test_case_mixin.py +++ b/edc_action_item/tests/test_case_mixin.py @@ -1,5 +1,6 @@ from dateutil.relativedelta import relativedelta from django.test import TestCase +from edc_consent.consent_definition import ConsentDefinition from edc_consent.site_consents import site_consents from edc_facility.import_holidays import import_holidays from edc_registration.models import RegisteredSubject @@ -16,7 +17,7 @@ def setUpTestData(cls): import_holidays() @staticmethod - def enroll(subject_identifier=None): + def enroll(subject_identifier=None, cdef: ConsentDefinition | None = None): subject_identifier = subject_identifier or "1111111" site_visit_schedules._registry = {} @@ -24,7 +25,7 @@ def enroll(subject_identifier=None): site_visit_schedules.register(visit_schedule) site_consents.registry = {} - site_consents.register(consent_v1) + site_consents.register(cdef or consent_v1) consent_datetime = get_utcnow() cdef = site_consents.get_consent_definition(report_datetime=consent_datetime) diff --git a/edc_action_item/tests/tests/test_action_item.py b/edc_action_item/tests/tests/test_action_item.py index 8cb50eb..ec65a3c 100644 --- a/edc_action_item/tests/tests/test_action_item.py +++ b/edc_action_item/tests/tests/test_action_item.py @@ -1,7 +1,11 @@ +from datetime import datetime +from zoneinfo import ZoneInfo + +import time_machine from dateutil.relativedelta import relativedelta from django.core.exceptions import ObjectDoesNotExist from django.db.models.deletion import ProtectedError -from django.test import TestCase +from django.test import TestCase, override_settings, tag from edc_consent.tests.consent_test_utils import consent_definition_factory from edc_constants.constants import CANCELLED, CLOSED, NEW, OPEN from edc_utils import get_utcnow @@ -19,21 +23,27 @@ from ..test_case_mixin import TestCaseMixin +@override_settings( + EDC_PROTOCOL_STUDY_OPEN_DATETIME=datetime(2018, 6, 10, 0, 00, tzinfo=ZoneInfo("UTC")), + EDC_PROTOCOL_STUDY_CLOSE_DATETIME=datetime(2027, 6, 10, 0, 00, tzinfo=ZoneInfo("UTC")), +) class TestActionItem(TestCaseMixin, TestCase): - @classmethod - def setUpTestData(cls): - consent_definition_factory( - model="edc_action_item.subjectconsent", + + def setUp(self): + test_datetime = datetime(2019, 6, 11, 8, 00, tzinfo=ZoneInfo("UTC")) + traveller = time_machine.travel(test_datetime) + traveller.start() + consent_v1 = consent_definition_factory( + model="edc_action_item.subjectconsentv1", start=get_utcnow() - relativedelta(years=1), end=get_utcnow() + relativedelta(years=1), ) - - def setUp(self): - self.subject_identifier = self.enroll() + self.subject_identifier = self.enroll(cdef=consent_v1) site_action_items.registry = {} site_action_items.register(FormZeroAction) get_action_type(FormZeroAction) self.action_type = ActionType.objects.get(name=FormZeroAction.name) + traveller.stop() def test_creates(self): obj = ActionItem.objects.create( @@ -239,6 +249,7 @@ def test_delete3(self): self.assertRaises(ProtectedError, action_item.delete) + @tag("1") def test_new(self): site_action_items.register(FormOneAction) site_action_items.register(FormTwoAction)