def test_skip_condition_false(self):
        answer = "Bothans"
        # find the question with the 'not equals' skip condition
        question = self.questionnaire.get_item_by_id("048e40da-bca4-48e5-9885-0bb6413bef62")
        rule = question.skip_condition.__dict__
        rule["when"] = rule["when"].__dict__

        # check the parse has set up the skip condition
        self.assertIsNotNone(question.skip_condition)

        # the condition will fire now as we have answer the question correctly, so we won't skip the question
        self.assertFalse(evaluate_rule(rule, answer))
    def test_skip_condition_blank(self):
        answer = ""

        # find the question with the 'not equals' skip condition
        question = self.questionnaire.get_item_by_id("048e40da-bca4-48e5-9885-0bb6413bef62")
        rule = question.skip_condition.__dict__
        rule["when"] = rule["when"].__dict__

        # check the parse has set up the skip condition
        self.assertIsNotNone(question.skip_condition)

        # the condition won't fire as we haven't answered any questions, so we will skip the question
        self.assertTrue(evaluate_rule(rule, answer))
    def _conditional_display(self, item):
        # Process any conditional display rules

        if item.schema_item:

            item.skipped = False

            if hasattr(item.schema_item, 'skip_condition') and item.schema_item.skip_condition:
                rule = item.schema_item.skip_condition.__dict__
                rule['when'] = rule['when'].__dict__
                answer = get_answers(current_user).get(rule['when']['id'])

                item.skipped = evaluate_rule(rule, answer)

            for child in item.children:
                self._conditional_display(child)
    def is_skipped(self, all_answers):
        if self.skip_condition is not None:
            answer = all_answers.get(self.skip_condition['when']['id'])
            return evaluate_rule(self.skip_condition, answer)

        return False