示例#1
0
 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
示例#2
0
 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
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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
示例#7
0
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()
示例#8
0
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")
示例#9
0
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()
示例#10
0
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")
示例#11
0
def _submit_form(f=None, domain=DOMAIN):
    if f is None:
        f = get_form()
    url = get_submit_url(domain)
    return spoof_submission(url, f)
示例#12
0
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)