Пример #1
0
 def _row_to_index_info(row):
     return CaseIndexInfo(
         case_id=row['id'],
         identifier=row['value']['identifier'],
         referenced_id=row['key'][1],
         referenced_type=row['value']['referenced_type'],
         relationship=row['value']['relationship']
     )
Пример #2
0
 def get_all_reverse_indices_info(domain, case_ids):
     assert isinstance(case_ids, list)
     indexes = CommCareCaseIndexSQL.objects.raw(
         'SELECT * FROM get_all_reverse_indices(%s, %s)',
         [domain, case_ids])
     return [
         CaseIndexInfo(case_id=index.case_id,
                       identifier=index.identifier,
                       referenced_id=index.referenced_id,
                       referenced_type=index.referenced_type,
                       relationship=index.relationship_id)
         for index in indexes
     ]
            referenced_id=referenced_id2,
            relationship_id=CommCareCaseIndexSQL.CHILD
        )
        case.track_create(child_index)
        CaseAccessorSQL.save_case(case)

        # Create irrelevant case and index
        _create_case_with_index(case.case_id)

        # create index on deleted case
        _create_case_with_index(referenced_id1, case_is_deleted=True)

        self.assertEqual(
            set(CaseAccessorSQL.get_all_reverse_indices_info(DOMAIN, [referenced_id1, referenced_id2])),
            {
                CaseIndexInfo(
                    case_id=case.case_id,
                    identifier='task',
                    referenced_id=referenced_id1,
                    referenced_type='task',
                    relationship=CommCareCaseIndexSQL.EXTENSION,
                ),
                CaseIndexInfo(
                    case_id=case.case_id,
                    identifier='parent',
                    referenced_id=referenced_id2,
                    referenced_type='mother',
                    relationship=CommCareCaseIndexSQL.CHILD
                ),
            }
        )