本文整理汇总了Python中corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL.archive_form方法的典型用法代码示例。如果您正苦于以下问题:Python FormAccessorSQL.archive_form方法的具体用法?Python FormAccessorSQL.archive_form怎么用?Python FormAccessorSQL.archive_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL
的用法示例。
在下文中一共展示了FormAccessorSQL.archive_form方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_forms_by_type
# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import archive_form [as 别名]
def test_get_forms_by_type(self):
form1 = create_form_for_test(DOMAIN)
form2 = create_form_for_test(DOMAIN)
# basic check
forms = FormAccessorSQL.get_forms_by_type(DOMAIN, 'XFormInstance', 5)
self.assertEqual(2, len(forms))
self.assertEqual({form1.form_id, form2.form_id}, {f.form_id for f in forms})
# check reverse ordering
forms = FormAccessorSQL.get_forms_by_type(DOMAIN, 'XFormInstance', 5, recent_first=True)
self.assertEqual(2, len(forms))
self.assertEqual([form2.form_id, form1.form_id], [f.form_id for f in forms])
# check limit
forms = FormAccessorSQL.get_forms_by_type(DOMAIN, 'XFormInstance', 1)
self.assertEqual(1, len(forms))
self.assertEqual(form1.form_id, forms[0].form_id)
# change state of form1
FormAccessorSQL.archive_form(form1, 'user1')
# check filtering by state
forms = FormAccessorSQL.get_forms_by_type(DOMAIN, 'XFormArchived', 2)
self.assertEqual(1, len(forms))
self.assertEqual(form1.form_id, forms[0].form_id)
forms = FormAccessorSQL.get_forms_by_type(DOMAIN, 'XFormInstance', 2)
self.assertEqual(1, len(forms))
self.assertEqual(form2.form_id, forms[0].form_id)
示例2: test_archive_unarchive_form
# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import archive_form [as 别名]
def test_archive_unarchive_form(self):
case_id = uuid.uuid4().hex
form = create_form_for_test(DOMAIN, case_id=case_id)
self.assertEqual(XFormInstanceSQL.NORMAL, form.state)
self.assertEqual(0, len(form.history))
transactions = CaseAccessorSQL.get_transactions(case_id)
self.assertEqual(1, len(transactions))
self.assertFalse(transactions[0].revoked)
FormAccessorSQL.archive_form(form, 'user1')
form = FormAccessorSQL.get_form(form.form_id)
self.assertEqual(XFormInstanceSQL.ARCHIVED, form.state)
operations = form.history
self.assertEqual(1, len(operations))
self.assertEqual(form.form_id, operations[0].form_id)
self.assertEqual('user1', operations[0].user_id)
transactions = CaseAccessorSQL.get_transactions(case_id)
self.assertEqual(1, len(transactions))
self.assertTrue(transactions[0].revoked)
FormAccessorSQL.unarchive_form(form, 'user2')
form = FormAccessorSQL.get_form(form.form_id)
self.assertEqual(XFormInstanceSQL.NORMAL, form.state)
operations = form.history
self.assertEqual(2, len(operations))
self.assertEqual(form.form_id, operations[1].form_id)
self.assertEqual('user2', operations[1].user_id)
transactions = CaseAccessorSQL.get_transactions(case_id)
self.assertEqual(1, len(transactions))
self.assertFalse(transactions[0].revoked)
示例3: test_get_form_operations
# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import archive_form [as 别名]
def test_get_form_operations(self):
form = create_form_for_test(DOMAIN)
operations = FormAccessorSQL.get_form_operations('missing_form')
self.assertEqual([], operations)
operations = FormAccessorSQL.get_form_operations(form.form_id)
self.assertEqual([], operations)
# don't call form.archive to avoid sending the signals
FormAccessorSQL.archive_form(form, user_id='user1')
FormAccessorSQL.unarchive_form(form, user_id='user2')
operations = FormAccessorSQL.get_form_operations(form.form_id)
self.assertEqual(2, len(operations))
self.assertEqual('user1', operations[0].user_id)
self.assertEqual(XFormOperationSQL.ARCHIVE, operations[0].operation)
self.assertIsNotNone(operations[0].date)
self.assertEqual('user2', operations[1].user_id)
self.assertEqual(XFormOperationSQL.UNARCHIVE, operations[1].operation)
self.assertIsNotNone(operations[1].date)
self.assertGreater(operations[1].date, operations[0].date)
示例4: test_get_form_ids_in_domain
# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import archive_form [as 别名]
def test_get_form_ids_in_domain(self):
form1 = create_form_for_test(DOMAIN)
form2 = create_form_for_test(DOMAIN)
create_form_for_test('bad-domain')
# basic check
form_ids = FormAccessorSQL.get_form_ids_in_domain_by_type(DOMAIN, 'XFormInstance')
self.assertEqual(2, len(form_ids))
self.assertEqual({form1.form_id, form2.form_id}, set(form_ids))
# change state of form1
FormAccessorSQL.archive_form(form1, 'user1')
# check filtering by state
form_ids = FormAccessorSQL.get_form_ids_in_domain_by_type(DOMAIN, 'XFormArchived')
self.assertEqual(1, len(form_ids))
self.assertEqual(form1.form_id, form_ids[0])
form_ids = FormAccessorSQL.get_form_ids_in_domain_by_type(DOMAIN, 'XFormInstance')
self.assertEqual(1, len(form_ids))
self.assertEqual(form2.form_id, form_ids[0])
示例5: archive
# 需要导入模块: from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL [as 别名]
# 或者: from corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL import archive_form [as 别名]
def archive(self, user_id=None):
if self.is_archived:
return
from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL
FormAccessorSQL.archive_form(self, user_id=user_id)
xform_archived.send(sender="form_processor", xform=self)