def test_parent_child(self):
        parent_id = uuid.uuid4().hex
        parent_type = 'exploder-parent-type'
        parent_block = CaseBlock(
            create=True,
            case_id=parent_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type=parent_type,
        ).as_string()

        child_id = uuid.uuid4().hex
        child_block = CaseBlock(
            create=True,
            case_id=child_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-child-type',
            index={
                'parent': (parent_type, parent_id)
            },
        ).as_string()

        submit_case_blocks([parent_block, child_block], self.domain.name)
        self.assertEqual(2, len(self.accessor.get_case_ids_in_domain()))

        explode_cases(self.domain.name, self.user_id, 5)
        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(10, len(cases_back))
        parent_cases = {
            p.case_id: p
            for p in [case for case in cases_back if case.type == parent_type]
        }
Exemplo n.º 2
0
    def test_explode_ledgers(self):
        explode_cases(self.project.name, self.user_id, 5)
        cases = self.case_accessor.iter_cases(self.case_accessor.get_case_ids_in_domain())
        for case in cases:
            ledger_values = {l.entry_id: l for l in self.ledger_accessor.get_ledger_values_for_case(case.case_id)}

            if case.case_id == 'case2' or case.get_case_property('cc_exploded_from') == 'case2':
                self.assertEqual(len(ledger_values), 0)
            else:
                self.assertEqual(len(ledger_values), len(self.ledgers))
                for id, balance in six.iteritems(self.ledgers):
                    self.assertEqual(ledger_values[id].balance, balance.entry.quantity)
                    self.assertEqual(ledger_values[id].entry_id, balance.entry.id)
Exemplo n.º 3
0
    def test_explode_ledgers(self):
        explode_cases(self.project.name, self.user_id, 5)
        cases = self.case_accessor.iter_cases(self.case_accessor.get_case_ids_in_domain())
        for case in cases:
            ledger_values = {l.entry_id: l for l in self.ledger_accessor.get_ledger_values_for_case(case.case_id)}

            if case.case_id == 'case2' or case.get_case_property('cc_exploded_from') == 'case2':
                self.assertEqual(len(ledger_values), 0)
            else:
                self.assertEqual(len(ledger_values), len(self.ledgers))
                for id, balance in six.iteritems(self.ledgers):
                    self.assertEqual(ledger_values[id].balance, balance.entry.quantity)
                    self.assertEqual(ledger_values[id].entry_id, balance.entry.id)
Exemplo n.º 4
0
 def test_simple(self):
     caseblock = CaseBlock(create=True,
                           case_id=uuid.uuid4().hex,
                           user_id=self.user_id,
                           owner_id=self.user_id,
                           case_type='exploder-type',
                           version=V2).as_string()
     submit_case_blocks([caseblock], self.domain.name)
     self.assertEqual(1, len(get_case_ids_in_domain(self.domain.name)))
     explode_cases(self.user_id, self.domain.name, 10)
     cases_back = list(get_cases_in_domain(self.domain.name))
     self.assertEqual(10, len(cases_back))
     for case in cases_back:
         self.assertEqual(self.user_id, case.owner_id)
Exemplo n.º 5
0
 def test_skip_user_case(self):
     caseblock = CaseBlock(
         create=True,
         case_id=uuid.uuid4().hex,
         user_id=self.user_id,
         owner_id=self.user_id,
         case_type='commcare-user',
     ).as_string()
     submit_case_blocks([caseblock], self.domain.name)
     self.assertEqual(1, len(get_case_ids_in_domain(self.domain.name)))
     explode_cases(self.user_id, self.domain.name, 10)
     cases_back = list(get_cases_in_domain(self.domain.name))
     self.assertEqual(1, len(cases_back))
     for case in cases_back:
         self.assertEqual(self.user_id, case.owner_id)
    def test_skip_user_case(self):
        caseblock = CaseBlock(
            create=True,
            case_id=uuid.uuid4().hex,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='commcare-user',
        ).as_string()
        submit_case_blocks([caseblock], self.domain.name)
        self.assertEqual(1, len(self.accessor.get_case_ids_in_domain()))
        explode_cases(self.domain.name, self.user_id, 10)

        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(1, len(cases_back))
        for case in cases_back:
            self.assertEqual(self.user_id, case.owner_id)
Exemplo n.º 7
0
    def test_simple(self):
        caseblock = CaseBlock(
            create=True,
            case_id=uuid.uuid4().hex,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-type',
        ).as_string().decode('utf-8')
        submit_case_blocks([caseblock], self.domain.name)
        self.assertEqual(1, len(self.accessor.get_case_ids_in_domain()))
        explode_cases(self.domain.name, self.user_id, 10)

        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(10, len(cases_back))
        for case in cases_back:
            self.assertEqual(self.user_id, case.owner_id)
    def test_simple(self):
        caseblock = CaseBlock.deprecated_init(
            create=True,
            case_id=uuid.uuid4().hex,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-type',
        ).as_text()
        submit_case_blocks([caseblock], self.domain.name)
        self.assertEqual(1, len(self.accessor.get_case_ids_in_domain()))
        explode_cases(self.domain.name, self.user_id, 10)

        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(10, len(cases_back))
        for case in cases_back:
            self.assertEqual(self.user_id, case.owner_id)
Exemplo n.º 9
0
    def test_simple(self):
        caseblock = CaseBlock(
            create=True,
            case_id=uuid.uuid4().hex,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-type',
        ).as_text()
        submit_case_blocks([caseblock], self.domain.name)
        self.assertEqual(1, len(CommCareCase.objects.get_case_ids_in_domain(self.domain.name)))
        explode_cases(self.domain.name, self.user_id, 10)

        case_ids = CommCareCase.objects.get_case_ids_in_domain(self.domain.name)
        cases_back = list(CommCareCase.objects.iter_cases(case_ids, self.domain.name))
        self.assertEqual(10, len(cases_back))
        for case in cases_back:
            self.assertEqual(self.user_id, case.owner_id)
Exemplo n.º 10
0
    def test_parent_child(self):
        parent_id = uuid.uuid4().hex
        parent_type = 'exploder-parent-type'
        parent_block = CaseBlock(
            create=True,
            case_id=parent_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type=parent_type,
        ).as_string()

        child_id = uuid.uuid4().hex
        child_block = CaseBlock(
            create=True,
            case_id=child_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-child-type',
            index={
                'parent': (parent_type, parent_id)
            },
        ).as_string()

        submit_case_blocks([parent_block, child_block], self.domain.name)
        self.assertEqual(2, len(self.accessor.get_case_ids_in_domain()))

        explode_cases(self.user_id, self.domain.name, 5)
        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(10, len(cases_back))
        parent_cases = {
            p.case_id: p
            for p in filter(lambda case: case.type == parent_type, cases_back)
        }
        self.assertEqual(5, len(parent_cases))
        child_cases = filter(lambda case: case.type == 'exploder-child-type',
                             cases_back)
        self.assertEqual(5, len(child_cases))
        child_indices = [
            child.indices[0].referenced_id for child in child_cases
        ]
        # make sure they're different
        self.assertEqual(len(child_cases), len(set(child_indices)))
        for child in child_cases:
            self.assertEqual(1, len(child.indices))
            self.assertTrue(child.indices[0].referenced_id in parent_cases)
Exemplo n.º 11
0
    def test_parent_child(self):
        parent_id = uuid.uuid4().hex
        parent_type = 'exploder-parent-type'
        parent_block = CaseBlock(
            create=True,
            case_id=parent_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type=parent_type,
            version=V2
        ).as_string()

        child_id = uuid.uuid4().hex
        child_block = CaseBlock(
            create=True,
            case_id=child_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-child-type',
            index={'parent': (parent_type, parent_id)},
            version=V2
        ).as_string()

        submit_case_blocks([parent_block, child_block], self.domain.name)
        self.assertEqual(2, len(get_case_ids_in_domain(self.domain.name)))

        explode_cases(self.user_id, self.domain.name, 5)
        cases_back = list(get_cases_in_domain(self.domain.name))
        self.assertEqual(10, len(cases_back))
        parent_cases = {p._id: p for p in filter(lambda case: case.type == parent_type, cases_back)}
        self.assertEqual(5, len(parent_cases))
        child_cases = filter(lambda case: case.type == 'exploder-child-type', cases_back)
        self.assertEqual(5, len(child_cases))
        child_indices = [child.indices[0].referenced_id for child in child_cases]
        # make sure they're different
        self.assertEqual(len(child_cases), len(set(child_indices)))
        for child in child_cases:
            self.assertEqual(1, len(child.indices))
            self.assertTrue(child.indices[0].referenced_id in parent_cases)
Exemplo n.º 12
0
    def test_parent_child(self):
        parent_id = uuid.uuid4().hex
        parent_type = 'exploder-parent-type'
        parent_block = CaseBlock(
            create=True,
            case_id=parent_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type=parent_type,
        ).as_string().decode('utf-8')

        child_id = uuid.uuid4().hex
        child_block = CaseBlock(
            create=True,
            case_id=child_id,
            user_id=self.user_id,
            owner_id=self.user_id,
            case_type='exploder-child-type',
            index={'parent': (parent_type, parent_id)},
        ).as_string().decode('utf-8')

        submit_case_blocks([parent_block, child_block], self.domain.name)
        self.assertEqual(2, len(self.accessor.get_case_ids_in_domain()))

        explode_cases(self.domain.name, self.user_id, 5)
        case_ids = self.accessor.get_case_ids_in_domain()
        cases_back = list(self.accessor.iter_cases(case_ids))
        self.assertEqual(10, len(cases_back))
        parent_cases = {p.case_id: p for p in [case for case in cases_back if case.type == parent_type]}
        self.assertEqual(5, len(parent_cases))
        child_cases = [case for case in cases_back if case.type == 'exploder-child-type']
        self.assertEqual(5, len(child_cases))
        child_indices = [child.indices[0].referenced_id for child in child_cases]
        # make sure they're different
        self.assertEqual(len(child_cases), len(set(child_indices)))
        for child in child_cases:
            self.assertEqual(1, len(child.indices))
            self.assertTrue(child.indices[0].referenced_id in parent_cases)
    def test_child_extensions(self):
        self.assertEqual(4, len(self.accessor.get_case_ids_in_domain()))

        explode_cases(self.project.name, self.user_id, 5)
        case_ids = self.accessor.get_case_ids_in_domain()
        self.assertEqual(20, len(case_ids))
Exemplo n.º 14
0
    def test_child_extensions(self):
        self.assertEqual(4, len(self.accessor.get_case_ids_in_domain()))

        explode_cases(self.project.name, self.user_id, 5)
        case_ids = self.accessor.get_case_ids_in_domain()
        self.assertEqual(20, len(case_ids))
Exemplo n.º 15
0
    def test_child_extensions(self):
        self.assertEqual(4, len(CommCareCase.objects.get_case_ids_in_domain(self.project.name)))

        explode_cases(self.project.name, self.user_id, 5)
        case_ids = CommCareCase.objects.get_case_ids_in_domain(self.project.name)
        self.assertEqual(20, len(case_ids))