Skip to content

Commit

Permalink
update form, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 6, 2024
1 parent 1f69663 commit 4bab5c5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
4 changes: 3 additions & 1 deletion edc_action_item/forms/action_item_form.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from django import forms
from django.apps import apps as django_apps
from edc_consent.modelform_mixins import RequiresConsentModelFormMixin
from edc_constants.constants import CANCELLED, NEW, OPEN
from edc_model_form.mixins import BaseModelFormMixin

from ..models import ActionItem


class ActionItemForm(forms.ModelForm):
class ActionItemForm(RequiresConsentModelFormMixin, BaseModelFormMixin, forms.ModelForm):
subject_identifier = forms.CharField(
label="Subject Identifier",
required=False,
Expand Down
23 changes: 22 additions & 1 deletion edc_action_item/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,37 @@

from django.db import models
from django.db.models.deletion import CASCADE, PROTECT
from edc_consent.field_mixins import PersonalFieldsMixin
from edc_consent.model_mixins import ConsentModelMixin
from edc_constants.choices import YES_NO
from edc_constants.constants import YES
from edc_crf.model_mixins import CrfWithActionModelMixin
from edc_identifier.model_mixins import NonUniqueSubjectIdentifierFieldMixin
from edc_identifier.model_mixins import (
NonUniqueSubjectIdentifierFieldMixin,
NonUniqueSubjectIdentifierModelMixin,
)
from edc_model.models import BaseUuidModel, HistoricalRecords
from edc_sites.model_mixins import SiteModelMixin

from ..models import ActionModelMixin


class SubjectConsent(
ConsentModelMixin,
SiteModelMixin,
NonUniqueSubjectIdentifierModelMixin,
PersonalFieldsMixin,
BaseUuidModel,
):
screening_identifier = models.CharField(
verbose_name="Screening identifier", max_length=50, unique=True
)
history = HistoricalRecords()

class Meta(ConsentModelMixin.Meta):
pass


class SubjectIdentifierModelManager(models.Manager):
def get_by_natural_key(self, subject_identifier):
return self.get(subject_identifier=subject_identifier)
Expand Down
12 changes: 9 additions & 3 deletions edc_action_item/tests/test_case_mixin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dateutil.relativedelta import relativedelta
from django.test import TestCase
from edc_consent import site_consents
from edc_facility.import_holidays import import_holidays
from edc_metadata.tests.models import SubjectConsent
from edc_registration.models import RegisteredSubject
from edc_utils import get_utcnow
from edc_visit_schedule.site_visit_schedules import site_visit_schedules
Expand All @@ -21,9 +22,14 @@ def enroll(subject_identifier=None):
site_visit_schedules.loaded = False
site_visit_schedules.register(visit_schedule)

subject_consent = SubjectConsent.objects.create(
subject_identifier=subject_identifier, consent_datetime=get_utcnow()
consent_datetime = get_utcnow()
cdef = site_consents.get_consent_definition(report_datetime=consent_datetime)
subject_consent = cdef.model_cls.objects.create(
subject_identifier=subject_identifier,
consent_datetime=consent_datetime,
dob=get_utcnow() - relativedelta(years=25),
)
RegisteredSubject.objects.create(subject_identifier=subject_identifier)
_, schedule = site_visit_schedules.get_by_onschedule_model("edc_metadata.onschedule")
schedule.put_on_schedule(
subject_identifier=subject_consent.subject_identifier,
Expand Down
16 changes: 14 additions & 2 deletions edc_action_item/tests/tests/test_action_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
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, 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

from edc_action_item.action import Action
from edc_action_item.create_or_update_action_type import create_or_update_action_type
Expand All @@ -17,8 +20,16 @@


class TestActionItem(TestCaseMixin, TestCase):
@classmethod
def setUpTestData(cls):
consent_definition_factory(
model="edc_action_item.subjectconsent",
start=get_utcnow() - relativedelta(years=1),
end=get_utcnow() + relativedelta(years=1),
)

def setUp(self):
self.subject_identifier = self.fake_enroll()
self.subject_identifier = self.enroll()
site_action_items.registry = {}
site_action_items.register(FormZeroAction)
get_action_type(FormZeroAction)
Expand Down Expand Up @@ -74,6 +85,7 @@ def test_identifier_not_changed(self):
except ObjectDoesNotExist:
self.fail("ActionItem unexpectedly does not exist")

@tag("1")
def test_changes_action_item_status_from_new_to_open_on_edit(self):
action_type = ActionType.objects.get(name=FormZeroAction.name)

Expand Down
2 changes: 1 addition & 1 deletion edc_action_item/tests/visit_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
name="schedule",
onschedule_model="edc_metadata.onschedule",
offschedule_model="edc_metadata.offschedule",
consent_model="edc_metadata.subjectconsent",
consent_model="edc_action_item.subjectconsent",
appointment_model="edc_appointment.appointment",
)

Expand Down

0 comments on commit 4bab5c5

Please sign in to comment.