本文整理汇总了Python中corehq.apps.smsforms.models.XFormsSession.get_db方法的典型用法代码示例。如果您正苦于以下问题:Python XFormsSession.get_db方法的具体用法?Python XFormsSession.get_db怎么用?Python XFormsSession.get_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.smsforms.models.XFormsSession
的用法示例。
在下文中一共展示了XFormsSession.get_db方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sync_from_creation
# 需要导入模块: from corehq.apps.smsforms.models import XFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.XFormsSession import get_db [as 别名]
def test_sync_from_creation(self):
properties = _arbitrary_session_properties()
couch_session = XFormsSession(**properties)
couch_session.save()
sql_session = SQLXFormsSession.objects.get(couch_id=couch_session._id)
for prop, value in properties.items():
self.assertEqual(getattr(sql_session, prop), value)
# make sure we didn't do any excess saves
self.assertTrue(XFormsSession.get_db().get_rev(couch_session._id).startswith('1-'))
示例2: handle
# 需要导入模块: from corehq.apps.smsforms.models import XFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.XFormsSession import get_db [as 别名]
def handle(self, *args, **options):
db = XFormsSession.get_db()
session_ids = [row['id'] for row in db.view("smsforms/sessions_by_touchforms_id")]
errors = []
for session_doc in iter_docs(db, session_ids):
try:
# Handle the old touchforms session id convention where it was
# always an int
session_id = session_doc.get("session_id", None)
if isinstance(session_id, int):
session_doc["session_id"] = str(session_id)
couch_session = XFormsSession.wrap(session_doc)
sync_sql_session_from_couch_session(couch_session)
except Exception as e:
logging.exception('problem migrating session {}: {}'.format(session_doc['_id'], e))
errors.append(session_doc['_id'])
print 'migrated {} couch sessions. there are now {} in sql'.format(
len(session_ids) - len(errors), SQLXFormsSession.objects.count()
)
if errors:
print 'errors: {}'.format(', '.join(errors))
示例3: test_all_inbound
# 需要导入模块: from corehq.apps.smsforms.models import XFormsSession [as 别名]
# 或者: from corehq.apps.smsforms.models.XFormsSession import get_db [as 别名]
#.........这里部分代码省略.........
session = self.get_open_session(self.user1)
self.assertIsNone(session)
self.assertNoNewSubmission(form)
# One keyword overrides another
incoming("999123", "reg", "TEST")
sms1 = self.assertLastOutboundSMSEquals(self.user1, "Enter Participant ID")
incoming("999123", "mod pid1237", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "Enter Study Arm 1:a, 2:b.")
self.assertNoNewSubmission(form)
incoming("999123", "reg", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "%s Enter Study Arm 1:a, 2:b." % get_message(MSG_INVALID_CHOICE))
incoming("999123", "a", "TEST")
form = self.get_last_form_submission()
self.assertFormQuestionEquals(form, "arm", "arm_a")
case = self.get_case("pid1237")
self.assertIsNotNone(case)
self.assertCasePropertyEquals(case, "arm", "arm_a")
# Test initator filters
case = self.get_case("pid1237")
case.set_case_property("contact_phone_number", "999124")
case.set_case_property("contact_phone_number_is_verified", "1")
case.save()
incoming("999123", "for_user", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "This message is for users")
incoming("999123", "for_case", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "Default SMS Response")
incoming("999124", "for_case", "TEST")
self.assertLastOutboundSMSEquals(case, "This message is for cases")
incoming("999124", "for_user", "TEST")
self.assertLastOutboundSMSEquals(case, "Default SMS Response")
# Test form over sms for case
incoming("999124", "mod", "TEST")
self.assertLastOutboundSMSEquals(case, "Enter Study Arm 1:a, 2:b.")
incoming("999123", "mod pid1237", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "Enter Study Arm 1:a, 2:b.")
incoming("999124", "b", "TEST")
form = self.get_last_form_submission()
self.assertFormQuestionEquals(form, "arm", "arm_b")
case = self.get_case("pid1237")
self.assertCasePropertyEquals(case, "arm", "arm_b")
incoming("999123", "a", "TEST")
form = self.get_last_form_submission()
self.assertFormQuestionEquals(form, "arm", "arm_a")
case = self.get_case("pid1237")
self.assertCasePropertyEquals(case, "arm", "arm_a")
# Test structured sms for case
incoming("999124", "mod_ss 2", "TEST")
self.assertLastOutboundSMSEquals(case, "Thank you for your modification submission.")
form = self.get_last_form_submission()
self.assertFormQuestionEquals(form, "arm", "arm_b")
case = self.get_case("pid1237")
self.assertCasePropertyEquals(case, "arm", "arm_b")
# Test Auth
incoming("999122", "mod pid1237", "TEST")
self.assertLastOutboundSMSEquals(self.user2, get_message(MSG_CASE_NOT_FOUND))
# Test notifying others
incoming("999124", "for_owner", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "This message is for the case owner")
incoming("999124", "for_group", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "This message is for the group")
self.assertLastOutboundSMSEquals(self.user2, "This message is for the group")
case = self.get_case("pid1237")
case.owner_id = self.group1._id
case.save()
incoming("999124", "for_owner", "TEST")
self.assertLastOutboundSMSEquals(self.user1, "This message is for the case owner")
self.assertLastOutboundSMSEquals(self.user2, "This message is for the case owner")
# Test case sharing auth
incoming("999122", "mod pid1237", "TEST")
self.assertLastOutboundSMSEquals(self.user2, "Enter Study Arm 1:a, 2:b.")
incoming("999122", "1", "TEST")
form = self.get_last_form_submission()
self.assertFormQuestionEquals(form, "arm", "arm_a")
case = self.get_case("pid1237")
self.assertCasePropertyEquals(case, "arm", "arm_a")
# Test closing open sessions on an sms reply
incoming("999122", "reg", "TEST")
self.assertLastOutboundSMSEquals(self.user2, "Enter Participant ID")
incoming("999122", "for_user", "TEST")
self.assertLastOutboundSMSEquals(self.user2, "This message is for users")
incoming("999122", "null", "TEST")
self.assertLastOutboundSMSEquals(self.user2, "Default SMS Response")
# make sure the same number of sessions were made
couch_number = XFormsSession.get_db().view('smsforms/sessions_by_touchforms_id', limit=0).total_rows
sql_number = SQLXFormsSession.objects.count()
self.assertEqual(couch_number, sql_number)