本文整理汇总了Python中corehq.apps.receiverwrapper.models.FormRepeater.delete方法的典型用法代码示例。如果您正苦于以下问题:Python FormRepeater.delete方法的具体用法?Python FormRepeater.delete怎么用?Python FormRepeater.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.receiverwrapper.models.FormRepeater
的用法示例。
在下文中一共展示了FormRepeater.delete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: IgnoreDocumentTest
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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)
示例2: test_get_list
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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()
示例3: test_get_list
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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()
示例4: RepeaterTest
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [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])
#.........这里部分代码省略.........
示例5: RepeaterTest
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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())
#.........这里部分代码省略.........
示例6: RepeaterTest
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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)
示例7: RepeaterTest
# 需要导入模块: from corehq.apps.receiverwrapper.models import FormRepeater [as 别名]
# 或者: from corehq.apps.receiverwrapper.models.FormRepeater import delete [as 别名]
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:
#.........这里部分代码省略.........