Example #1
0
    def test_invalid_for_educational_mismatch(self) -> None:
        self.group.ip_use.educational = True
        self.dbsession.add(self.group)
        self.dbsession.commit()

        schema = TaskScheduleItemSchema().bind(request=self.req)
        appstruct = {
            ViewParam.SCHEDULE_ID: self.schedule.id,
            ViewParam.TABLE_NAME: "mfi20",
            ViewParam.CLINICIAN_CONFIRMATION: True,
            ViewParam.DUE_FROM: Duration(days=0),
            ViewParam.DUE_WITHIN: Duration(days=10),
        }

        cstruct = schema.serialize(appstruct)

        # No real world example prohibits educational use
        mock_task_class = mock.Mock(prohibits_educational=True)
        with mock.patch.object(schema,
                               "_get_task_class",
                               return_value=mock_task_class):
            with self.assertRaises(Invalid) as cm:
                schema.deserialize(cstruct)

        self.assertIn("prohibits educational", cm.exception.messages()[0])
Example #2
0
    def test_valid_for_clinician_task_with_confirmation(self) -> None:
        schema = TaskScheduleItemSchema().bind(request=mock.Mock())
        appstruct = {
            ViewParam.SCHEDULE_ID: 1,
            ViewParam.TABLE_NAME: "elixhauserci",
            ViewParam.CLINICIAN_CONFIRMATION: True,
            ViewParam.DUE_FROM: Duration(days=90),
            ViewParam.DUE_WITHIN: Duration(days=100),
        }

        try:
            schema.serialize(appstruct)
        except Invalid:
            self.fail("Validation failed unexpectedly")
Example #3
0
    def test_invalid_for_negative_due_from(self) -> None:
        schema = TaskScheduleItemSchema().bind(request=self.req)
        appstruct = {
            ViewParam.SCHEDULE_ID: 1,
            ViewParam.TABLE_NAME: "phq9",
            ViewParam.CLINICIAN_CONFIRMATION: False,
            ViewParam.DUE_FROM: Duration(days=-1),
            ViewParam.DUE_WITHIN: Duration(days=10),
        }

        cstruct = schema.serialize(appstruct)
        with self.assertRaises(Invalid) as cm:
            schema.deserialize(cstruct)

        self.assertIn("must be zero or more days", cm.exception.messages()[0])
Example #4
0
    def test_invalid_for_clinician_task_with_no_confirmation(self) -> None:
        schema = TaskScheduleItemSchema().bind(request=self.req)
        appstruct = {
            ViewParam.SCHEDULE_ID: 1,
            ViewParam.TABLE_NAME: "elixhauserci",
            ViewParam.CLINICIAN_CONFIRMATION: False,
            ViewParam.DUE_FROM: Duration(days=90),
            ViewParam.DUE_WITHIN: Duration(days=100),
        }

        cstruct = schema.serialize(appstruct)
        with self.assertRaises(Invalid) as cm:
            schema.deserialize(cstruct)

        self.assertIn("you must tick 'Allow clinician tasks'",
                      cm.exception.messages()[0])
Example #5
0
    def test_invalid_for_research_mismatch(self) -> None:
        self.group.ip_use.research = True
        self.dbsession.add(self.group)
        self.dbsession.commit()

        schema = TaskScheduleItemSchema().bind(request=self.req)
        appstruct = {
            ViewParam.SCHEDULE_ID: self.schedule.id,
            ViewParam.TABLE_NAME: "moca",
            ViewParam.CLINICIAN_CONFIRMATION: True,
            ViewParam.DUE_FROM: Duration(days=0),
            ViewParam.DUE_WITHIN: Duration(days=10),
        }

        cstruct = schema.serialize(appstruct)
        with self.assertRaises(Invalid) as cm:
            schema.deserialize(cstruct)

        self.assertIn("prohibits research", cm.exception.messages()[0])
Example #6
0
 def test_serialize_deserialize(self) -> None:
     appstruct = {
         ViewParam.SCHEDULE_ID: 1,
         ViewParam.TABLE_NAME: "bmi",
         ViewParam.CLINICIAN_CONFIRMATION: False,
         ViewParam.DUE_FROM: Duration(days=90),
         ViewParam.DUE_WITHIN: Duration(days=100),
     }
     schema = TaskScheduleItemSchema().bind(request=self.req)
     self.serialize_deserialize(schema, appstruct)
Example #7
0
    def test_invalid_for_missing_ip_use(self) -> None:
        self.group.ip_use = None
        self.dbsession.add(self.group)
        self.dbsession.commit()

        schema = TaskScheduleItemSchema().bind(request=self.req)
        appstruct = {
            ViewParam.SCHEDULE_ID: self.schedule.id,
            ViewParam.TABLE_NAME: "moca",
            ViewParam.CLINICIAN_CONFIRMATION: True,
            ViewParam.DUE_FROM: Duration(days=0),
            ViewParam.DUE_WITHIN: Duration(days=10),
        }

        cstruct = schema.serialize(appstruct)
        with self.assertRaises(Invalid) as cm:
            schema.deserialize(cstruct)

        self.assertIn(
            f"The group '{self.group.name}' has no intellectual property "
            f"settings",
            cm.exception.messages()[0],
        )