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


Python CaseFactory.create_or_update_case方法代码示例

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


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

示例1: test_extension_index

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    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']))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:28,代码来源:test_bugs.py

示例2: TestIndexedCaseIds

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
class TestIndexedCaseIds(TestCase):
    @classmethod
    def setUpClass(cls):
        delete_all_cases()

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

    def test_indexed_case_ids_returns_extensions(self):
        """ When getting indices, also return extensions """
        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_indexed_case_ids(self.domain, [extension_id])
        self.assertItemsEqual(returned_cases, [host_id])
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:27,代码来源:test_db_accessors.py

示例3: TestIndexedCaseIds

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

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

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

    def test_indexed_case_ids_returns_extensions(self):
        """ When getting indices, also return extensions """
        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_indexed_case_ids([extension_id])
        self.assertItemsEqual(returned_cases, [host_id])
开发者ID:dimagi,项目名称:commcare-hq,代码行数:31,代码来源:test_db_accessors.py

示例4: test_deleted_indices_removed

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    def test_deleted_indices_removed(self):
        factory = CaseFactory(
            self.domain,
            case_defaults={
                'user_id': self.commcare_user._id,
                'owner_id': self.commcare_user._id,
                'case_type': 'a-case',
                'create': True,
            },
        )
        # create a parent/child set of cases
        parent_id, child_id = [uuid.uuid4().hex for i in range(2)]
        child, parent = factory.create_or_update_case(CaseStructure(
            case_id=child_id,
            indices=[
                CaseIndex(CaseStructure(case_id=parent_id))
            ]
        ))
        # confirm the child has an index, and 1 form
        self.assertEqual(1, len(child.indices))
        self.assertEqual(parent_id, child.indices[0].referenced_id)
        self.assertEqual(1, len(child.xform_ids))

        # simulate parent deletion
        parent.soft_delete()

        # call the remove index task
        remove_indices_from_deleted_cases(self.domain, [parent_id])

        # check that the index is removed via a new form
        child = CaseAccessors(self.domain).get_case(child_id)
        self.assertEqual(0, len(child.indices))
        self.assertEqual(2, len(child.xform_ids))
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:35,代码来源:retire.py

示例5: test_form_extras_override_defaults

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_form_extras_override_defaults(self):
     domain = uuid.uuid4().hex
     token_id = uuid.uuid4().hex
     factory = CaseFactory(domain=domain, form_extras={'last_sync_token': token_id})
     [case] = factory.create_or_update_case(CaseStructure(attrs={'create': True}), form_extras={'last_sync_token': 'differenttoken'})
     form = FormAccessors(domain).get_form(case.xform_ids[0])
     self.assertEqual('differenttoken', form.last_sync_token)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_factory.py

示例6: test_simple_delete

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    def test_simple_delete(self):
        factory = CaseFactory()
        case = factory.create_case()
        [case] = factory.create_or_update_case(
            CaseStructure(case_id=case.case_id, attrs={'update': {'foo': 'bar'}})
        )
        self.assertIsNotNone(self.casedb.get_case(case.case_id))
        self.assertEqual(2, len(case.xform_ids))
        for form_id in case.xform_ids:
            self.assertIsNotNone(self.formdb.get_form(form_id))

        with capture_kafka_changes_context(topics.FORM_SQL, topics.CASE_SQL) as change_context:
            safe_hard_delete(case)

        if should_use_sql_backend(case.domain):
            self.assertEqual(3, len(change_context.changes))
            expected_ids = {case.case_id} | set(case.xform_ids)
            self.assertEqual(expected_ids, {change.id for change in change_context.changes})
            for change in change_context.changes:
                self.assertTrue(change.deleted)

        with self.assertRaises(CaseNotFound):
            self.casedb.get_case(case.case_id)

        for form_id in case.xform_ids:
            with self.assertRaises(XFormNotFound):
                self.formdb.get_form(form_id)
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:29,代码来源:test_delete.py

示例7: test_form_extras_override_defaults

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_form_extras_override_defaults(self):
     domain = uuid.uuid4().hex
     LOOSE_SYNC_TOKEN_VALIDATION.set(domain, True, namespace="domain")
     token_id = uuid.uuid4().hex
     factory = CaseFactory(domain=domain, form_extras={"last_sync_token": token_id})
     [case] = factory.create_or_update_case(CaseStructure(), form_extras={"last_sync_token": "differenttoken"})
     form = FormAccessors(domain).get_form(case.xform_ids[0])
     self.assertEqual("differenttoken", form.last_sync_token)
开发者ID:philipkaare,项目名称:commcare-hq,代码行数:10,代码来源:test_factory.py

示例8: test_form_extras_override_defaults

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_form_extras_override_defaults(self):
     domain = uuid.uuid4().hex
     LOOSE_SYNC_TOKEN_VALIDATION.set(domain, True, namespace='domain')
     token_id = uuid.uuid4().hex
     factory = CaseFactory(domain=domain, form_extras={'last_sync_token': token_id})
     [case] = factory.create_or_update_case(CaseStructure(), form_extras={'last_sync_token': 'differenttoken'})
     form = XFormInstance.get(case.xform_ids[0])
     self.assertEqual('differenttoken', form.last_sync_token)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:test_factory.py

示例9: test_form_extras

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_form_extras(self):
     domain = uuid.uuid4().hex
     LOOSE_SYNC_TOKEN_VALIDATION.set(domain, True, namespace='domain')
     token_id = uuid.uuid4().hex
     factory = CaseFactory(domain=domain)
     [case] = factory.create_or_update_case(CaseStructure(), form_extras={'last_sync_token': token_id})
     form = FormProcessorInterface(domain).xform_model.get(case.xform_ids[0])
     self.assertEqual(token_id, form.last_sync_token)
开发者ID:nnestle,项目名称:commcare-hq,代码行数:10,代码来源:test_factory.py

示例10: test_no_walk_related

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_no_walk_related(self):
     factory = CaseFactory()
     parent = factory.create_case()
     child_updates = factory.create_or_update_case(
         CaseStructure(attrs={'create': True}, walk_related=False, relationships=[
             CaseRelationship(CaseStructure(case_id=parent._id))
         ]),
     )
     self.assertEqual(1, len(child_updates))
     self.assertEqual(parent._id, child_updates[0].indices[0].referenced_id)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:12,代码来源:test_factory.py

示例11: test_complex_index

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    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']))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:43,代码来源:test_bugs.py

示例12: test_simple_delete

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
 def test_simple_delete(self):
     factory = CaseFactory()
     case = factory.create_case()
     [case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
     self.assertTrue(CommCareCase.get_db().doc_exist(case._id))
     self.assertEqual(2, len(case.xform_ids))
     for form_id in case.xform_ids:
         self.assertTrue(XFormInstance.get_db().doc_exist(form_id))
     safe_hard_delete(case)
     self.assertFalse(CommCareCase.get_db().doc_exist(case._id))
     for form_id in case.xform_ids:
         self.assertFalse(XFormInstance.get_db().doc_exist(form_id))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:14,代码来源:test_delete.py

示例13: TestCaseHistory

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
class TestCaseHistory(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={"prop_1": "val1"})
        self.other_case = self.factory.create_case()

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

    @run_with_all_backends
    def test_case_history(self):
        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'prop_1': "val1",
                        'prop_2': "val1",
                        'prop_3': "val1",
                    },
                }),
        )
        self.factory.create_or_update_case(
            CaseStructure(
                self.case.case_id,
                attrs={
                    "update": {
                        'prop_1': "val2",
                        'prop_2': "val2",
                        'prop_4': "val",
                    },
                }),
        )
        case = CaseAccessors(self.domain).get_case(self.case.case_id)
        history = get_case_history(case)
        self.assertEqual(history[0]['prop_1'], "val1")
        self.assertEqual(history[1]['prop_2'], "val1")
        self.assertEqual(history[2]['prop_2'], "val2")
开发者ID:dimagi,项目名称:commcare-hq,代码行数:42,代码来源:test_case_history.py

示例14: test_simple_delete

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    def test_simple_delete(self):
        factory = CaseFactory()
        case = factory.create_case()
        [case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
        self.assertIsNotNone(FormProcessorInterface.get_case(case.id))
        self.assertEqual(2, len(case.xform_ids))
        for form_id in case.xform_ids:
            self.assertIsNotNone(FormProcessorInterface.get_xform(form_id))
        FormProcessorInterface.hard_delete_case(case)

        with self.assertRaises(CaseNotFound):
            FormProcessorInterface.get_case(case.id)

        for form_id in case.xform_ids:
            with self.assertRaises(XFormNotFound):
                FormProcessorInterface.get_xform(form_id)
开发者ID:johan--,项目名称:commcare-hq,代码行数:18,代码来源:test_delete.py

示例15: test_delete_with_related

# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_or_update_case [as 别名]
    def test_delete_with_related(self):
        factory = CaseFactory()
        parent = factory.create_case()
        [child] = factory.create_or_update_case(
            CaseStructure(attrs={'create': True}, walk_related=False, relationships=[
                CaseRelationship(CaseStructure(case_id=parent._id))
            ]),
        )
        # deleting the parent should not be allowed because the child still references it
        with self.assertRaises(CommCareCaseError):
            safe_hard_delete(parent)

        # deleting the child is ok
        safe_hard_delete(child)
        self.assertTrue(CommCareCase.get_db().doc_exist(parent._id))
        self.assertFalse(CommCareCase.get_db().doc_exist(child._id))
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:18,代码来源:test_delete.py


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