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


Python FormRepeater.get_url方法代码示例

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


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

示例1: RepeaterTest

# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import get_url [as 别名]
class RepeaterTest(BaseRepeaterTest):
    def setUp(self):

        self.domain = "test-domain"
        create_domain(self.domain)
        self.case_repeater = CaseRepeater(
            domain=self.domain,
            url='case-repeater-url',
            version=V1,
        )
        self.case_repeater.save()
        self.form_repeater = FormRepeater(
            domain=self.domain,
            url='form-repeater-url',
        )
        self.form_repeater.save()
        self.log = []
        self.post_xml(xform_xml, self.domain)

    def clear_log(self):
        for i in range(len(self.log)):
            self.log.pop()

    def make_post_fn(self, status_codes):
        status_codes = iter(status_codes)

        def post_fn(data, url, headers=None):
            status_code = status_codes.next()
            self.log.append((url, status_code, data, headers))

            class resp:
                status = status_code
            return resp

        return post_fn

    def tearDown(self):
        self.case_repeater.delete()
        self.form_repeater.delete()
        XFormInstance.get(instance_id).delete()
        repeat_records = RepeatRecord.all()
        for repeat_record in repeat_records:
            repeat_record.delete()

    def test_repeater(self):
        #  this test should probably be divided into more units

        CommCareCase.get(case_id)

        def now():
            return datetime.utcnow()

        repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
        self.assertEqual(len(repeat_records), 2)

        self.clear_log()

        records_by_repeater_id = {}
        for repeat_record in repeat_records:
            repeat_record.fire(post_fn=self.make_post_fn([404, 404, 404]))
            repeat_record.save()
            records_by_repeater_id[repeat_record.repeater_id] = repeat_record

        for (url, status, data, headers) in self.log:
            self.assertEqual(status, 404)

        self.clear_log()

        next_check_time = now() + timedelta(minutes=60)

        repeat_records = RepeatRecord.all(
            domain=self.domain,
            due_before=now() + timedelta(minutes=15),
        )
        self.assertEqual(len(repeat_records), 0)

        repeat_records = RepeatRecord.all(
            domain=self.domain,
            due_before=next_check_time + timedelta(seconds=2),
        )
        self.assertEqual(len(repeat_records), 2)

        for repeat_record in repeat_records:
            self.assertLess(abs(next_check_time - repeat_record.next_check),
                            timedelta(seconds=3))
            repeat_record.fire(post_fn=self.make_post_fn([404, 200]))
            repeat_record.save()

        self.assertEqual(len(self.log), 4)

        # The following is pretty fickle and depends on which of
        #   - corehq.apps.receiverwrapper.signals
        #   - casexml.apps.case.signals
        # gets loaded first.
        # This is deterministic but easily affected by minor code changes

        # check case stuff
        rec = records_by_repeater_id[self.case_repeater.get_id]
        self.assertEqual(self.log[1][:2], (self.case_repeater.get_url(rec), 200))
        self.assertIn('server-modified-on', self.log[1][3])
#.........这里部分代码省略.........
开发者ID:nnestle,项目名称:commcare-hq,代码行数:103,代码来源:test_repeater.py


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