def test_start(self):
        org, rp, rp_id = self.setup_org_n_rp()
        q = self.add_questionnaire('q')
        q, org = map(db.session.merge, (q, org))
        qb = QuestionnaireBank(
            name='qb', research_protocol_id=rp_id, classification='baseline',
            start='{"days": 1}', expired='{"days": 2}')
        qbq = QuestionnaireBankQuestionnaire(rank=0, questionnaire=q)
        qb.questionnaires.append(qbq)

        trigger_date = datetime.strptime('2000-01-01', '%Y-%m-%d')
        start = qb.calculated_start(trigger_date).relative_start
        assert start > trigger_date
        assert start == datetime.strptime('2000-01-02', '%Y-%m-%d')

        end = qb.calculated_expiry(start)
        expected_expiry = datetime.strptime('2000-01-04', '%Y-%m-%d')
        assert end == expected_expiry
Пример #2
0
    def test_start(self):
        org, rp, rp_id = self.setup_org_n_rp()
        q = self.add_questionnaire('q')
        q, org = map(db.session.merge, (q, org))
        qb = QuestionnaireBank(name='qb',
                               research_protocol_id=rp_id,
                               classification='baseline',
                               start='{"days": 1}',
                               expired='{"days": 2}')
        qbq = QuestionnaireBankQuestionnaire(rank=0, questionnaire=q)
        qb.questionnaires.append(qbq)

        trigger_date = datetime.strptime('2000-01-01', '%Y-%m-%d')
        start = qb.calculated_start(trigger_date).relative_start
        assert start > trigger_date
        assert start == datetime.strptime('2000-01-02', '%Y-%m-%d')

        end = qb.calculated_expiry(start)
        expected_expiry = datetime.strptime('2000-01-04', '%Y-%m-%d')
        assert end == expected_expiry
Пример #3
0
    def test_due(self):
        org, rp, rp_id = self.setup_org_n_rp()
        q = self.add_questionnaire('q')
        q, org = map(db.session.merge, (q, org))
        qb = QuestionnaireBank(name='qb',
                               research_protocol_id=rp_id,
                               classification='baseline',
                               start='{"days": 1}',
                               due='{"days": 2}')
        qbq = QuestionnaireBankQuestionnaire(rank=0, questionnaire=q)
        qb.questionnaires.append(qbq)

        trigger_date = datetime.strptime('2000-01-01', '%Y-%m-%d')
        now = datetime.now()
        start = qb.calculated_start(trigger_date,
                                    as_of_date=now).relative_start
        self.assertTrue(start > trigger_date)
        self.assertEqual(start, datetime.strptime('2000-01-02', '%Y-%m-%d'))

        due = qb.calculated_due(trigger_date, as_of_date=now)
        expected_due = datetime.strptime('2000-01-04', '%Y-%m-%d')
        self.assertEqual(due, expected_due)