Skip to content

Commit

Permalink
fix tests for changes in edc-consent
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Apr 18, 2024
1 parent 5ca49f9 commit 8ccdfc9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions edc_action_item/tests/test_case_mixin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,15 +17,15 @@ 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 = {}
site_visit_schedules.loaded = False
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)
Expand Down
27 changes: 19 additions & 8 deletions edc_action_item/tests/tests/test_action_item.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8ccdfc9

Please sign in to comment.