当前位置: 首页>>代码示例>>Python>>正文


Python CaseFactory.create_or_update_cases方法代码示例

本文整理汇总了Python中casexml.apps.case.mock.CaseFactory.create_or_update_cases方法的典型用法代码示例。如果您正苦于以下问题:Python CaseFactory.create_or_update_cases方法的具体用法?Python CaseFactory.create_or_update_cases怎么用?Python CaseFactory.create_or_update_cases使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在casexml.apps.case.mock.CaseFactory的用法示例。


在下文中一共展示了CaseFactory.create_or_update_cases方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_from_structure

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_create_from_structure(self):
        owner_id = uuid.uuid4().hex
        factory = CaseFactory(case_defaults={
            'owner_id': owner_id,
            'create': True,
            'update': {'custom_prop': 'custom_value'}
        })
        case_id = uuid.uuid4().hex
        child_case_id = uuid.uuid4().hex
        parent_case_id = uuid.uuid4().hex
        structures = [
            CaseStructure(case_id=case_id, attrs={'create': True}),
            CaseStructure(
                case_id=child_case_id,
                indices=[
                    CaseIndex(CaseStructure(case_id=parent_case_id, attrs={'create': True}))
                ]
            )
        ]
        cases = factory.create_or_update_cases(structures)
        for case in cases:
            self.assertEqual(owner_id, case.owner_id)
            self.assertEqual('custom_value', case.dynamic_case_properties()['custom_prop'])

        [regular, child, parent] = cases
        self.assertEqual(1, len(child.indices))
        self.assertEqual(parent_case_id, child.indices[0].referenced_id)
        if not getattr(settings, 'TESTS_SHOULD_USE_SQL_BACKEND', False):
            self.assertEqual(2, len(regular.actions))  # create + update
            self.assertEqual(2, len(parent.actions))  # create + update
            self.assertEqual(3, len(child.actions))  # create + update + index
开发者ID:dimagi,项目名称:commcare-hq,代码行数:33,代码来源:test_factory.py

示例2: test_create_from_structure

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_create_from_structure(self):
        owner_id = uuid.uuid4().hex
        factory = CaseFactory(case_defaults={
            'owner_id': owner_id,
            'create': True,
            'update': {'custom_prop': 'custom_value'}
        })
        case_id = uuid.uuid4().hex
        child_case_id = uuid.uuid4().hex
        parent_case_id = uuid.uuid4().hex
        structures = [
            CaseStructure(case_id=case_id),
            CaseStructure(
                case_id=child_case_id,
                relationships=[
                    CaseRelationship(CaseStructure(case_id=parent_case_id))
                ]
            )
        ]
        cases = factory.create_or_update_cases(structures)
        for case in cases:
            self.assertEqual(owner_id, case.owner_id)
            self.assertEqual('custom_value', case.custom_prop)

        [regular, child, parent] = cases
        self.assertEqual(1, len(child.indices))
        self.assertEqual(parent_case_id, child.indices[0].referenced_id)
        self.assertEqual(2, len(regular.actions))  # create + update
        self.assertEqual(2, len(parent.actions))  # create + update
        self.assertEqual(3, len(child.actions))  # create + update + index
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:32,代码来源:test_factory.py

示例3: setUpClass

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def setUpClass(cls):
        super(TestFilterDslLookups, cls).setUpClass()
        with trap_extra_setup(ConnectionError):
            cls.es = get_es_new()
            initialize_index_and_mapping(cls.es, CASE_SEARCH_INDEX_INFO)

        cls.child_case_id = 'margaery'
        cls.parent_case_id = 'mace'
        cls.grandparent_case_id = 'olenna'
        cls.domain = "Tyrell"
        factory = CaseFactory(domain=cls.domain)
        grandparent_case = CaseStructure(
            case_id=cls.grandparent_case_id,
            attrs={
                'create': True,
                'case_type': 'grandparent',
                'update': {
                    "name": "Olenna",
                    "alias": "Queen of thorns",
                    "house": "Tyrell",
                },
            })

        parent_case = CaseStructure(
            case_id=cls.parent_case_id,
            attrs={
                'create': True,
                'case_type': 'parent',
                'update': {
                    "name": "Mace",
                    "house": "Tyrell",
                },
            },
            indices=[CaseIndex(
                grandparent_case,
                identifier='mother',
                relationship='child',
            )])

        child_case = CaseStructure(
            case_id=cls.child_case_id,
            attrs={
                'create': True,
                'case_type': 'child',
                'update': {
                    "name": "Margaery",
                    "house": "Tyrell",
                },
            },
            indices=[CaseIndex(
                parent_case,
                identifier='father',
                relationship='extension',
            )],
        )
        for case in factory.create_or_update_cases([child_case]):
            send_to_elasticsearch('case_search', transform_case_for_elasticsearch(case.to_json()))
        cls.es.indices.refresh(CASE_SEARCH_INDEX_INFO.index)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:60,代码来源:test_filter_dsl.py

示例4: test_delete_sharing_form

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_delete_sharing_form(self):
        factory = CaseFactory()
        c1, c2 = factory.create_or_update_cases([
            CaseStructure(attrs={'create': True}),
            CaseStructure(attrs={'create': True}),
        ])
        with self.assertRaises(CommCareCaseError):
            c1.hard_delete()

        with self.assertRaises(CommCareCaseError):
            c2.hard_delete()

        self.assertIsNotNone(self.interface.case_model.get(c1.case_id))
        self.assertIsNotNone(self.interface.case_model.get(c2.case_id))
开发者ID:nnestle,项目名称:commcare-hq,代码行数:16,代码来源:test_delete.py

示例5: test_delete_sharing_form

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_delete_sharing_form(self):
        factory = CaseFactory()
        c1, c2 = factory.create_or_update_cases([
            CaseStructure(attrs={'create': True}),
            CaseStructure(attrs={'create': True}),
        ])
        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c1)

        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c2)

        self.assertIsNotNone(self.casedb.get_case(c1.case_id))
        self.assertIsNotNone(self.casedb.get_case(c2.case_id))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:16,代码来源:test_delete.py

示例6: test_delete_sharing_form

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_delete_sharing_form(self):
        factory = CaseFactory()
        c1, c2 = factory.create_or_update_cases([
            CaseStructure(attrs={'create': True}),
            CaseStructure(attrs={'create': True}),
        ])
        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c1)

        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(c2)

        self.assertTrue(CommCareCase.get_db().doc_exist(c1._id))
        self.assertTrue(CommCareCase.get_db().doc_exist(c2._id))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:16,代码来源:test_delete.py

示例7: test_delete_sharing_form

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_delete_sharing_form(self):
        factory = CaseFactory()
        c1, c2 = factory.create_or_update_cases([
            CaseStructure(attrs={'create': True}),
            CaseStructure(attrs={'create': True}),
        ])
        with self.assertRaises(CommCareCaseError):
            FormProcessorInterface.hard_delete_case(c1)

        with self.assertRaises(CommCareCaseError):
            FormProcessorInterface.hard_delete_case(c2)

        self.assertIsNotNone(FormProcessorInterface.get_case(c1.id))
        self.assertIsNotNone(FormProcessorInterface.get_case(c2.id))
开发者ID:johan--,项目名称:commcare-hq,代码行数:16,代码来源:test_delete.py

示例8: test_legacy_support_toggle

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_legacy_support_toggle(self):
        restore_config = RestoreConfig(self.project, user=self.user)
        factory = CaseFactory(domain=self.project.name, case_defaults={"owner_id": self.user_id})
        # create a parent and child case (with index) from one user
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        factory.create_or_update_cases(
            [
                CaseStructure(
                    case_id=child_id,
                    attrs={"create": True},
                    indices=[
                        CaseIndex(
                            CaseStructure(case_id=parent_id, attrs={"create": True}),
                            relationship="child",
                            related_type="parent",
                        )
                    ],
                )
            ]
        )
        restore_payload = restore_config.get_payload().as_string()
        self.assertTrue(child_id in restore_payload)
        self.assertTrue(parent_id in restore_payload)
        sync_log = synclog_from_restore_payload(restore_payload)
        self.assertEqual(SimplifiedSyncLog, type(sync_log))
        # make both cases irrelevant by changing the owner ids
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )

        # doing it again should fail since they are no longer relevant

        # todo: add this back in when we add the assertion back. see SimplifiedSyncLog.prune_case
        # with self.assertRaises(SimplifiedSyncAssertionError):
        #     factory.create_or_update_cases([
        #         CaseStructure(case_id=child_id, attrs={'owner_id': 'different'}),
        #         CaseStructure(case_id=parent_id, attrs={'owner_id': 'different'}),
        #     ], form_extras={'last_sync_token': sync_log._id})

        # enabling the toggle should prevent the failure the second time
        # though we also need to hackily set the request object in the threadlocals
        LEGACY_SYNC_SUPPORT.set(self.domain, True, namespace="domain")
        request = JsonObject(domain=self.domain)
        set_request(request)
        factory.create_or_update_cases(
            [
                CaseStructure(case_id=child_id, attrs={"owner_id": "different"}),
                CaseStructure(case_id=parent_id, attrs={"owner_id": "different"}),
            ],
            form_extras={"last_sync_token": sync_log._id},
        )
开发者ID:johan--,项目名称:commcare-hq,代码行数:57,代码来源:test_new_sync.py

示例9: test_create_from_structure

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
    def test_create_from_structure(self):
        owner_id = uuid.uuid4().hex
        factory = CaseFactory(
            case_defaults={"owner_id": owner_id, "create": True, "update": {"custom_prop": "custom_value"}}
        )
        case_id = uuid.uuid4().hex
        child_case_id = uuid.uuid4().hex
        parent_case_id = uuid.uuid4().hex
        structures = [
            CaseStructure(case_id=case_id),
            CaseStructure(case_id=child_case_id, indices=[CaseIndex(CaseStructure(case_id=parent_case_id))]),
        ]
        cases = factory.create_or_update_cases(structures)
        for case in cases:
            self.assertEqual(owner_id, case.owner_id)
            self.assertEqual("custom_value", case.dynamic_case_properties()["custom_prop"])

        [regular, child, parent] = cases
        self.assertEqual(1, len(child.indices))
        self.assertEqual(parent_case_id, child.indices[0].referenced_id)
        if not settings.TESTS_SHOULD_USE_SQL_BACKEND:
            self.assertEqual(2, len(regular.actions))  # create + update
            self.assertEqual(2, len(parent.actions))  # create + update
            self.assertEqual(3, len(child.actions))  # create + update + index
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:26,代码来源:test_factory.py

示例10: TestExtensionCaseIds

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class TestExtensionCaseIds(TestCase):

    def setUp(self):
        super(TestExtensionCaseIds, self).setUp()
        self.domain = 'domain'
        FormProcessorTestUtils.delete_all_cases()
        self.factory = CaseFactory(self.domain)

    def tearDown(self):
        FormProcessorTestUtils.delete_all_cases()
        FormProcessorTestUtils.delete_all_xforms()
        super(TestExtensionCaseIds, self).tearDown()

    def test_no_extensions(self):
        """ Returns empty when there are other index types """
        parent_id = uuid.uuid4().hex
        child_id = uuid.uuid4().hex
        parent = CaseStructure(case_id=parent_id, attrs={'create': True})

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=child_id,
                indices=[
                    CaseIndex(parent, relationship=CASE_INDEX_CHILD)
                ],
                attrs={'create': True}
            )
        )
        returned_cases = CaseAccessors(self.domain).get_extension_case_ids([parent_id])
        self.assertEqual(returned_cases, [])

    def test_simple_extension_returned(self):
        """ Should return extension if it exists """
        host_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        host = CaseStructure(case_id=host_id, attrs={'create': True})

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION)
                ],
                attrs={'create': True}
            )
        )
        returned_cases = CaseAccessors(self.domain).get_extension_case_ids([host_id])
        self.assertItemsEqual(returned_cases, [extension_id])

    def test_extension_of_multiple_hosts_returned(self):
        """ Should return an extension from any host if there are multiple indices """
        host_id = uuid.uuid4().hex
        host_2_id = uuid.uuid4().hex
        parent_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        host = CaseStructure(case_id=host_id, attrs={'create': True})
        host_2 = CaseStructure(case_id=host_2_id, attrs={'create': True})
        parent = CaseStructure(case_id=parent_id, attrs={'create': True})

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                    CaseIndex(host_2, relationship=CASE_INDEX_EXTENSION, identifier="host_2"),
                    CaseIndex(parent, relationship=CASE_INDEX_CHILD),
                ],
                attrs={'create': True}
            )
        )

        returned_cases = CaseAccessors(self.domain).get_extension_case_ids([host_2_id])
        self.assertItemsEqual(returned_cases, [extension_id])
        returned_cases = CaseAccessors(self.domain).get_extension_case_ids([host_id])
        self.assertItemsEqual(returned_cases, [extension_id])

    def test_host_with_multiple_extensions(self):
        """ Return all extensions from a single host """
        host_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        extension_2_id = uuid.uuid4().hex

        host = CaseStructure(case_id=host_id, attrs={'create': True})

        self.factory.create_or_update_cases([
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                ],
                attrs={'create': True}
            ),
            CaseStructure(
                case_id=extension_2_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                ],
                attrs={'create': True}
            ),
        ]
#.........这里部分代码省略.........
开发者ID:dimagi,项目名称:commcare-hq,代码行数:103,代码来源:test_db_accessors.py

示例11: ReprocessSubmissionStubTests

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class ReprocessSubmissionStubTests(TestCase):
    @classmethod
    def setUpClass(cls):
        super(ReprocessSubmissionStubTests, cls).setUpClass()
        cls.domain = uuid.uuid4().hex
        cls.product = SQLProduct.objects.create(domain=cls.domain, product_id='product1', name='product1')

    @classmethod
    def tearDownClass(cls):
        cls.product.delete()
        super(ReprocessSubmissionStubTests, cls).tearDownClass()

    def setUp(self):
        super(ReprocessSubmissionStubTests, self).setUp()
        self.factory = CaseFactory(domain=self.domain)
        self.formdb = FormAccessors(self.domain)
        self.casedb = CaseAccessors(self.domain)
        self.ledgerdb = LedgerAccessors(self.domain)

    def tearDown(self):
        FormProcessorTestUtils.delete_all_cases_forms_ledgers(self.domain)
        super(ReprocessSubmissionStubTests, self).tearDown()

    def test_reprocess_unfinished_submission_case_create(self):
        case_id = uuid.uuid4().hex
        with _patch_save_to_raise_error(self):
            self.factory.create_or_update_cases([
                CaseStructure(case_id=case_id, attrs={'case_type': 'parent', 'create': True})
            ])

        stubs = UnfinishedSubmissionStub.objects.filter(domain=self.domain, saved=False).all()
        self.assertEqual(1, len(stubs))

        # form that was saved before case error raised
        normal_form_ids = self.formdb.get_all_form_ids_in_domain('XFormInstance')
        self.assertEqual(0, len(normal_form_ids))

        # shows error form (duplicate of form that was saved before case error)
        # this is saved becuase the saving was assumed to be atomic so if there was any error it's assumed
        # the form didn't get saved
        # we don't really care about this form in this test
        error_forms = self.formdb.get_forms_by_type('XFormError', 10)
        self.assertEqual(1, len(error_forms))
        self.assertIsNone(error_forms[0].orig_id)
        self.assertEqual(error_forms[0].form_id, stubs[0].xform_id)

        self.assertEqual(0, len(self.casedb.get_case_ids_in_domain(self.domain)))

        result = reprocess_unfinished_stub(stubs[0])
        self.assertEqual(1, len(result.cases))

        case_ids = self.casedb.get_case_ids_in_domain()
        self.assertEqual(1, len(case_ids))
        self.assertEqual(case_id, case_ids[0])

        with self.assertRaises(UnfinishedSubmissionStub.DoesNotExist):
            UnfinishedSubmissionStub.objects.get(pk=stubs[0].pk)

    def test_reprocess_unfinished_submission_case_update(self):
        case_id = uuid.uuid4().hex
        form_ids = []
        form_ids.append(submit_case_blocks(
            CaseBlock(case_id=case_id, create=True, case_type='box').as_string().decode('utf-8'),
            self.domain
        )[0].form_id)

        with _patch_save_to_raise_error(self):
            submit_case_blocks(
                CaseBlock(case_id=case_id, update={'prop': 'a'}).as_string().decode('utf-8'),
                self.domain
            )

        stubs = UnfinishedSubmissionStub.objects.filter(domain=self.domain, saved=False).all()
        self.assertEqual(1, len(stubs))

        form_ids.append(stubs[0].xform_id)

        # submit second form with case update
        form_ids.append(submit_case_blocks(
            CaseBlock(case_id=case_id, update={'prop': 'b'}).as_string().decode('utf-8'),
            self.domain
        )[0].form_id)

        case = self.casedb.get_case(case_id)
        self.assertEqual(2, len(case.xform_ids))
        self.assertEqual('b', case.get_case_property('prop'))

        result = reprocess_unfinished_stub(stubs[0])
        self.assertEqual(1, len(result.cases))
        self.assertEqual(0, len(result.ledgers))

        case = self.casedb.get_case(case_id)
        self.assertEqual('b', case.get_case_property('prop'))  # should be property value from most recent form
        self.assertEqual(3, len(case.xform_ids))
        self.assertEqual(form_ids, case.xform_ids)

        with self.assertRaises(UnfinishedSubmissionStub.DoesNotExist):
            UnfinishedSubmissionStub.objects.get(pk=stubs[0].pk)

    def test_reprocess_unfinished_submission_ledger_create(self):
#.........这里部分代码省略.........
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:103,代码来源:test_reprocess_errors.py

示例12: TestExtensionCaseIds

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class TestExtensionCaseIds(TestCase):

    @classmethod
    def setUpClass(cls):
        delete_all_cases()

    def setUp(self):
        self.domain = 'domain'
        self.factory = CaseFactory(self.domain)

    def test_no_extensions(self):
        """ Returns empty when there are other index types """
        parent_id = uuid.uuid4().hex
        child_id = uuid.uuid4().hex
        parent = CaseStructure(case_id=parent_id)

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=child_id,
                indices=[
                    CaseIndex(parent, relationship=CASE_INDEX_CHILD)
                ]
            )
        )
        returned_cases = get_extension_case_ids(self.domain, [parent_id])
        self.assertEqual(returned_cases, [])

    def test_simple_extension_returned(self):
        """ Should return extension if it exists """
        host_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        host = CaseStructure(case_id=host_id)

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION)
                ]
            )
        )
        returned_cases = get_extension_case_ids(self.domain, [host_id])
        self.assertItemsEqual(returned_cases, [extension_id])

    def test_extension_of_multiple_hosts_returned(self):
        """ Should return an extension from any host if there are multiple indices """
        host_id = uuid.uuid4().hex
        host_2_id = uuid.uuid4().hex
        parent_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        host = CaseStructure(case_id=host_id)
        host_2 = CaseStructure(case_id=host_2_id)
        parent = CaseStructure(case_id=parent_id)

        self.factory.create_or_update_case(
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                    CaseIndex(host_2, relationship=CASE_INDEX_EXTENSION, identifier="host_2"),
                    CaseIndex(parent, relationship=CASE_INDEX_CHILD),
                ]
            )
        )

        returned_cases = get_extension_case_ids(self.domain, [host_2_id])
        self.assertItemsEqual(returned_cases, [extension_id])
        returned_cases = get_extension_case_ids(self.domain, [host_id])
        self.assertItemsEqual(returned_cases, [extension_id])

    def test_host_with_multiple_extensions(self):
        """ Return all extensions from a single host """
        host_id = uuid.uuid4().hex
        extension_id = uuid.uuid4().hex
        extension_2_id = uuid.uuid4().hex

        host = CaseStructure(case_id=host_id)

        self.factory.create_or_update_cases([
            CaseStructure(
                case_id=extension_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                ]
            ),
            CaseStructure(
                case_id=extension_2_id,
                indices=[
                    CaseIndex(host, relationship=CASE_INDEX_EXTENSION, identifier="host"),
                ]
            ),
        ]
        )

        returned_cases = get_extension_case_ids(self.domain, [host_id])
        self.assertItemsEqual(returned_cases, [extension_id, extension_2_id])

    def test_extensions_from_list(self):
        """ Given a list of hosts, should return all extensions """
        host_id = uuid.uuid4().hex
#.........这里部分代码省略.........
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:103,代码来源:test_db_accessors.py

示例13: AutoCloseExtensionsTest

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class AutoCloseExtensionsTest(TestCase):

    def setUp(self):
        FormProcessorTestUtils.delete_all_cases()
        FormProcessorTestUtils.delete_all_xforms()
        delete_all_users()
        self.domain = "domain"
        self.project = Domain(name=self.domain)
        self.user = create_restore_user(self.domain, username='name', password="changeme")
        self.factory = CaseFactory(domain=self.domain)
        self.extension_ids = ['1', '2', '3']
        self.host_id = 'host'

    def tearDown(self):
        FormProcessorTestUtils.delete_all_cases()
        FormProcessorTestUtils.delete_all_xforms()
        delete_all_users()

    def _create_extension_chain(self):
        host = CaseStructure(case_id=self.host_id)
        extension = CaseStructure(
            case_id=self.extension_ids[0],
            indices=[CaseIndex(
                related_structure=host,
                relationship="extension",
            )],
        )
        extension_2 = CaseStructure(
            case_id=self.extension_ids[1],
            indices=[CaseIndex(
                related_structure=extension,
                relationship="extension",
            )],
        )
        extension_3 = CaseStructure(
            case_id=self.extension_ids[2],
            indices=[CaseIndex(
                related_structure=extension_2,
                relationship="extension",
            )],
        )
        return self.factory.create_or_update_cases([extension_3])

    def _create_extension_loop(self):
        extension_3 = CaseStructure(case_id=self.extension_ids[2])
        host = CaseStructure(
            case_id=self.host_id,
            indices=[CaseIndex(
                related_structure=extension_3,
                relationship="extension",
            )],
        )
        return self.factory.create_or_update_cases([host])

    def _create_host_is_subcase_chain(self):
        parent = CaseStructure(case_id='parent')
        host = CaseStructure(
            case_id=self.host_id,
            indices=[CaseIndex(
                related_structure=parent,
                relationship="child",
            )],
        )
        extension = CaseStructure(
            case_id=self.extension_ids[0],
            indices=[CaseIndex(
                related_structure=host,
                relationship="extension",
            )],
        )
        extension_2 = CaseStructure(
            case_id=self.extension_ids[1],
            indices=[CaseIndex(
                related_structure=extension,
                relationship="extension",
            )],
        )
        return self.factory.create_or_update_cases([extension_2])

    @run_with_all_backends
    def test_get_extension_chain_simple(self):
        host = CaseStructure(case_id=self.host_id)
        extension = CaseStructure(
            case_id=self.extension_ids[0],
            indices=[CaseIndex(
                related_structure=host,
                relationship="extension",
            )],
        )
        self.factory.create_or_update_cases([extension])
        self.assertEqual(
            set(self.extension_ids[0]),
            CaseAccessors(self.domain).get_extension_chain([self.host_id])
        )

    @run_with_all_backends
    def test_get_extension_chain_multiple(self):
        created_cases = self._create_extension_chain()
        self.assertEqual(
            set(self.extension_ids),
#.........这里部分代码省略.........
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:103,代码来源:test_close_extension_chain.py

示例14: TestCasePropertyChanged

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class TestCasePropertyChanged(TestCase):
    def setUp(self):
        self.domain = "isildur"
        self.factory = CaseFactory(self.domain)
        self.case = self.factory.create_case(owner_id='owner', case_name="Aragorn", update={"sword": "Narsil"})
        self.other_case = self.factory.create_case()

    def tearDown(self):
        delete_all_xforms()
        delete_all_cases()

    @run_with_all_backends
    def test_date_case_property_changed(self):
        updated_on = datetime(2015, 5, 3, 12, 11)
        # submit 2 updates
        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'abc': "updated"
                    },
                    "date_modified": updated_on
                }),
        )
        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'bcd': "updated"
                    },
                }),
        )
        case = CaseAccessors(self.domain).get_case(self.case.case_id)

        self.assertEqual(
            updated_on.replace(tzinfo=pytz.UTC),
            get_datetime_case_property_changed(case, "abc", "updated")
        )

    @run_with_all_backends
    def test_multiple_cases_in_update(self):
        day_1 = datetime(2015, 5, 1, 12, 11)
        day_2 = datetime(2015, 5, 2, 12, 11)

        # Submit two updates TOGETHER, one for this case, but irrelevant,
        # and one for another case, but touching the same property
        self.factory.create_or_update_cases([
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'not_relevant': "updated"
                    },
                    "date_modified": day_1,
                }),
            CaseStructure(
                self.other_case.case_id,
                attrs={
                    "update": {
                        'relevant_property': "updated"
                    },
                    "date_modified": day_1,
                }),
        ])

        # Submit an update that DOES modify the relevant property
        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'relevant_property': "updated"
                    },
                    "date_modified": day_2,
                }),
        )
        case = CaseAccessors(self.domain).get_case(self.case.case_id)

        self.assertEqual(
            day_2.replace(tzinfo=pytz.UTC),
            get_datetime_case_property_changed(case, "relevant_property", "updated")
        )

    @run_with_all_backends
    def test_owner_id_changed(self):
        changes, _ = get_paged_changes_to_case_property(self.case, 'owner_id')
        self.assertEqual(len(changes), 1)
        self.assertEqual(changes[0].new_value, 'owner')

        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'owner_id': 'new_owner'
                    },
                }),
        )
#.........这里部分代码省略.........
开发者ID:dimagi,项目名称:commcare-hq,代码行数:103,代码来源:test_get_case_property_changes.py

示例15: AutoCloseExtensionsTest

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_cases [as 别名]
class AutoCloseExtensionsTest(SyncBaseTest):
    def setUp(self):
        FormProcessorTestUtils.delete_all_cases()
        FormProcessorTestUtils.delete_all_xforms()
        self.domain = "domain"
        self.project = Domain(name=self.domain)
        self.user = User(user_id='user', username='name', password="changeme",
                         date_joined=datetime(2011, 6, 9))
        self.factory = CaseFactory()
        self.extension_ids = ['1', '2', '3']
        self.host = CaseStructure(case_id='host')
        self.extension = CaseStructure(
            case_id=self.extension_ids[0],
            indices=[CaseIndex(
                related_structure=self.host,
                relationship="extension",
            )],
        )
        self.extension_2 = CaseStructure(
            case_id=self.extension_ids[1],
            indices=[CaseIndex(
                related_structure=self.extension,
                relationship="extension",
            )],
        )
        self.extension_3 = CaseStructure(
            case_id=self.extension_ids[2],
            indices=[CaseIndex(
                related_structure=self.extension_2,
                relationship="extension",
            )],
        )

    def test_get_extension_chain_simple(self):
        self.factory.create_or_update_cases([self.extension])
        self.assertEqual(set(self.extension_ids[0]), get_extension_chain([self.host], self.domain))

    def test_get_extension_chain_multiple(self):
        self.factory.create_or_update_cases([self.extension_3])
        self.assertEqual(set(self.extension_ids),
                         get_extension_chain([self.host], self.domain))

    @flag_enabled('EXTENSION_CASES_SYNC_ENABLED')
    def test_get_extension_to_close(self):
        """should return empty if case is not a host, otherwise should return full chain"""
        created_cases = self.factory.create_or_update_cases([self.extension_3])
        # host open, should be empty
        no_cases = get_extensions_to_close(created_cases[-1], self.domain)
        self.assertEqual(set(), no_cases)

        created_cases[-1] = self.factory.create_or_update_case(CaseStructure(
            case_id=self.host.case_id,
            attrs={'close': True}
        ))[0]

        # host closed, should get full chain
        full_chain = get_extensions_to_close(created_cases[-1], self.domain)
        self.assertEqual(set(self.extension_ids), full_chain)

        # extension (not a host), should be empty
        no_cases = get_extensions_to_close(created_cases[2], self.domain)
        self.assertEqual(set(), no_cases)

    @flag_enabled('EXTENSION_CASES_SYNC_ENABLED')
    def test_close_cases(self):
        """Closing a host should close all the extensions"""
        self.factory.create_or_update_cases([self.extension_3])
        self.assertFalse(CommCareCase.get(self.extension.case_id).closed)
        self.assertFalse(CommCareCase.get(self.extension_2.case_id).closed)
        self.assertFalse(CommCareCase.get(self.extension_3.case_id).closed)

        self.factory.create_or_update_case(CaseStructure(
            case_id=self.extension.case_id,
            attrs={'close': True}
        ))
        self.assertFalse(CommCareCase.get(self.host.case_id).closed)
        self.assertTrue(CommCareCase.get(self.extension.case_id).closed)
        self.assertFalse(CommCareCase.get(self.extension_2.case_id).closed)
        self.assertFalse(CommCareCase.get(self.extension_3.case_id).closed)

        self.factory.create_or_update_case(CaseStructure(
            case_id=self.host.case_id,
            attrs={'close': True}
        ))
        self.assertTrue(CommCareCase.get(self.host.case_id).closed)
        self.assertTrue(CommCareCase.get(self.extension.case_id).closed)
        self.assertTrue(CommCareCase.get(self.extension_2.case_id).closed)
        self.assertTrue(CommCareCase.get(self.extension_3.case_id).closed)
开发者ID:bazuzi,项目名称:commcare-hq,代码行数:90,代码来源:test_close_extension_chain.py


注:本文中的casexml.apps.case.mock.CaseFactory.create_or_update_cases方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。