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


Python mock.CaseBlock类代码示例

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


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

示例1: test_multiple_case_blocks_some_deleted

    def test_multiple_case_blocks_some_deleted(self, rebuild_case):
        """ Don't rebuild deleted cases """

        case_ids = [uuid.uuid4().hex, uuid.uuid4().hex, uuid.uuid4().hex]

        for i, case_id in enumerate(case_ids):
            if i == 0:
                # only the first case is owned by the user getting retired
                owner_id = self.other_user._id
            else:
                owner_id = self.commcare_user._id

            caseblock = CaseBlock(
                create=True,
                case_id=case_id,
                owner_id=owner_id,
                user_id=self.commcare_user._id,
            )
            submit_case_blocks(caseblock.as_string(), self.domain, user_id=self.other_user._id)

        self.other_user.retire()

        detail = UserArchivedRebuild(user_id=self.other_user.user_id)
        expected_call_args = [mock.call(self.domain, case_id, detail) for case_id in case_ids[1:]]

        self.assertEqual(rebuild_case.call_count, len(case_ids) - 1)
        self.assertItemsEqual(rebuild_case.call_args_list, expected_call_args)
开发者ID:tlwakwella,项目名称:commcare-hq,代码行数:27,代码来源:retire.py

示例2: test_case_block_index_supports_relationship

    def test_case_block_index_supports_relationship(self):
        """
        CaseBlock index should allow the relationship to be set
        """
        case_block = CaseBlock(
            case_id='abcdef',
            case_type='at_risk',
            date_modified='2015-07-24',
            date_opened='2015-07-24',
            index={
                'host': IndexAttrs(case_type='newborn', case_id='123456', relationship='extension')
            },
        )

        self.assertEqual(
            ElementTree.tostring(case_block.as_xml()).decode('utf-8'),
            re.sub(r'(\n| {2,})', '', """
            <case case_id="abcdef" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
                <update>
                    <case_type>at_risk</case_type>
                    <date_opened>2015-07-24</date_opened>
                </update>
                <index>
                    <host case_type="newborn" relationship="extension">123456</host>
                </index>
            </case>
            """)
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:28,代码来源:test_indexes.py

示例3: test_all_case_forms_deleted

    def test_all_case_forms_deleted(self):
        from corehq.apps.callcenter.sync_user_case import sync_usercase
        sync_usercase(self.commcare_user)

        user_case_id = self.commcare_user.get_usercase_id()

        # other user submits form against the case (should get deleted)
        caseblock = CaseBlock(
            create=False,
            case_id=user_case_id,
        )
        submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain, user_id=self.other_user._id)

        case_ids = CaseAccessors(self.domain).get_case_ids_by_owners([self.commcare_user._id])
        self.assertEqual(1, len(case_ids))

        form_ids = FormAccessors(self.domain).get_form_ids_for_user(self.commcare_user._id)
        self.assertEqual(0, len(form_ids))

        user_case = self.commcare_user.get_usercase()
        self.assertEqual(2, len(user_case.xform_ids))

        self.commcare_user.retire()

        for form_id in user_case.xform_ids:
            self.assertTrue(FormAccessors(self.domain).get_form(form_id).is_deleted)

        self.assertTrue(CaseAccessors(self.domain).get_case(user_case_id).is_deleted)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:28,代码来源:retire.py

示例4: submit_mapping_case_block

def submit_mapping_case_block(user, index):
    mapping = user.get_location_map_case()

    if mapping:
        caseblock = CaseBlock(
            create=False,
            case_id=mapping._id,
            version=V2,
            index=index
        )
    else:
        caseblock = CaseBlock(
            create=True,
            case_type=const.USER_LOCATION_OWNER_MAP_TYPE,
            case_id=location_map_case_id(user),
            version=V2,
            owner_id=user._id,
            index=index,
            case_name=const.USER_LOCATION_OWNER_MAP_TYPE.replace('-', ' '),
            user_id=const.COMMTRACK_USERNAME,
        )

    submit_case_blocks(
        ElementTree.tostring(
            caseblock.as_xml(format_datetime=json_format_datetime)
        ),
        user.domain,
    )
开发者ID:dslowikowski,项目名称:commcare-hq,代码行数:28,代码来源:util.py

示例5: test_case_block_index_default_relationship

    def test_case_block_index_default_relationship(self):
        """
        CaseBlock index relationship should default to "child"
        """
        case_block = CaseBlock(
            case_id='123456',
            case_type='newborn',
            date_modified='2015-07-24',
            date_opened='2015-07-24',
            index={
                'parent': ChildIndexAttrs(case_type='mother', case_id='789abc')
            },
        )

        self.assertEqual(
            ElementTree.tostring(case_block.as_xml()).decode('utf-8'),
            re.sub(r'(\n| {2,})', '', """
            <case case_id="123456" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
                <update>
                    <case_type>newborn</case_type>
                    <date_opened>2015-07-24</date_opened>
                </update>
                <index>
                    <parent case_type="mother">789abc</parent>
                </index>
            </case>
            """)
        )
开发者ID:dimagi,项目名称:commcare-hq,代码行数:28,代码来源:test_indexes.py

示例6: create_case_from_dhis2

def create_case_from_dhis2(dhis2_child, domain, user):
    """
    Create a new case using the data pulled from DHIS2

    :param dhis2_child: TRACKED_ENTITY (i.e. "Child") from DHIS2
    :param domain: (str) The name of the domain
    :param user: (Document) The owner of the new case
    :return: New case ID
    """
    case_id = uuid.uuid4().hex
    update = {k: dhis2_child[v] for k, v in NUTRITION_ASSESSMENT_PROGRAM_FIELDS.iteritems()}
    update['dhis_org_id'] = dhis2_child['Org unit']
    # Do the inverse of push_case() to 'Gender' / 'child_gender'
    if 'child_gender' in update:
        if update['child_gender'] == 'Undefined':
            del update['child_gender']
        else:
            update['child_gender'] = update['child_gender'].lower()
    caseblock = CaseBlock(
        create=True,
        case_id=case_id,
        owner_id=user.userID,
        user_id=user.userID,
        case_type=CASE_TYPE,
        case_name=update[CASE_NAME] if CASE_NAME else '',
        external_id=dhis2_child['Instance'],
        update=update
    )
    casexml = ElementTree.tostring(caseblock.as_xml())
    submit_case_blocks(casexml, domain)
    return case_id
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:31,代码来源:tasks.py

示例7: submit_mapping_case_block

def submit_mapping_case_block(user, index):
    mapping = user.get_location_map_case()

    if mapping:
        caseblock = CaseBlock(
            create=False,
            case_id=mapping._id,
            version=V2,
            index=index
        )
    else:
        caseblock = CaseBlock(
            create=True,
            case_type=USER_LOCATION_OWNER_MAP_TYPE,
            case_id=location_map_case_id(user),
            version=V2,
            owner_id=user._id,
            index=index
        )

    submit_case_blocks(
        ElementTree.tostring(caseblock.as_xml()),
        user.domain,
        user.username,
        user._id
    )
开发者ID:rigambhir,项目名称:commcare-hq,代码行数:26,代码来源:util.py

示例8: test_forms_touching_live_case_not_deleted

    def test_forms_touching_live_case_not_deleted(self):
        case_id = uuid.uuid4().hex
        caseblock = CaseBlock(
            create=True,
            case_id=case_id,
            owner_id=self.commcare_user._id,
            user_id=self.commcare_user._id,
        )
        xform, _ = submit_case_blocks(caseblock.as_string().decode('utf-8'), self.domain)

        # other user submits form against the case and another case not owned by the user
        # should NOT get deleted since this form touches a case that's still 'alive'
        double_case_xform, _ = submit_case_blocks([
            CaseBlock(
                create=False,
                case_id=case_id,
            ).as_string().decode('utf-8'),
            CaseBlock(
                create=True,
                case_id=uuid.uuid4().hex,
                owner_id=self.other_user._id,
                user_id=self.other_user._id,
            ).as_string().decode('utf-8')
        ], self.domain, user_id=self.other_user._id)

        self.commcare_user.retire()

        self.assertTrue(FormAccessors(self.domain).get_form(xform.form_id).is_deleted)
        self.assertFalse(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)

        # When the other user is deleted then the form should get deleted since it no-longer touches
        # any 'live' cases.
        self.other_user.retire()
        self.assertTrue(FormAccessors(self.domain).get_form(double_case_xform.form_id).is_deleted)
开发者ID:dimagi,项目名称:commcare-hq,代码行数:34,代码来源:retire.py

示例9: make_supply_point_product

def make_supply_point_product(supply_point_case, product_uuid, owner_id=None):
    domain = supply_point_case.domain
    id = uuid.uuid4().hex
    user_id = const.get_commtrack_user_id(domain)
    owner_id = owner_id or get_owner_id(supply_point_case) or user_id
    username = const.COMMTRACK_USERNAME
    product_name = Product.get(product_uuid).name
    caseblock = CaseBlock(
        case_id=id,
        create=True,
        version=V2,
        case_name=product_name,
        user_id=user_id,
        owner_id=owner_id,
        case_type=const.SUPPLY_POINT_PRODUCT_CASE_TYPE,
        update={
            "product": product_uuid
        },
        index={
            const.PARENT_CASE_REF: (const.SUPPLY_POINT_CASE_TYPE,
                                    supply_point_case._id),
        }
    )
    casexml = ElementTree.tostring(caseblock.as_xml())
    submit_case_blocks(casexml, domain, username, user_id,
                       xmlns=const.COMMTRACK_SUPPLY_POINT_PRODUCT_XMLNS)
    sppc = SupplyPointProductCase.get(id)
    sppc.bind_to_location(supply_point_case.location)
    sppc.save()
    return sppc
开发者ID:modonnell729,项目名称:commcare-hq,代码行数:30,代码来源:helpers.py

示例10: test_case_block_index_omit_child

    def test_case_block_index_omit_child(self):
        """
        CaseBlock index relationship omit relationship attribute if set to "child"
        """
        case_block = CaseBlock(
            case_id='123456',
            case_type='newborn',
            date_modified='2015-07-24',
            index={
                'parent': IndexAttrs(case_type='mother', case_id='789abc', relationship='child')
            },
        )

        self.assertEqual(
            ElementTree.tostring(case_block.as_xml()),
            re.sub(r'(\n| {2,})', '', """
            <case case_id="123456" date_modified="2015-07-24" xmlns="http://commcarehq.org/case/transaction/v2">
                <update>
                    <case_type>newborn</case_type>
                </update>
                <index>
                    <parent case_type="mother">789abc</parent>
                </index>
            </case>
            """)
        )
开发者ID:saketkanth,项目名称:commcare-hq,代码行数:26,代码来源:test_indexes.py

示例11: testBadIndexReference

 def testBadIndexReference(self):
     block = CaseBlock(create=True, case_id=self.CASE_ID, user_id=USER_ID, version=V2,
                       index={'bad': ('bad-case', 'not-an-existing-id')})
     try:
         post_case_blocks([block.as_xml()])
         self.fail("Submitting against a bad case in an index should fail!")
     except IllegalCaseId:
         pass
开发者ID:kamilk161,项目名称:commcare-hq,代码行数:8,代码来源:test_indexes.py

示例12: to_xml

        def to_xml(to_update):
            caseblock = CaseBlock(
                create=False,
                case_id=to_update.case.case_id,
                user_id=MOTECH_ID,
                owner_id=to_update.new_owner_id or CaseBlock.undefined,
                case_type=to_update.new_type or CaseBlock.undefined,
            )

            return ElementTree.tostring(caseblock.as_xml())
开发者ID:nnestle,项目名称:commcare-hq,代码行数:10,代码来源:bihar_cleanup_case_2.py

示例13: update_case_external_id

def update_case_external_id(case, external_id):
    """
    Update the external_id of a case
    """
    caseblock = CaseBlock(
        create=False,
        case_id=case['_id'],
        external_id=external_id
    )
    casexml = ElementTree.tostring(caseblock.as_xml())
    submit_case_blocks(casexml, case['domain'])
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:11,代码来源:tasks.py

示例14: _create_closed_case

 def _create_closed_case(cls):
     case_id = uuid.uuid4().hex
     caseblock = CaseBlock(
         case_id=case_id,
         case_type=cls.case_type,
         date_opened=cls.closed_case_date_opened,
         date_modified=cls.closed_case_date_closed,
         case_name=cls.case_name,
         close=True,
     )
     post_case_blocks([caseblock.as_xml()], domain=cls.domain)
     return case_id
开发者ID:dimagi,项目名称:commcare-hq,代码行数:12,代码来源:test_aggregation.py

示例15: pull_child_entities

def pull_child_entities(settings, dhis2_children):
    """
    Create new child cases for nutrition tracking in CommCare.

    Sets external_id on new child cases, and CCHQ Case ID on DHIS2
    tracked entity instances. (CCHQ Case ID is initially unset because the
    case is new and does not exist in CommCare.)

    :param settings: DHIS2 settings, incl. relevant domain
    :param dhis2_children: A list of dictionaries of Child tracked entities
                           from the DHIS2 API where CCHQ Case ID is unset

    This fulfills the third requirement of `DHIS2 Integration`_.


    .. _DHIS2 Integration: https://www.dropbox.com/s/8djk1vh797t6cmt/WV Sri Lanka Detailed Requirements.docx
    """
    dhis2_api = Dhis2Api(settings.dhis2.host, settings.dhis2.username, settings.dhis2.password,
                         settings.dhis2.top_org_unit_name)
    for dhis2_child in dhis2_children:
        # Add each child separately. Although this is slower, it avoids problems if a DHIS2 API call fails
        # ("Instance" is DHIS2's friendly name for "id")
        case = get_case_by_external_id(settings.domain, dhis2_child['Instance'])
        if case:
            case_id = case['case_id']
        else:
            user = get_user_by_org_unit(settings.domain, dhis2_child['Org unit'], settings.dhis2.top_org_unit_name)
            if not user:
                # No user is assigned to this organisation unit (i.e. region or facility). Now what?
                # TODO: Now what? Ascend to parent org unit?
                continue
            case_id = uuid.uuid4().hex
            caseblock = CaseBlock(
                create=True,
                case_id=case_id,
                owner_id=user.userID,
                user_id=user.userID,
                version=V2,
                case_type='child_gmp',  # TODO: Move to a constant / setting
                external_id=dhis2_child['Instance'],
                update={
                    'name': dhis2_child['Name'],
                    'height': dhis2_child['Height'],
                    'weight': dhis2_child['Weight'],
                    'age': dhis2_child['Age at time of visit'],
                    'bmi': dhis2_child['Body-mass index'],
                }
            )
            casexml = ElementTree.tostring(caseblock.as_xml())
            submit_case_blocks(casexml, settings.domain)
        dhis2_child['CCHQ Case ID'] = case_id
        dhis2_api.update_te_inst(dhis2_child)
开发者ID:jmaina,项目名称:commcare-hq,代码行数:52,代码来源:tasks.py


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