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


Python mock.CaseFactory类代码示例

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


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

示例1: TestIndexedCaseIds

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,代码行数:29,代码来源:test_db_accessors.py

示例2: test_create_from_structure

    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,代码行数:30,代码来源:test_factory.py

示例3: post

    def post(self, request, *args, **kwargs):
        domain = request.GET.get('domain')
        case_type = request.GET.get('case_type')
        user_name = request.GET.get('user')
        properties = json.loads(request.body)
        case_id = properties['case_id']

        properties.pop('case_id')

        couch_user = CommCareUser.get_by_username(user_name)
        if not couch_user.is_member_of(domain):
            return HttpResponseForbidden("This user does not have access to this domain.")

        case = get_case_or_404(domain, case_id)

        if not case.type == case_type:
            return HttpResponseBadRequest("Case type mismatch")

        factory = CaseFactory(domain=domain)
        factory.update_case(
            case_id=case_id,
            update=properties
        )

        return HttpResponse("Case {case_id} updated".format(case_id=case_id))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:25,代码来源:views.py

示例4: TestIndexedCaseIds

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,代码行数:25,代码来源:test_db_accessors.py

示例5: test_deleted_indices_removed

    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,代码行数:33,代码来源:retire.py

示例6: test_create_from_structure

    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,代码行数:31,代码来源:test_factory.py

示例7: test_extension_index

    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,代码行数:26,代码来源:test_bugs.py

示例8: test_simple_delete

    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,代码行数:27,代码来源:test_delete.py

示例9: test_form_extras_override_defaults

 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,代码行数:7,代码来源:test_factory.py

示例10: test_form_extras

 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,代码行数:8,代码来源:test_factory.py

示例11: test_form_extras_override_defaults

 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,代码行数:8,代码来源:test_factory.py

示例12: test_form_extras_override_defaults

 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,代码行数:8,代码来源:test_factory.py

示例13: setUpClass

    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,代码行数:58,代码来源:test_filter_dsl.py

示例14: test_form_extras_default

 def test_form_extras_default(self):
     domain = uuid.uuid4().hex
     # have to enable loose sync token validation for the domain or create actual SyncLog documents.
     # this is the easier path.
     token_id = uuid.uuid4().hex
     factory = CaseFactory(domain=domain, form_extras={'last_sync_token': token_id})
     case = factory.create_case()
     form = FormAccessors(domain).get_form(case.xform_ids[0])
     self.assertEqual(token_id, form.last_sync_token)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:9,代码来源:test_factory.py

示例15: test_form_extras_default

 def test_form_extras_default(self):
     domain = uuid.uuid4().hex
     # have to enable loose sync token validation for the domain or create actual SyncLog documents.
     # this is the easier path.
     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_case()
     form = XFormInstance.get(case.xform_ids[0])
     self.assertEqual(token_id, form.last_sync_token)
开发者ID:LifeCoaching,项目名称:commcare-hq,代码行数:10,代码来源:test_factory.py


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