def _test(self, submit_app_id, expected_app_id, expected_build_id): form_id = spoof_submission( get_submit_url(self.domain, submit_app_id), '<data xmlns="http://example.com/"><question1/></data>') form = FormAccessors(self.domain).get_form(form_id) self.assertEqual(form.app_id, expected_app_id) self.assertEqual(form.build_id, expected_build_id) return form
def _test(self, submit_app_id, expected_app_id, expected_build_id): form_id = spoof_submission( get_submit_url(self.domain, submit_app_id), '<data xmlns="http://example.com/"><question1/></data>' ) form = FormAccessors(self.domain).get_form(form_id) self.assertEqual(form.app_id, expected_app_id) self.assertEqual(form.build_id, expected_build_id) return form
def _submit_form(self, f=None, domain=DOMAIN): if f is None: f = get_form() url = get_submit_url(domain) self._send_form_to_es( domain=domain, xmlns="http://www.commcarehq.org/export/test", ) return spoof_submission(url, f)
def _test(self, id, expected_app_id, expected_build_id): r = spoof_submission( '/a/{domain}/receiver/{id}/'.format(domain=self.domain, id=id), '<data xmlns="http://example.com/"><question1/></data>', hqsubmission=False, ) form_id = r['X-CommCareHQ-FormID'] form = XFormInstance.get(form_id) self.assertEqual(form.app_id, expected_app_id) self.assertEqual(form.build_id, expected_build_id)
def _test(self, id, expected_app_id, expected_build_id): r = spoof_submission( '/a/{domain}/receiver/{id}/'.format(domain=self.domain, id=id), '<data xmlns="http://example.com/"><question1/></data>', hqsubmission=False, ) form_id = r['X-CommCareHQ-FormID'] form = XFormInstance.get(form_id) self.assertEqual(form.app_id, expected_app_id) self.assertEqual(form.build_id, expected_build_id) return form
def handle_sms_form_complete(sender, session_id, form, **kwargs): from corehq.apps.smsforms.models import XFormsSession session = XFormsSession.latest_by_session_id(session_id) if session: # i don't know if app_id is the id of the overall app or the id of the specific build of the app # the thing i want to pass in is the id of the overall app resp = spoof_submission(get_submit_url(session.domain, session.app_id), form, hqsubmission=False) xform_id = resp['X-CommCareHQ-FormID'] session.end(completed=True) session.submission_id = xform_id session.save() xform = XFormInstance.get(xform_id) xform.survey_incentive = session.survey_incentive xform.save()
def post(request, domain): """expects same posts as receiver but munges the forms before passing them on""" xml = request.raw_post_data user_map = UserMap(domain) submit = True if is_user_registration(xml): submit = update_migration_users(xml, user_map) else: xml = add_user_id(xml, user_map) if submit: submit_time = request.META.get('HTTP_X_SUBMIT_TIME', None) headers = {"HTTP_X_SUBMIT_TIME": submit_time} if submit_time else {} return spoof_submission(get_submit_url(domain), xml, hqsubmission=False, headers=headers) else: return HttpResponse("user already exists")
def submit_unfinished_form(session_id, include_case_side_effects=False): session = XFormsSession.latest_by_session_id(session_id) if session is not None and session.end_time is None: # Get and clean the raw xml try: xml = get_raw_instance(session_id) except InvalidSessionIdException: session.end(completed=False) session.save() return root = XML(xml) case_tag_regex = re.compile("^(\{.*\}){0,1}case$") # Use regex in order to search regardless of namespace meta_tag_regex = re.compile("^(\{.*\}){0,1}meta$") timeEnd_tag_regex = re.compile("^(\{.*\}){0,1}timeEnd$") current_timstamp = json_format_datetime(datetime.utcnow()) for child in root: if case_tag_regex.match(child.tag) is not None: # Found the case tag case_element = child case_element.set("date_modified", current_timstamp) if not include_case_side_effects: # Remove case actions (create, update, close) child_elements = [case_action for case_action in case_element] for case_action in child_elements: case_element.remove(case_action) elif meta_tag_regex.match(child.tag) is not None: # Found the meta tag, now set the value for timeEnd for meta_child in child: if timeEnd_tag_regex.match(meta_child.tag): meta_child.text = current_timstamp cleaned_xml = tostring(root) # Submit the xml and end the session resp = spoof_submission(get_submit_url(session.domain, session.app_id), cleaned_xml, hqsubmission=False) xform_id = resp['X-CommCareHQ-FormID'] session.end(completed=False) session.submission_id = xform_id session.save() # Tag the submission as a partial submission xform = XFormInstance.get(xform_id) xform.partial_submission = True xform.survey_incentive = session.survey_incentive xform.save()
def _submit_form(f=None, domain=DOMAIN): if f is None: f = get_form() url = get_submit_url(domain) return spoof_submission(url, f)
def submit_form(f=None, domain=DOMAIN): if f is None: f = get_form() url = get_submit_url(domain) return spoof_submission(url, f, hqsubmission=False)