本文整理汇总了Python中corehq.apps.receiverwrapper.models.FormRepeater类的典型用法代码示例。如果您正苦于以下问题:Python FormRepeater类的具体用法?Python FormRepeater怎么用?Python FormRepeater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormRepeater类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.client = Client()
self.domain = "test-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)
示例2: setUp
def setUp(self):
self.client = Client()
self.domain = "test-domain"
create_domain(self.domain)
self.case_repeater = CaseRepeater(domain=self.domain, url='case-repeater-url', version=V1, next_check=datetime.utcnow() - timedelta(seconds=5))
self.case_repeater.save()
self.form_repeater = FormRepeater(domain=self.domain, url='form-repeater-url', next_check=datetime.utcnow() - timedelta(seconds=10))
self.form_repeater.save()
self.log = []
self.post_xml(xform_xml)
示例3: setUp
def setUp(self):
self.domain = "test-domain"
create_domain(self.domain)
self.repeater = FormRepeater(
domain=self.domain,
url='form-repeater-url',
version=V1,
format='new_format'
)
self.repeater.save()
示例4: domain_forwarding
def domain_forwarding(request, domain):
form_repeaters = FormRepeater.by_domain(domain)
case_repeaters = CaseRepeater.by_domain(domain)
short_form_repeaters = ShortFormRepeater.by_domain(domain)
return render(request, "domain/admin/domain_forwarding.html", {
"domain": domain,
"repeaters": (
("FormRepeater", form_repeaters),
("CaseRepeater", case_repeaters),
("ShortFormRepeater", short_form_repeaters)
),
})
示例5: IgnoreDocumentTest
class IgnoreDocumentTest(BaseRepeaterTest):
def setUp(self):
self.domain = "test-domain"
create_domain(self.domain)
self.repeater = FormRepeater(
domain=self.domain,
url='form-repeater-url',
version=V1,
format='new_format'
)
self.repeater.save()
def tearDown(self):
self.repeater.delete()
repeat_records = RepeatRecord.all()
for repeat_record in repeat_records:
repeat_record.delete()
def test_ignore_document(self):
"""
When get_payload raises IgnoreDocument, fire should call update_success
"""
@RegisterGenerator(FormRepeater, 'new_format', 'XML')
class NewFormGenerator(BasePayloadGenerator):
def get_payload(self, repeat_record, payload_doc):
raise IgnoreDocument
repeat_records = RepeatRecord.all(
domain=self.domain,
)
for repeat_record_ in repeat_records:
repeat_record_.fire()
self.assertIsNone(repeat_record_.next_check)
self.assertTrue(repeat_record_.succeeded)
示例6: test_get_list
def test_get_list(self):
self.client.login(username=self.username, password=self.password)
# Add a form repeater and check that it comes back
form_repeater = FormRepeater(domain=self.domain.name, url='http://example.com/forwarding/form')
form_repeater.save()
backend_id = form_repeater._id
response = self.client.get(self.list_endpoint)
self.assertEqual(response.status_code, 200)
api_repeaters = simplejson.loads(response.content)['objects']
self.assertEqual(len(api_repeaters), 1)
self.assertEqual(api_repeaters[0]['id'], backend_id)
self.assertEqual(api_repeaters[0]['url'], form_repeater.url)
self.assertEqual(api_repeaters[0]['domain'], form_repeater.domain)
self.assertEqual(api_repeaters[0]['type'], 'FormRepeater')
# Add a case repeater and check that both come back
case_repeater = CaseRepeater(domain=self.domain.name, url='http://example.com/forwarding/case')
case_repeater.save()
backend_id = case_repeater._id
response = self.client.get(self.list_endpoint)
self.assertEqual(response.status_code, 200)
api_repeaters = simplejson.loads(response.content)['objects']
self.assertEqual(len(api_repeaters), 2)
api_case_repeater = filter(lambda r: r['type'] == 'CaseRepeater', api_repeaters)[0]
self.assertEqual(api_case_repeater['id'], case_repeater._id)
self.assertEqual(api_case_repeater['url'], case_repeater.url)
self.assertEqual(api_case_repeater['domain'], case_repeater.domain)
form_repeater.delete()
case_repeater.delete()
示例7: test_get_list
def test_get_list(self):
self.client.login(username=self.username, password=self.password)
# Add a form repeater and check that it comes back
form_repeater = FormRepeater(domain=self.domain.name, url="http://example.com/forwarding/form")
form_repeater.save()
backend_id = form_repeater._id
response = self.client.get(self.list_endpoint)
self.assertEqual(response.status_code, 200)
api_repeaters = json.loads(response.content)["objects"]
self.assertEqual(len(api_repeaters), 1)
self.assertEqual(api_repeaters[0]["id"], backend_id)
self.assertEqual(api_repeaters[0]["url"], form_repeater.url)
self.assertEqual(api_repeaters[0]["domain"], form_repeater.domain)
self.assertEqual(api_repeaters[0]["type"], "FormRepeater")
# Add a case repeater and check that both come back
case_repeater = CaseRepeater(domain=self.domain.name, url="http://example.com/forwarding/case")
case_repeater.save()
backend_id = case_repeater._id
response = self.client.get(self.list_endpoint)
self.assertEqual(response.status_code, 200)
api_repeaters = json.loads(response.content)["objects"]
self.assertEqual(len(api_repeaters), 2)
api_case_repeater = filter(lambda r: r["type"] == "CaseRepeater", api_repeaters)[0]
self.assertEqual(api_case_repeater["id"], case_repeater._id)
self.assertEqual(api_case_repeater["url"], case_repeater.url)
self.assertEqual(api_case_repeater["domain"], case_repeater.domain)
form_repeater.delete()
case_repeater.delete()
示例8: setUp
def setUp(self):
self.client = Client()
self.domain = "test-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()
f = StringIO(xform_xml)
f.name = 'register.xml'
self.client.post(
reverse('receiver_post', args=[self.domain]), {
'xml_submission_file': f
}
)
self.log = []
示例9: drop_repeater
def drop_repeater(request, domain, repeater_id):
rep = FormRepeater.get(repeater_id)
rep.retire()
messages.success(request, "Form forwarding stopped!")
return HttpResponseRedirect(reverse("corehq.apps.domain.views.domain_forwarding", args=[domain]))
示例10: RepeaterTest
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])
#.........这里部分代码省略.........
示例11: drop_repeater
def drop_repeater(request, domain, repeater_id):
rep = FormRepeater.get(repeater_id)
rep.retire()
messages.success(request, "Form forwarding stopped!")
return HttpResponseRedirect(reverse(DomainForwardingOptionsView.urlname, args=[domain]))
示例12: RepeaterTest
class RepeaterTest(TestCase):
def setUp(self):
self.client = Client()
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)
def post_xml(self, xml):
f = StringIO(xml)
f.name = "form.xml"
self.client.post(reverse("receiver_post", args=[self.domain]), {"xml_submission_file": f})
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):
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()
for repeat_record in repeat_records:
repeat_record.fire(post_fn=self.make_post_fn([404, 404, 404]))
repeat_record.save()
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=2))
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
self.assertEqual(self.log[1][:2], (self.case_repeater.url, 200))
self.assertIn("server-modified-on", self.log[1][3])
check_xml_line_by_line(self, self.log[1][2], case_block)
# check form stuff
self.assertEqual(self.log[3][:3], (self.form_repeater.url, 200, xform_xml))
self.assertIn("received-on", self.log[3][3])
repeat_records = RepeatRecord.all(domain=self.domain, due_before=next_check_time)
for repeat_record in repeat_records:
self.assertEqual(repeat_record.succeeded, True)
self.assertEqual(repeat_record.next_check, None)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
#.........这里部分代码省略.........
示例13: RepeaterTest
class RepeaterTest(TestCase):
def setUp(self):
self.client = Client()
self.domain = "test-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)
def post_xml(self, xml):
f = StringIO(xml)
f.name = 'form.xml'
self.client.post(
reverse('receiver_post', args=[self.domain]), {
'xml_submission_file': f
}
)
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):
status_code = status_codes.next()
self.log.append((url, status_code, data))
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):
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()
for repeat_record in repeat_records:
repeat_record.fire(post_fn=self.make_post_fn([404, 404, 404]))
repeat_record.save()
for (url, status, data) 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=2))
repeat_record.fire(post_fn=self.make_post_fn([404, 200]))
repeat_record.save()
self.assertEqual(len(self.log), 4)
self.assertEqual(self.log[1], (self.form_repeater.url, 200, xform_xml))
self.assertEqual(self.log[3][:2], (self.case_repeater.url, 200))
check_xml_line_by_line(self, self.log[3][2], case_block)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=next_check_time)
for repeat_record in repeat_records:
self.assertEqual(repeat_record.succeeded, True)
self.assertEqual(repeat_record.next_check, None)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
self.assertEqual(len(repeat_records), 0)
self.post_xml(update_xform_xml)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now())
self.assertEqual(len(repeat_records), 2)
示例14: RepeaterTest
class RepeaterTest(TestCase):
def setUp(self):
self.client = Client()
self.domain = "test-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()
f = StringIO(xform_xml)
f.name = 'register.xml'
self.client.post(
reverse('receiver_post', args=[self.domain]), {
'xml_submission_file': f
}
)
self.log = []
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):
status_code = status_codes.next()
self.log.append((url, status_code, data))
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):
CommCareCase.get(case_id)
now = datetime.utcnow()
repeat_records = RepeatRecord.all(domain=self.domain, due_before=now)
self.assertEqual(len(repeat_records), 2)
self.clear_log()
for repeat_record in repeat_records:
repeat_record.fire(post_fn=self.make_post_fn([404, 404, 404]))
repeat_record.save()
for (url, status, data) in self.log:
self.assertEqual(status, 404)
self.clear_log()
in30min = now + timedelta(minutes=30)
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=in30min + timedelta(seconds=1))
self.assertEqual(len(repeat_records), 2)
for repeat_record in repeat_records:
self.assertLess(abs(in30min - repeat_record.next_check), timedelta(seconds=1))
repeat_record.fire(post_fn=self.make_post_fn([404, 200]))
repeat_record.save()
self.assertEqual(len(self.log), 4)
self.assertEqual(self.log[1], (self.form_repeater.url, 200, xform_xml))
self.assertEqual(self.log[3][:2], (self.case_repeater.url, 200))
check_xml_line_by_line(self, self.log[3][2], case_block)
repeat_records = RepeatRecord.all(domain=self.domain, due_before=in30min)
for repeat_record in repeat_records:
self.assertEqual(repeat_record.succeeded, True)
self.assertEqual(repeat_record.next_check, None)
def test_migration(self):
now = datetime.utcnow()
repeats = [
{
"url": "http://example.com/",
"doc_type": "RepeatRecord",
"next_check": now,
"last_checked": None,
"succeeded": False
}
]
xform = XFormInstance.get(instance_id)
xform.repeats = repeats
xform.save()
def always_success():
while True:
#.........这里部分代码省略.........