コード例 #1
0
ファイル: test_bugs.py プロジェクト: dimagi/commcare-hq
    def test_extension_index(self):
        factory = CaseFactory()
        standard_case_id = uuid.uuid4().hex
        [case] = factory.create_or_update_case(
            CaseStructure(case_id=standard_case_id, attrs={'case_type': "standard_type", 'create': True})
        )

        extension_case_id = uuid.uuid4().hex
        factory.create_or_update_case(
            CaseStructure(
                case_id=extension_case_id,
                attrs={'case_type': "extension_type", 'create': True},
                indices=[
                    CaseIndex(
                        CaseStructure(case_id=standard_case_id),
                        related_type='standard_type',
                        relationship=CASE_INDEX_EXTENSION
                    )
                ],
                walk_related=False
            )
        )

        hierarchy = get_case_hierarchy(case, {})
        self.assertEqual(2, len(hierarchy['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases']))
コード例 #2
0
ファイル: test_bugs.py プロジェクト: ye-man/commcare-hq
    def test_normal_index(self):
        factory = CaseFactory()
        parent_id = uuid.uuid4().hex
        [cp] = factory.create_or_update_case(
            CaseStructure(case_id=parent_id,
                          attrs={
                              'case_type': 'parent',
                              'create': True
                          }))

        child_id = uuid.uuid4().hex
        factory.create_or_update_case(
            CaseStructure(case_id=child_id,
                          attrs={
                              'case_type': 'child',
                              'create': True
                          },
                          indices=[
                              CaseIndex(CaseStructure(case_id=parent_id),
                                        related_type='parent')
                          ],
                          walk_related=False))

        hierarchy = get_case_hierarchy(cp, {})
        self.assertEqual(2, len(hierarchy['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases']))
コード例 #3
0
ファイル: test_bugs.py プロジェクト: ye-man/commcare-hq
    def test_complex_index(self):
        factory = CaseFactory()
        parent_id = uuid.uuid4().hex
        cp = factory.create_or_update_case(
            CaseStructure(case_id=parent_id,
                          attrs={
                              'case_type': 'parent',
                              'create': True
                          }))[0]

        # cases processed according to ID order so ensure that this case is
        # processed after the task case by making its ID sort after task ID
        goal_id = uuid.uuid4().hex
        factory.create_or_update_case(
            CaseStructure(case_id=goal_id,
                          attrs={
                              'case_type': 'goal',
                              'create': True
                          },
                          indices=[
                              CaseIndex(CaseStructure(case_id=parent_id),
                                        related_type='parent')
                          ],
                          walk_related=False))

        task_id = uuid.uuid4().hex
        factory.create_or_update_case(
            CaseStructure(
                case_id=task_id,
                attrs={
                    'case_type': 'task',
                    'create': True
                },
                indices=[
                    CaseIndex(CaseStructure(case_id=goal_id),
                              related_type='goal',
                              identifier='goal'),
                    CaseIndex(CaseStructure(case_id=parent_id),
                              related_type='parent')
                ],
                walk_related=False,
            ))

        # with 'ignore_relationship_types' if a case got processed along the ignored relationship first
        # then it got marked as 'seen' and would be not be processed again when it came to the correct relationship
        type_info = {
            'task': {
                'ignore_relationship_types': ['parent']
            },
        }

        hierarchy = get_case_hierarchy(cp, type_info)
        self.assertEqual(3, len(hierarchy['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases']))
        self.assertEqual(2, len(hierarchy['child_cases'][0]['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases'][0]['child_cases']))
コード例 #4
0
ファイル: test_bugs.py プロジェクト: dimagi/commcare-hq
    def test_recursive_indexes(self):
        factory = CaseFactory()
        [case] = factory.create_or_update_case(CaseStructure(
            case_id='infinite-recursion',
            attrs={'case_type': 'bug', 'create': True},
            indices=[CaseIndex(CaseStructure(case_id='infinite-recursion', attrs={'create': True}), related_type='bug')],
            walk_related=False
        ))

        # this call used to fail with infinite recursion
        hierarchy = get_case_hierarchy(case, {})
        self.assertEqual(1, len(hierarchy['case_list']))
コード例 #5
0
    def test_deleted_index(self):
        hierarchy = self.test_normal_index()
        parent, child = hierarchy['case_list']

        factory = CaseFactory()
        ref = CaseStructure()
        ref.case_id = ""  # reset case_id to empty
        factory.create_or_update_case(
            CaseStructure(case_id=child.case_id,
                          indices=[CaseIndex(ref, related_type='parent')],
                          walk_related=False), )

        # re-fetch case to clear memoized properties
        parent = CommCareCase.objects.get_case(parent.case_id, parent.domain)
        hierarchy = get_case_hierarchy(parent, {})
        self.assertEqual(1, len(hierarchy['case_list']))
        self.assertEqual(0, len(hierarchy['child_cases']))
コード例 #6
0
ファイル: test_bugs.py プロジェクト: dimagi/commcare-hq
    def test_normal_index(self):
        factory = CaseFactory()
        parent_id = uuid.uuid4().hex
        [cp] = factory.create_or_update_case(
            CaseStructure(case_id=parent_id, attrs={'case_type': 'parent', 'create': True})
        )

        child_id = uuid.uuid4().hex
        factory.create_or_update_case(CaseStructure(
            case_id=child_id,
            attrs={'case_type': 'child', 'create': True},
            indices=[CaseIndex(CaseStructure(case_id=parent_id), related_type='parent')],
            walk_related=False
        ))

        hierarchy = get_case_hierarchy(cp, {})
        self.assertEqual(2, len(hierarchy['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases']))
コード例 #7
0
 def test_full_ancestry(self):
     """get_case_hierarchy should return the full parentage tree for any case
     """
     factory = CaseFactory('baggins-of-hobbiton')
     bagginses = ['balbo', 'mungo', 'bungo', 'bilbo']
     cases = {}
     for level, baggins in enumerate(bagginses):
         cases[baggins] = factory.create_or_update_case(
             CaseStructure(
                 case_id=baggins,
                 attrs={
                     'case_type': 'baggins',
                     'update': {'name': baggins},
                     'create': True},
                 indices=[CaseIndex(CaseStructure(case_id=bagginses[level - 1]))] if level != 0 else None,
                 walk_related=False,
             )
         )[0]
     hierarchy = get_case_hierarchy(cases['bungo'], {})
     self.assertEqual(4, len(hierarchy['case_list']))
コード例 #8
0
ファイル: test_bugs.py プロジェクト: dimagi/commcare-hq
    def test_complex_index(self):
        factory = CaseFactory()
        parent_id = uuid.uuid4().hex
        cp = factory.create_or_update_case(CaseStructure(case_id=parent_id, attrs={
            'case_type': 'parent', 'create': True
        }))[0]

        # cases processed according to ID order so ensure that this case is
        # processed after the task case by making its ID sort after task ID
        goal_id = uuid.uuid4().hex
        factory.create_or_update_case(CaseStructure(
            case_id=goal_id,
            attrs={'case_type': 'goal', 'create': True},
            indices=[CaseIndex(CaseStructure(case_id=parent_id), related_type='parent')],
            walk_related=False
        ))

        task_id = uuid.uuid4().hex
        factory.create_or_update_case(CaseStructure(
            case_id=task_id,
            attrs={'case_type': 'task', 'create': True},
            indices=[
                CaseIndex(CaseStructure(case_id=goal_id), related_type='goal', identifier='goal'),
                CaseIndex(CaseStructure(case_id=parent_id), related_type='parent')
            ],
            walk_related=False,
        ))

        # with 'ignore_relationship_types' if a case got processed along the ignored relationship first
        # then it got marked as 'seen' and would be not be processed again when it came to the correct relationship
        type_info = {
            'task': {
                'ignore_relationship_types': ['parent']
            },
        }

        hierarchy = get_case_hierarchy(cp, type_info)
        self.assertEqual(3, len(hierarchy['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases']))
        self.assertEqual(2, len(hierarchy['child_cases'][0]['case_list']))
        self.assertEqual(1, len(hierarchy['child_cases'][0]['child_cases']))
コード例 #9
0
ファイル: views.py プロジェクト: dimagi/commcare-hq
def get_case_hierarchy_for_restore(case):
    from corehq.apps.reports.view_helpers import get_case_hierarchy
    return [
        c for c in get_case_hierarchy(case, {})['case_list']
        if not c.closed
    ]