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


Python FormProcessorInterface.post_xform方法代码示例

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


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

示例1: test_basic_duplicate

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_basic_duplicate(self):
        xml_data = self._get_file()
        xform = FormProcessorInterface.post_xform(xml_data)
        self.assertEqual(self.ID, xform.id)
        self.assertEqual("XFormInstance", xform.doc_type)
        self.assertEqual("test-domain", xform.domain)

        xform = FormProcessorInterface.post_xform(xml_data, domain='test-domain')
        self.assertNotEqual(self.ID, xform.id)
        self.assertEqual("XFormDuplicate", xform.doc_type)
        self.assertTrue(self.ID in xform.problem)
开发者ID:johan--,项目名称:commcare-hq,代码行数:13,代码来源:test_duplicates.py

示例2: testDecimalAppVersion

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testDecimalAppVersion(self):
        '''
        Tests that an appVersion that looks like a decimal:
        (a) is not converted to a Decimal by couchdbkit
        (b) does not crash anything
        '''

        file_path = os.path.join(os.path.dirname(__file__), "data", "decimalmeta.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(xform_generic.metadata.appVersion, '2.0')
        self.assertEqual(xform_generic.metadata.to_json(), {
            'username': u'admin',
            'doc_type': 'Metadata',
            'instanceID': None,
            'userID': u'f7f0c79e-8b79-11df-b7de-005056c00008',
            'timeEnd': '2010-07-23T13:55:11.648000Z',
            'appVersion': u'2.0',
            'timeStart': '2010-07-22T13:54:27.971000Z',
            'deprecatedID': None,
            'deviceID': None,
            'clinic_id': u'5020280',
            'location': None,
        })
开发者ID:johan--,项目名称:commcare-hq,代码行数:27,代码来源:test_meta.py

示例3: testMetaDateInDatetimeFields

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testMetaDateInDatetimeFields(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "date_in_meta.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(datetime(2014, 7, 10), xform_generic.metadata.timeStart)
        self.assertEqual(datetime(2014, 7, 11), xform_generic.metadata.timeEnd)
开发者ID:johan--,项目名称:commcare-hq,代码行数:9,代码来源:test_meta.py

示例4: test_gps_location

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_gps_location(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "gps_location.xml")
        xml_data = open(file_path, "rb").read()

        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(
            xform_generic.metadata.location,
            # '42.3739063 -71.1109113 0.0 886.0'
            GeoPoint(
                latitude=Decimal('42.3739063'),
                longitude=Decimal('-71.1109113'),
                altitude=Decimal('0.0'),
                accuracy=Decimal('886.0'),
            )
        )

        self.assertEqual(xform_generic.metadata.to_json(), {
            'username': u'[email protected]',
            'doc_type': 'Metadata',
            'instanceID': u'5d3d01561f584e85b53669a48bfc6039',
            'userID': u'f7f0c79e-8b79-11df-b7de-005056c00008',
            'timeEnd': '2013-07-20T00:02:27.493000Z',
            'appVersion': u'2.0',
            'timeStart': '2013-07-19T21:21:31.188000Z',
            'deprecatedID': None,
            'deviceID': u'commconnect',
            'location': '42.3739063 -71.1109113 0.0 886.0',
        })
开发者ID:johan--,项目名称:commcare-hq,代码行数:31,代码来源:test_meta.py

示例5: _test

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def _test(self, name, any_id_ok=False, tz_differs=False):
        with open(os.path.join(os.path.dirname(__file__), 'data', '{name}.xml'.format(name=name))) as f:
            instance = f.read()

        if tz_differs and phone_timezones_should_be_processed():
            expected_name = name + '-tz'
        else:
            expected_name = name

        with open(os.path.join(os.path.dirname(__file__), 'data',
                               '{name}.json'.format(name=expected_name))) as f:
            result = json.load(f)

        xform = FormProcessorInterface.post_xform(instance)
        xform_json = json.loads(json.dumps(xform.to_json()))
        for key in ['is_archived', 'is_deprecated', 'is_duplicate', 'is_error']:
            del xform_json[key]

        result['received_on'] = xform_json['received_on']
        result['_rev'] = xform_json['_rev']
        result['_attachments'] = None
        xform_json['_attachments'] = None
        if any_id_ok:
            result['_id'] = xform_json['_id']
            result['id'] = xform_json['id']

        self.assertDictEqual(xform_json, result)
开发者ID:johan--,项目名称:commcare-hq,代码行数:29,代码来源:test_post.py

示例6: test_empty_gps_location

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_empty_gps_location(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "gps_empty_location.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(
            xform_generic.metadata.location,
            None
        )

        self.assertEqual(xform_generic.metadata.to_json()['location'], None)
开发者ID:johan--,项目名称:commcare-hq,代码行数:13,代码来源:test_meta.py

示例7: test_wrong_domain

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_wrong_domain(self):
        domain = 'test-domain'
        generic_xform = GenericXFormInstance(
            doc_type='XFormInstance',
            domain='wrong-domain',
        )
        xform = FormProcessorInterface.create_from_generic(generic_xform)

        instance = self._get_file()
        instance = instance.replace(self.ID, xform.id)
        xform = FormProcessorInterface.post_xform(instance, domain=domain)
        self.assertNotEqual(xform.id, self.ID)
开发者ID:johan--,项目名称:commcare-hq,代码行数:14,代码来源:test_duplicates.py

示例8: test_wrong_doc_type

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_wrong_doc_type(self):
        domain = 'test-domain'
        XFormInstance.get_db().save_doc({
            '_id': self.ID,
            'doc_type': 'Foo',
            'domain': domain,
        })
        self.addCleanup(lambda: XFormInstance.get_db().delete_doc(self.ID))

        instance = self._get_file()
        xform = FormProcessorInterface.post_xform(instance, domain=domain)
        self.assertNotEqual(xform.id, self.ID)
开发者ID:johan--,项目名称:commcare-hq,代码行数:14,代码来源:test_duplicates.py

示例9: test_basic_edit

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_basic_edit(self):
        xml_data1, xml_data2 = self._get_files()
        yesterday = datetime.utcnow() - timedelta(days=1)

        xform = FormProcessorInterface.post_xform(xml_data1)
        self.assertEqual(self.ID, xform.id)
        self.assertEqual("XFormInstance", xform.doc_type)
        self.assertEqual("", xform.form['vitals']['height'])
        self.assertEqual("other", xform.form['assessment']['categories'])

        # post form back in time to simulate an edit
        FormProcessorInterface.update_properties(
            xform,
            domain=self.domain,
            received_on=yesterday,
        )

        xform = FormProcessorInterface.post_xform(xml_data2, domain=self.domain)
        self.assertEqual(self.ID, xform.id)
        self.assertEqual("XFormInstance", xform.doc_type)
        self.assertEqual("100", xform.form['vitals']['height'])
        self.assertEqual("Edited Baby!", xform.form['assessment']['categories'])

        [deprecated_xform] = FormProcessorInterface.get_by_doc_type(self.domain, 'XFormDeprecated')

        self.assertEqual(self.ID, deprecated_xform.orig_id)
        self.assertNotEqual(self.ID, deprecated_xform.id)
        self.assertEqual('XFormDeprecated', deprecated_xform.doc_type)
        self.assertEqual("", deprecated_xform.form['vitals']['height'])
        self.assertEqual("other", deprecated_xform.form['assessment']['categories'])

        self.assertEqual(xform.received_on, deprecated_xform.received_on)
        self.assertEqual(xform.deprecated_form_id, deprecated_xform.id)
        self.assertTrue(xform.edited_on > deprecated_xform.received_on)

        self.assertEqual(
            FormProcessorInterface.get_attachment(deprecated_xform.id, 'form.xml'),
            xml_data1
        )
        self.assertEqual(FormProcessorInterface.get_attachment(self.ID, 'form.xml'), xml_data2)
开发者ID:johan--,项目名称:commcare-hq,代码行数:42,代码来源:test_edits.py

示例10: testCRSReg

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
 def testCRSReg(self):
     file_path = os.path.join(os.path.dirname(__file__), "data", "crs_reg.xml")
     with open(file_path, "rb") as f:
         xml_data = f.read()
     
     instance = FormProcessorInterface.post_xform(xml_data)
     instance = XFormInstance.get(instance.id)
     transform = DocumentTransform(instance._doc, get_db())
     self.assertTrue("IDENTIFIER" in json.dumps(transform.doc))
     self.assertTrue("IDENTIFIER" in transform.attachments["form.xml"])
     
     deidentified = deidentify_form(transform)
     self.assertTrue("IDENTIFIER" not in json.dumps(deidentified.doc))
     self.assertTrue("IDENTIFIER" not in deidentified.attachments["form.xml"])
开发者ID:johan--,项目名称:commcare-hq,代码行数:16,代码来源:test_deidentification.py

示例11: testClosed

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testClosed(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "namespaces.xml")
        xml_data = open(file_path, "rb").read()
        xform = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual("http://commcarehq.org/test/ns", xform.xmlns)
        self._assert_xmlns('no namespace here', xform, 'form/empty')
        self._assert_xmlns('http://commcarehq.org/test/flatns', xform, 'form/flat', True)
        self._assert_xmlns('http://commcarehq.org/test/parent', xform, 'form/parent', True)
        self._assert_xmlns('cwo', xform, 'form/parent/childwithout')
        self._assert_xmlns('http://commcarehq.org/test/child1', xform, 'form/parent/childwith', True)
        self._assert_xmlns('http://commcarehq.org/test/child2', xform, 'form/parent/childwithelement', True)
        self._assert_xmlns('gc', xform, 'form/parent/childwithelement/grandchild')
        self._assert_xmlns('lcwo', xform, 'form/parent/lastchildwithout')
        self._assert_xmlns('nothing here either', xform, 'form/lastempty')
开发者ID:johan--,项目名称:commcare-hq,代码行数:17,代码来源:test_namespaces.py

示例12: testMetaAppVersionDict

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testMetaAppVersionDict(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "meta_dict_appversion.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(xform_generic.metadata.appVersion, '2.0')

        self.assertEqual(xform_generic.metadata.to_json(), {
            'username': u'[email protected]',
            'doc_type': 'Metadata',
            'instanceID': u'5d3d01561f584e85b53669a48bfc6039',
            'userID': u'f7f0c79e-8b79-11df-b7de-005056c00008',
            'timeEnd': '2013-07-20T00:02:27.493000Z',
            'appVersion': u'2.0',
            'timeStart': '2013-07-19T21:21:31.188000Z',
            'deprecatedID': None,
            'deviceID': u'commconnect',
            'location': None,
        })
开发者ID:johan--,项目名称:commcare-hq,代码行数:21,代码来源:test_meta.py

示例13: testMetaBadUsername

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testMetaBadUsername(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "meta_bad_username.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertEqual(xform_generic.metadata.appVersion, '2.0')

        self.assertEqual(xform_generic.metadata.to_json(), {
            'username': u'2013-07-19',
            'doc_type': 'Metadata',
            'instanceID': u'e8afaec3c66745ef80e48062d4b91b56',
            'userID': u'f7f0c79e-8b79-11df-b7de-005056c00008',
            'timeEnd': '2013-07-20T00:02:27.493000Z',
            'appVersion': u'2.0',
            'timeStart': '2013-07-19T21:21:31.188000Z',
            'deprecatedID': None,
            'deviceID': u'commconnect',
            'location': None,
        })
开发者ID:johan--,项目名称:commcare-hq,代码行数:21,代码来源:test_meta.py

示例14: test_various_encodings

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def test_various_encodings(self):
        tests = (
            ('utf-8', u'हिन्दी चट्टानों'),
            ('UTF-8', u'हिन्दी चट्टानों'),
            ('ASCII', 'hello'),
        )
        file_path = os.path.join(os.path.dirname(__file__), "data", "encoding.xml")
        with open(file_path, "rb") as f:
            xml_template = f.read()

        for encoding, value in tests:
            xml_data = xml_template.format(
                encoding=encoding,
                form_id=uuid.uuid4().hex,
                sample_value=value.encode(encoding),
            )
            xform = FormProcessorInterface.post_xform(xml_data)
            self.assertEqual(value, xform.form['test'])
            elem = FormProcessorInterface.get_xml_element(xform)
            self.assertEqual(value, elem.find('{http://commcarehq.org/couchforms-tests}test').text)
开发者ID:johan--,项目名称:commcare-hq,代码行数:22,代码来源:test_xml.py

示例15: testClosed

# 需要导入模块: from corehq.form_processor.interfaces import FormProcessorInterface [as 别名]
# 或者: from corehq.form_processor.interfaces.FormProcessorInterface import post_xform [as 别名]
    def testClosed(self):
        file_path = os.path.join(os.path.dirname(__file__), "data", "meta.xml")
        xml_data = open(file_path, "rb").read()
        xform_generic = FormProcessorInterface.post_xform(xml_data)

        self.assertNotEqual(None, xform_generic.metadata)
        self.assertEqual(date(2010, 07, 22), xform_generic.metadata.timeStart.date())
        self.assertEqual(date(2010, 07, 23), xform_generic.metadata.timeEnd.date())
        self.assertEqual("admin", xform_generic.metadata.username)
        self.assertEqual("f7f0c79e-8b79-11df-b7de-005056c00008", xform_generic.metadata.userID)
        self.assertEqual("v1.2.3 (biz bazzle)", xform_generic.metadata.appVersion)
        self.assertEqual(xform_generic.metadata.to_json(), {
            'username': u'admin',
            'doc_type': 'Metadata',
            'instanceID': None,
            'userID': u'f7f0c79e-8b79-11df-b7de-005056c00008',
            'timeEnd': '2010-07-23T13:55:11.648000Z',
            'appVersion': u'v1.2.3 (biz bazzle)',
            'timeStart': '2010-07-22T13:54:27.971000Z',
            'deprecatedID': None,
            'deviceID': None,
            'clinic_id': u'5020280',
            'location': None,
        })
开发者ID:johan--,项目名称:commcare-hq,代码行数:26,代码来源:test_meta.py


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