Ejemplo n.º 1
0
    def test_update_schedule_phase_anchors(self):
        pre_made_phase = SchedulePhase(
            anchor='foo',
            forms=[SchedulePhaseForm(form_id=self.form_1.unique_id)],
        )
        pre_made_phase_2 = SchedulePhase(
            anchor='bar',
            forms=[SchedulePhaseForm(form_id=self.form_2.unique_id)])
        pre_made_phase_3 = SchedulePhase(anchor='burp')
        self.module.schedule_phases = [
            pre_made_phase, pre_made_phase_2, pre_made_phase_3
        ]

        new_anchors = [(2, 'baz'), (1, 'quux')]

        self.module.update_schedule_phase_anchors(new_anchors)
        self.assertEqual(self.module.schedule_phases[0].forms[0].form_id,
                         self.form_1.unique_id)
        self.assertEqual(self.module.schedule_phases[0].anchor,
                         new_anchors[1][1])

        self.assertEqual(self.module.schedule_phases[1].forms[0].form_id,
                         self.form_2.unique_id)
        self.assertEqual(self.module.schedule_phases[1].anchor,
                         new_anchors[0][1])

        self.assertEqual(self.module.schedule_phases[2].anchor, 'burp')
Ejemplo n.º 2
0
    def test_get_phase(self):
        phase = SchedulePhase(
            anchor='some_case_property',
            forms=[SchedulePhaseForm(form_id=self.form_1.unique_id),
                   SchedulePhaseForm(form_id=self.form_2.unique_id)],
        )

        self.module.schedule_phases = [phase]

        self.assertEqual(self.form_1.get_phase(), phase)
        self.assertEqual(self.form_3.get_phase(), None)
Ejemplo n.º 3
0
 def _apply_schedule_phases(self):
     self.module.schedule_phases = [
         SchedulePhase(  # phase 1
             anchor='edd',
             forms=[SchedulePhaseForm(form_id=self.form_1.unique_id),
                    SchedulePhaseForm(form_id=self.form_2.unique_id)],
         ),
         SchedulePhase(  # phase 2
             anchor='dob',
             forms=[SchedulePhaseForm(form_id=self.form_3.unique_id)]
         ),
     ]
Ejemplo n.º 4
0
    def test_update_schedule_phases(self):
        pre_made_phase = SchedulePhase(anchor='foo')
        pre_made_phase_2 = SchedulePhase(anchor='bar')
        self.module.schedule_phases = [pre_made_phase, pre_made_phase_2]

        new_phase = SchedulePhase(anchor='baz')
        updated_phases = [new_phase.anchor, pre_made_phase.anchor]

        self.module.update_schedule_phases(updated_phases)
        self.assertEqual([phase.anchor for phase in self.module.get_schedule_phases()], updated_phases)

        # Test reordering
        self.module.schedule_phases = [pre_made_phase, pre_made_phase_2]
        updated_phases = [pre_made_phase_2.anchor, pre_made_phase.anchor]
        self.module.update_schedule_phases(updated_phases)
        self.assertEqual([phase.anchor for phase in self.module.get_schedule_phases()], updated_phases)

        # Test deletion
        self.module.schedule_phases = [pre_made_phase, pre_made_phase_2]
        updated_phases = []
        self.module.update_schedule_phases(updated_phases)
        self.assertEqual([phase.anchor for phase in self.module.get_schedule_phases()], updated_phases)

        # Test deletion with forms
        phase_with_forms = SchedulePhase(
            anchor='edd',
            forms=[SchedulePhaseForm(form_id=self.form_1.unique_id)],
        )
        self.module.schedule_phases = [phase_with_forms]
        updated_phases = []
        with self.assertRaises(ScheduleError):
            self.module.update_schedule_phases(updated_phases)
Ejemplo n.º 5
0
    def test_multiple_modules(self):
        self._apply_schedule_phases()

        other_module = self.app.get_module(2)
        other_module.has_schedule = True
        scheduled_form = other_module.get_form(0)
        scheduled_form.schedule = FormSchedule(
            visits=[ScheduleVisit(
                due=9), ScheduleVisit(due=11)])
        other_module.forms.append(copy.copy(scheduled_form))

        other_module.schedule_phases = [
            SchedulePhase(
                anchor='case_property',
                forms=[SchedulePhaseForm(form_id=scheduled_form.unique_id)])
        ]

        expected_fixture = u"""
             <partial>
             <fixture id="schedule:m2:p1:f0">
                 <schedule expires="" allow_unscheduled="False">
                     <visit id="1" due="9" repeats="False"/>
                     <visit id="2" due="11" repeats="False"/>
                 </schedule>
             </fixture>
             </partial>
        """

        suite = self.app.create_suite()

        self.assertXmlPartialEqual(expected_fixture, suite,
                                   './fixture[@id="schedule:m2:p1:f0"]')
        self.assertXmlHasXpath(suite, './fixture[@id="schedule:m1:p1:f0"]')
Ejemplo n.º 6
0
 def test_phase_requires_anchor(self):
     self.module.schedule_phases = [
         SchedulePhase(
             forms=[SchedulePhaseForm(form_id=self.form_3.unique_id)]),
     ]
     with self.assertRaises(ScheduleError):
         self.app.create_suite()
Ejemplo n.º 7
0
def get_visit_scheduler_module_and_form_for_test():
    form = AdvancedForm(schedule=FormSchedule(
        unique_id='form-unique-id-1',
        schedule_form_id='form1',
        enabled=True,
        visits=[
            ScheduleVisit(
                due=1, starts=-1, expires=1, repeats=False, increment=None),
            ScheduleVisit(
                due=7, starts=-2, expires=3, repeats=False, increment=None),
            ScheduleVisit(due=None,
                          starts=None,
                          expires=None,
                          repeats=True,
                          increment=14),
        ],
    ))

    module = AdvancedModule(
        schedule_phases=[
            SchedulePhase(anchor='edd', forms=[]),
            SchedulePhase(anchor='add',
                          forms=[SchedulePhaseForm(form_id=form.unique_id)]),
        ],
        forms=[form],
    )

    return module, form
Ejemplo n.º 8
0
    def test_remove_form_from_phase(self):
        form_1 = self.form_1
        form_2 = self.form_2
        self.module.schedule_phases = [
            SchedulePhase(
                anchor='dob',
                forms=[SchedulePhaseForm(form_id=form_1.unique_id),
                       SchedulePhaseForm(form_id=form_2.unique_id)]
            )
        ]
        phase = next(self.module.get_schedule_phases())  # get the phase through the module so we have a _parent
        phase.remove_form(form_1)

        self.assertEqual(len(phase.forms), 1)
        self.assertEqual([form_2], list(phase.get_forms()))

        with self.assertRaises(ScheduleError):
            phase.remove_form(form_1)
Ejemplo n.º 9
0
    def test_add_form_to_phase(self):
        self.module.schedule_phases = [
            SchedulePhase(
                anchor='dob',
                forms=[SchedulePhaseForm(form_id=self.form_1.unique_id),
                       SchedulePhaseForm(form_id=self.form_2.unique_id)]
            ),
            SchedulePhase(anchor='second_phase', forms=[]),
        ]
        phases = list(self.module.get_schedule_phases())
        phase1 = phases[0]
        phase1.add_form(self.form_3)
        self.assertEqual(phase1.get_phase_form_index(self.form_3), 2)

        # adding a form to a different phase removes it from the first phase
        phase2 = phases[1]
        phase2.add_form(self.form_3)
        self.assertEqual(phase2.get_phase_form_index(self.form_3), 0)
        self.assertIsNone(phase1.get_form(self.form_3))