本文整理汇总了Python中corehq.form_processor.backends.sql.dbaccessors.FormAccessorSQL类的典型用法代码示例。如果您正苦于以下问题:Python FormAccessorSQL类的具体用法?Python FormAccessorSQL怎么用?Python FormAccessorSQL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormAccessorSQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_forms_received_since
def test_get_forms_received_since(self):
# since this test depends on the global form list just wipe everything
FormProcessorTestUtils.delete_all_sql_forms()
form1 = create_form_for_test(DOMAIN)
form2 = create_form_for_test(DOMAIN)
middle = datetime.utcnow()
time.sleep(.01)
form3 = create_form_for_test(DOMAIN)
form4 = create_form_for_test(DOMAIN)
time.sleep(.01)
end = datetime.utcnow()
forms_back = list(FormAccessorSQL.get_all_forms_received_since())
self.assertEqual(4, len(forms_back))
self.assertEqual(set(form.form_id for form in forms_back),
set([form1.form_id, form2.form_id, form3.form_id, form4.form_id]))
forms_back = list(FormAccessorSQL.get_all_forms_received_since(middle))
self.assertEqual(2, len(forms_back))
self.assertEqual(set(form.form_id for form in forms_back),
set([form3.form_id, form4.form_id]))
self.assertEqual(0, len(list(FormAccessorSQL.get_all_forms_received_since(end))))
self.assertEqual(1, len(list(FormAccessorSQL.get_forms_received_since(limit=1))))
示例2: _validate_deprecation
def _validate_deprecation(self, existing_form, new_form):
saved_new_form = FormAccessorSQL.get_form(new_form.form_id)
deprecated_form = FormAccessorSQL.get_form(existing_form.form_id)
self.assertEqual(deprecated_form.form_id, saved_new_form.deprecated_form_id)
self.assertTrue(deprecated_form.is_deprecated)
self.assertNotEqual(saved_new_form.form_id, deprecated_form.form_id)
self.assertEqual(saved_new_form.form_id, deprecated_form.orig_id)
示例3: test_save_form_deprecated
def test_save_form_deprecated(self):
existing_form, new_form = _simulate_form_edit()
FormAccessorSQL.update_form(existing_form, publish_changes=False)
FormAccessorSQL.save_new_form(new_form)
self._validate_deprecation(existing_form, new_form)
示例4: test_form_with_id_exists
def test_form_with_id_exists(self):
form = create_form_for_test(DOMAIN)
self.assertFalse(FormAccessorSQL.form_exists('not a form'))
self.assertFalse(FormAccessorSQL.form_exists(form.form_id, 'wrong domain'))
self.assertTrue(FormAccessorSQL.form_exists(form.form_id))
self.assertTrue(FormAccessorSQL.form_exists(form.form_id, DOMAIN))
示例5: test_save_new_form
def test_save_new_form(self):
unsaved_form = create_form_for_test(DOMAIN, save=False)
FormAccessorSQL.save_new_form(unsaved_form)
self.assertTrue(unsaved_form.is_saved())
attachments = FormAccessorSQL.get_attachments(unsaved_form.form_id)
self.assertEqual(1, len(attachments))
示例6: unarchive
def unarchive(self, user_id=None):
if not self.is_archived:
return
from corehq.form_processor.backends.sql.dbaccessors import FormAccessorSQL
FormAccessorSQL.unarchive_form(self, user_id=user_id)
xform_unarchived.send(sender="form_processor", xform=self)
示例7: test_hard_delete_forms_and_attachments
def test_hard_delete_forms_and_attachments(self):
forms = [create_form_for_test(DOMAIN) for i in range(3)]
form_ids = sorted(form.form_id for form in forms)
forms = FormAccessorSQL.get_forms(form_ids)
self.assertEqual(3, len(forms))
other_form = create_form_for_test('other_domain')
self.addCleanup(lambda: FormAccessorSQL.hard_delete_forms('other_domain', [other_form.form_id]))
attachments = sorted(
get_blob_db().metadb.get_for_parents(form_ids),
key=lambda meta: meta.parent_id
)
self.assertEqual(3, len(attachments))
deleted = FormAccessorSQL.hard_delete_forms(DOMAIN, form_ids[1:] + [other_form.form_id])
self.assertEqual(2, deleted)
forms = FormAccessorSQL.get_forms(form_ids)
self.assertEqual(1, len(forms))
self.assertEqual(form_ids[0], forms[0].form_id)
for attachment in attachments[1:]:
with self.assertRaises(BlobNotFound):
attachment.open()
with attachments[0].open() as content:
self.assertIsNotNone(content.read())
other_form = FormAccessorSQL.get_form(other_form.form_id)
self.assertIsNotNone(other_form.get_xml())
示例8: test_save_form_deprecated
def test_save_form_deprecated(self):
existing_form, new_form = _simulate_form_edit()
FormAccessorSQL.save_deprecated_form(existing_form)
FormAccessorSQL.save_new_form(new_form)
self._validate_deprecation(existing_form, new_form)
示例9: hard_delete_case_and_forms
def hard_delete_case_and_forms(cls, domain, case, xforms):
form_ids = [xform.form_id for xform in xforms]
FormAccessorSQL.hard_delete_forms(domain, form_ids)
CaseAccessorSQL.hard_delete_cases(domain, [case.case_id])
for form in xforms:
form.state |= XFormInstanceSQL.DELETED
publish_form_saved(form)
case.deleted = True
publish_case_saved(case)
示例10: print_stats
def print_stats(self, domain, short=True, diffs_only=False):
status = get_couch_sql_migration_status(domain)
print("Couch to SQL migration status for {}: {}".format(domain, status))
db = get_diff_db(domain)
try:
diff_stats = db.get_diff_stats()
except OperationalError:
diff_stats = {}
has_diffs = False
for doc_type in doc_types():
form_ids_in_couch = set(get_form_ids_by_type(domain, doc_type))
form_ids_in_sql = set(FormAccessorSQL.get_form_ids_in_domain_by_type(domain, doc_type))
diff_count, num_docs_with_diffs = diff_stats.pop(doc_type, (0, 0))
has_diffs |= self._print_status(
doc_type, form_ids_in_couch, form_ids_in_sql, diff_count, num_docs_with_diffs, short, diffs_only
)
form_ids_in_couch = set(get_doc_ids_in_domain_by_type(
domain, "XFormInstance-Deleted", XFormInstance.get_db())
)
form_ids_in_sql = set(FormAccessorSQL.get_deleted_form_ids_in_domain(domain))
diff_count, num_docs_with_diffs = diff_stats.pop("XFormInstance-Deleted", (0, 0))
has_diffs |= self._print_status(
"XFormInstance-Deleted", form_ids_in_couch, form_ids_in_sql,
diff_count, num_docs_with_diffs, short, diffs_only
)
case_ids_in_couch = set(get_case_ids_in_domain(domain))
case_ids_in_sql = set(CaseAccessorSQL.get_case_ids_in_domain(domain))
diff_count, num_docs_with_diffs = diff_stats.pop("CommCareCase", (0, 0))
has_diffs |= self._print_status(
'CommCareCase', case_ids_in_couch, case_ids_in_sql, diff_count, num_docs_with_diffs, short, diffs_only
)
case_ids_in_couch = set(get_doc_ids_in_domain_by_type(
domain, "CommCareCase-Deleted", XFormInstance.get_db())
)
case_ids_in_sql = set(CaseAccessorSQL.get_deleted_case_ids_in_domain(domain))
diff_count, num_docs_with_diffs = diff_stats.pop("CommCareCase-Deleted", (0, 0))
has_diffs |= self._print_status(
'CommCareCase-Deleted', case_ids_in_couch, case_ids_in_sql,
diff_count, num_docs_with_diffs, short, diffs_only
)
if diff_stats:
for key, counts in diff_stats.items():
diff_count, num_docs_with_diffs = counts
has_diffs |= self._print_status(
key, set(), set(), diff_count, num_docs_with_diffs, short, diffs_only
)
if diffs_only and not has_diffs:
print(shell_green("No differences found between old and new docs!"))
return has_diffs
示例11: _simulate_form_edit
def _simulate_form_edit():
existing_form = create_form_for_test(DOMAIN, save=False)
FormAccessorSQL.save_new_form(existing_form)
existing_form = FormAccessorSQL.get_form(existing_form.form_id)
new_form = create_form_for_test(DOMAIN, save=False)
new_form.form_id = existing_form.form_id
existing_form, new_form = apply_deprecation(existing_form, new_form)
assert existing_form.form_id != new_form.form_id
return existing_form, new_form
示例12: test_hard_delete_forms
def test_hard_delete_forms(self):
forms = [create_form_for_test(DOMAIN) for i in range(3)]
form_ids = [form.form_id for form in forms]
other_form = create_form_for_test('other_domain')
self.addCleanup(lambda: FormAccessorSQL.hard_delete_forms('other_domain', [other_form.form_id]))
forms = FormAccessorSQL.get_forms(form_ids)
self.assertEqual(3, len(forms))
deleted = FormAccessorSQL.hard_delete_forms(DOMAIN, form_ids[1:] + [other_form.form_id])
self.assertEqual(2, deleted)
forms = FormAccessorSQL.get_forms(form_ids)
self.assertEqual(1, len(forms))
self.assertEqual(form_ids[0], forms[0].form_id)
示例13: save_processed_models
def save_processed_models(cls, processed_forms, cases=None, stock_updates=None):
with transaction.atomic():
logging.debug('Beginning atomic commit\n')
# Save deprecated form first to avoid ID conflicts
if processed_forms.deprecated:
FormAccessorSQL.save_deprecated_form(processed_forms.deprecated)
FormAccessorSQL.save_new_form(processed_forms.submitted)
if cases:
for case in cases:
CaseAccessorSQL.save_case(case)
for stock_update in stock_updates or []:
stock_update.commit()
cls._publish_changes(processed_forms, cases)
示例14: test_get_attachment_by_name
def test_get_attachment_by_name(self):
form = create_form_for_test(DOMAIN)
form_xml = get_simple_form_xml(form.form_id)
with self.assertRaises(AttachmentNotFound):
FormAccessorSQL.get_attachment_by_name(form.form_id, 'not_a_form.xml')
with self.assertNumQueries(1, using=db_for_read_write(XFormAttachmentSQL)):
attachment_meta = FormAccessorSQL.get_attachment_by_name(form.form_id, 'form.xml')
self.assertEqual(form.form_id, attachment_meta.form_id)
self.assertEqual('form.xml', attachment_meta.name)
self.assertEqual('text/xml', attachment_meta.content_type)
self.assertEqual(form_xml, attachment_meta.read_content())
示例15: test_save_form_db_error
def test_save_form_db_error(self):
form = create_form_for_test(DOMAIN)
dup_form = create_form_for_test(DOMAIN, save=False)
dup_form.form_id = form.form_id
try:
FormAccessorSQL.save_new_form(dup_form)
except Exception:
dup_form.form_id = uuid.uuid4().hex
FormAccessorSQL.save_new_form(dup_form)
else:
self.fail("saving dup form didn't raise an exception")
attachments = FormAccessorSQL.get_attachments(dup_form.form_id)
self.assertEqual(1, len(attachments))