Пример #1
0
    def test_check_attrs_for_form_one_next_action(self):

        form_one = FormOne.objects.create(
            subject_identifier=self.subject_identifier)

        action_type_two = get_action_type(
            site_action_items.get(FormTwo.action_name))
        action_item_one = ActionItem.objects.get(
            action_identifier=form_one.action_identifier, status=CLOSED)
        action_item_two = ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            action_type__name="submit-form-two",
            status=NEW,
        )
        form_one = FormOne.objects.get(id=form_one.id)

        self.assertEqual(action_item_two.subject_identifier,
                         form_one.subject_identifier)
        self.assertNotEqual(action_item_two.action_identifier,
                            form_one.action_identifier)
        self.assertEqual(action_item_two.reference_model,
                         FormTwo._meta.label_lower)
        self.assertEqual(action_item_two.related_action_item,
                         form_one.action_item)
        self.assertEqual(action_item_two.related_reference_model,
                         FormOne._meta.label_lower)
        self.assertEqual(action_item_two.parent_action_item,
                         form_one.action_item)
        self.assertEqual(
            action_item_two.parent_action_item.reference_model,
            action_item_one.reference_model,
        )
        self.assertEqual(action_item_two.parent_action_item, action_item_one)
        self.assertEqual(get_action_type(action_item_two.action_cls),
                         action_type_two)
Пример #2
0
    def test_ae_initial_action(self):
        """Asserts an AeInitial creates one and only one
        AeFollowupAction.
        """
        # create ae initial action
        action_type = get_action_type(AeInitialAction)
        action_item = ActionItem.objects.create(
            subject_identifier=self.subject_identifier, action_type=action_type
        )
        # create ae initial
        ae_initial = baker.make_recipe(
            "adverse_event_app.aeinitial",
            action_identifier=action_item.action_identifier,
            subject_identifier=self.subject_identifier,
        )
        ActionItem.objects.get(
            subject_identifier=self.subject_identifier, action_type=action_type
        )
        action_item = ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            action_type=action_type,
            status=CLOSED,
        )

        # assert ae initial action created ONE ae followup
        action_type = get_action_type(AeFollowupAction)
        self.assertEqual(
            ActionItem.objects.filter(
                subject_identifier=self.subject_identifier, action_type=action_type
            ).count(),
            1,
        )

        # assert ae initial action created ONE ae followup
        # with correct parent action identifier
        ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            parent_action_item=action_item,
            action_type=action_type,
            status=NEW,
        )

        # resave ae initial and show does not create another followup
        ae_initial.save()
        ae_initial.save()
        ae_initial.save()
        self.assertEqual(
            ActionItem.objects.filter(
                subject_identifier=self.subject_identifier, action_type=action_type
            ).count(),
            1,
        )
Пример #3
0
    def test_action_is_closed_if_model_creates_action(self):

        # form_one next_actions = [FormTwoAction, FormThreeAction]
        form_one_obj = FormOne.objects.create(
            subject_identifier=self.subject_identifier)
        self.assertEqual(ActionItem.objects.all().count(), 3)

        # next_actions = ['self']
        FormTwo.objects.create(
            subject_identifier=self.subject_identifier,
            parent_action_item=form_one_obj.action_item,
            form_one=form_one_obj,
        )
        self.assertEqual(ActionItem.objects.all().count(), 4)

        # next_actions = [FormZeroAction]
        # should find the existing and NEW FormThreeAction
        # instead of creating one,.
        FormThree.objects.create(
            subject_identifier=self.subject_identifier,
            parent_action_item=form_one_obj.action_item,
        )
        self.assertEqual(ActionItem.objects.all().count(), 5)

        # 3 (1 for each model) are closed
        self.assertEqual(ActionItem.objects.filter(status=CLOSED).count(), 3)
        # next_actions are NEW
        self.assertEqual(ActionItem.objects.filter(status=NEW).count(), 2)

        f1_action_type = get_action_type(FormOneAction)
        f2_action_type = get_action_type(FormTwoAction)
        f3_action_type = get_action_type(FormThreeAction)

        obj = ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            action_type=f1_action_type)
        self.assertEqual(obj.status, CLOSED)

        obj = ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            action_type=f2_action_type,
            status=CLOSED,
        )
        self.assertEqual(obj.status, CLOSED)

        obj = ActionItem.objects.get(
            subject_identifier=self.subject_identifier,
            action_type=f3_action_type,
            status=CLOSED,
        )
        self.assertEqual(obj.status, CLOSED)
Пример #4
0
    def test_action_type_update_from_action_classes(self):
        class MyAction(Action):
            name = "my-action"
            display_name = "my action"
            reference_model = "edc_action_item.reference"

        class MyActionWithNextAction(Action):
            name = "my-action-with-next-as-self"
            display_name = "my action with next as self"
            next_actions = [MyAction]
            reference_model = "edc_action_item.reference"

        class MyActionWithNextActionAsSelf(Action):
            name = "my-action-with-next"
            display_name = "my action with next"
            next_actions = ["self"]
            reference_model = "edc_action_item.reference"

        site_action_items.register(MyAction)
        site_action_items.register(MyActionWithNextAction)
        site_action_items.register(MyActionWithNextActionAsSelf)
        my_action = MyAction(subject_identifier=self.subject_identifier)

        try:
            action_item = ActionItem.objects.get(action_identifier=my_action.action_identifier)
        except ObjectDoesNotExist:
            self.fail("ActionItem unexpectedly does not exist")

        self.assertEqual(my_action.action_item, action_item)
        self.assertEqual(my_action.action_identifier, action_item.action_identifier)
        self.assertEqual(get_action_type(my_action), action_item.action_type)
        self.assertEqual(
            get_action_type(my_action).reference_model, action_item.reference_model
        )
        self.assertIsNone(action_item.parent_action_item_id)

        class MyActionWithIncorrectModel(Action):
            name = "my-action2"
            display_name = "my action 2"
            reference_model = "edc_action_item.TestModelWithAction"

        site_action_items.register(MyActionWithIncorrectModel)

        TestModelWithAction.objects.create(subject_identifier=self.subject_identifier)
        self.assertRaises(
            ObjectDoesNotExist,
            TestModelWithAction.objects.create,
            subject_identifier=self.subject_identifier,
            action_identifier="blahblah",
        )
Пример #5
0
 def test_identifier_not_changed(self):
     site_action_items.registry = {}
     site_action_items.register(FormOneAction)
     get_action_type(FormOneAction)
     action_type = ActionType.objects.get(name=FormOneAction.name)
     obj = ActionItem.objects.create(
         subject_identifier=self.subject_identifier, action_type=action_type
     )
     action_identifier = obj.action_identifier
     obj.save()
     try:
         ActionItem.objects.get(action_identifier=action_identifier)
     except ObjectDoesNotExist:
         self.fail("ActionItem unexpectedly does not exist")
Пример #6
0
 def test_check_attrs_for_own_action1(self):
     """Test when action creates model."""
     obj = FormZero.objects.create(
         subject_identifier=self.subject_identifier)
     action = FormZeroAction(
         subject_identifier=self.subject_identifier,
         action_identifier=obj.action_identifier,
     )
     self.assertEqual(action.subject_identifier, obj.subject_identifier)
     self.assertEqual(action.action_identifier, obj.action_identifier)
     self.assertEqual(action.action_identifier, obj.action_identifier)
     self.assertEqual(action.reference_model, obj._meta.label_lower)
     self.assertTrue(action.linked_to_reference)
     self.assertIsNone(action.related_action_item)
     self.assertIsNone(action.related_reference_model)
     self.assertIsNone(action.parent_action_item)
     action_type = get_action_type(
         site_action_items.get(FormZero.action_name))
     self.assertEqual(get_action_type(action), action_type)
Пример #7
0
 def test_finds_existing_actions0(self):
     """Finds existing actions even when one is created in advance."""
     action_type = get_action_type(FormZeroAction)
     self.assertEqual(ActionItem.objects.all().count(), 0)
     ActionItem.objects.create(subject_identifier=self.subject_identifier,
                               action_type=action_type)
     FormZero.objects.create(subject_identifier=self.subject_identifier)
     obj = FormZero.objects.get(subject_identifier=self.subject_identifier)
     self.assertTrue(
         ActionItem.objects.filter(action_identifier=obj.action_identifier))
     self.assertEqual(ActionItem.objects.all().count(), 1)
     obj.save()
     self.assertEqual(ActionItem.objects.all().count(), 1)
Пример #8
0
    def test_add_action_if_required(self):

        FormFourAction(subject_identifier=self.subject_identifier)
        form_four = FormFour.objects.create(
            subject_identifier=self.subject_identifier, happy=YES)

        self.assertRaises(
            ObjectDoesNotExist,
            ActionItem.objects.get,
            action_type=get_action_type(FormOneAction),
        )

        form_four.happy = NO
        form_four.save()
        try:
            ActionItem.objects.get(action_type=get_action_type(FormOneAction),
                                   status=NEW)
        except ObjectDoesNotExist:
            self.fail("action item unexpectedly does not exist")

        form_four.save()
        try:
            ActionItem.objects.get(action_type=get_action_type(FormOneAction),
                                   status=NEW)
        except ObjectDoesNotExist:
            self.fail("action item unexpectedly does not exist")

        form_one = FormOne.objects.create(
            subject_identifier=self.subject_identifier)

        form_four.save()
        try:
            ActionItem.objects.get(
                action_identifier=form_one.action_identifier, status=CLOSED)
        except ObjectDoesNotExist:
            self.fail("action item unexpectedly does not exist")
Пример #9
0
 def test_creates_next_actions(self):
     f1_action_type = get_action_type(FormOneAction)
     f2_action_type = get_action_type(FormTwoAction)
     f3_action_type = get_action_type(FormThreeAction)
     FormOne.objects.create(subject_identifier=self.subject_identifier)
     self.assertEqual(ActionItem.objects.all().count(), 3)
     self.assertEqual(
         ActionItem.objects.filter(
             subject_identifier=self.subject_identifier,
             action_type=f1_action_type).count(),
         1,
     )
     self.assertEqual(
         ActionItem.objects.filter(
             subject_identifier=self.subject_identifier,
             action_type=f2_action_type).count(),
         1,
     )
     self.assertEqual(
         ActionItem.objects.filter(
             subject_identifier=self.subject_identifier,
             action_type=f3_action_type).count(),
         1,
     )
Пример #10
0
 def test_finds_existing_actions2(self):
     action_type = get_action_type(FormOneAction)
     self.assertEqual(ActionItem.objects.all().count(), 0)
     for _ in range(0, 5):
         ActionItem.objects.create(
             subject_identifier=self.subject_identifier,
             action_type=action_type)
     self.assertEqual(ActionItem.objects.all().count(), 5)
     for _ in range(0, 5):
         FormOne.objects.create(subject_identifier=self.subject_identifier)
     self.assertEqual(
         ActionItem.objects.filter(action_type=action_type).count(), 5)
     self.assertEqual(
         ActionItem.objects.filter(action_type=action_type,
                                   action_identifier__isnull=True).count(),
         0,
     )
Пример #11
0
    def test_ae_initial_updates_existing_action_item(self):
        action_type = get_action_type(AeInitialAction)
        action_item = ActionItem.objects.create(
            subject_identifier=self.subject_identifier,
            action_type=action_type,
            reference_model="adverse_event_app.aeinitial",
        )

        # then create reference model
        ae_initial = baker.make_recipe(
            "adverse_event_app.aeinitial",
            subject_identifier=self.subject_identifier,
            action_identifier=action_item.action_identifier,
        )

        action_item = ActionItem.objects.get(pk=action_item.pk)
        self.assertEqual(action_item.reference_model, ae_initial._meta.label_lower)
        self.assertEqual(action_item.action_identifier, ae_initial.action_identifier)
Пример #12
0
    def test_finds_existing_actions1(self):
        """Finds existing actions even when many are created in advance."""
        # create 5 action items for FormOne
        action_type = get_action_type(FormOneAction)
        self.assertEqual(ActionItem.objects.all().count(), 0)
        for _ in range(0, 5):
            ActionItem.objects.create(
                subject_identifier=self.subject_identifier,
                action_type=action_type)
        self.assertEqual(
            ActionItem.objects.filter(
                subject_identifier=self.subject_identifier).count(),
            5,
        )
        self.assertEqual(
            ActionItem.objects.filter(action_type=action_type).count(), 5)
        self.assertEqual(
            ActionItem.objects.filter(
                action_type=action_type,
                action_identifier__isnull=False,
                linked_to_reference=False,
            ).count(),
            5,
        )

        # create FormOne instances and expect them to link to
        # an exiting action item
        for i in range(0, 5):
            with self.subTest(index=i):
                obj = FormOne.objects.create(
                    subject_identifier=self.subject_identifier)
                self.assertTrue(
                    ActionItem.objects.get(
                        action_identifier=obj.action_identifier))
                self.assertEqual(
                    ActionItem.objects.filter(action_type=action_type).count(),
                    5)
                self.assertEqual(
                    ActionItem.objects.filter(
                        action_type=action_type,
                        action_identifier=obj.action_identifier).count(),
                    1,
                )
Пример #13
0
 def test_check_attrs_for_own_action0(self):
     """Test when model creates action."""
     obj = FormZero.objects.create(
         subject_identifier=self.subject_identifier)
     action_type = get_action_type(
         site_action_items.get(FormZero.action_name))
     action_item = ActionItem.objects.get(
         subject_identifier=self.subject_identifier,
         action_type__name="submit-form-zero",
     )
     self.assertEqual(action_item.subject_identifier,
                      obj.subject_identifier)
     self.assertEqual(action_item.action_identifier, obj.action_identifier)
     self.assertEqual(action_item.action_identifier, obj.action_identifier)
     self.assertEqual(action_item.reference_model, obj._meta.label_lower)
     self.assertTrue(action_item.linked_to_reference)
     self.assertIsNone(action_item.related_action_item)
     self.assertIsNone(action_item.related_reference_model)
     self.assertIsNone(action_item.parent_action_item)
     # self.assertIsNone(action_item.parent_reference_model)
     self.assertIsNone(action_item.parent_action_item)
     self.assertEqual(action_item.action_type, action_type)
Пример #14
0
 def setUp(self):
     self.subject_identifier = self.fake_enroll()
     site_action_items.registry = {}
     site_action_items.register(FormZeroAction)
     get_action_type(FormZeroAction)
     self.action_type = ActionType.objects.get(name=FormZeroAction.name)