def _get_open_rosa_response(self,
                                instance,
                                success_message=None,
                                error_message=None,
                                error_nature=None):
        if self.is_openrosa_version3:
            instance_ok = instance.is_normal or instance.is_duplicate
            has_error = error_message or error_nature
            if instance_ok and not has_error:
                response = openrosa_response.get_openarosa_success_response(
                    message=success_message)
            else:
                error_message = error_message or instance.problem
                response = self.get_v3_error_response(error_message,
                                                      error_nature)
        else:
            if instance.is_normal:
                response = openrosa_response.get_openarosa_success_response()
            else:
                response = self.get_v2_submit_error_response(instance)

        # this hack is required for ODK
        response["Location"] = self.location

        # this is a magic thing that we add
        response['X-CommCareHQ-FormID'] = instance.form_id
        return response
Exemple #2
0
    def test_submit_mode(self):
        # test 'submit_mode=demo' request param

        accepted_response = openrosa_response.get_openarosa_success_response(
        ).content
        ignored_response = openrosa_response.SUBMISSION_IGNORED_RESPONSE.content

        client = django_digest.test.Client()
        client.set_authorization(self.user.username, '1234', method='Digest')
        # submissions with 'submit_mode=demo' param by real users should be ignored
        self._test_post(file_path=self.simple_form,
                        client=client,
                        authtype='digest',
                        submit_mode=DEMO_SUBMIT_MODE,
                        expected_response=ignored_response)

        # submissions with 'submit_mode=demo' param by real users should be ignored
        #   even if no authorization headers are supplied
        self._test_post(file_path=self.simple_form,
                        client=client,
                        authtype='noauth',
                        submit_mode=DEMO_SUBMIT_MODE,
                        expected_response=ignored_response)

        # submissions by 'demo_user' should not be ignored even with 'submit_mode=demo' param
        self._test_post(file_path=self.form_with_demo_case,
                        authtype='noauth',
                        submit_mode=DEMO_SUBMIT_MODE,
                        expected_response=accepted_response)
Exemple #3
0
    def test_submit_mode(self):
        # test 'submit_mode=demo' request param

        accepted_response = openrosa_response.get_openarosa_success_response().content
        ignored_response = openrosa_response.SUBMISSION_IGNORED_RESPONSE.content

        client = django_digest.test.Client()
        client.set_authorization(self.user.username, '1234',
                                 method='Digest')
        # submissions with 'submit_mode=demo' param by real users should be ignored
        self._test_post(
            file_path=self.simple_form,
            client=client,
            authtype='digest',
            submit_mode=DEMO_SUBMIT_MODE,
            expected_response=ignored_response
        )

        # submissions with 'submit_mode=demo' param by real users should be ignored
        #   even if no authorization headers are supplied
        self._test_post(
            file_path=self.simple_form,
            client=client,
            authtype='noauth',
            submit_mode=DEMO_SUBMIT_MODE,
            expected_response=ignored_response
        )

        # submissions by 'demo_user' should not be ignored even with 'submit_mode=demo' param
        self._test_post(
            file_path=self.form_with_demo_case,
            authtype='noauth',
            submit_mode=DEMO_SUBMIT_MODE,
            expected_response=accepted_response
        )
    def _get_open_rosa_response(self, instance, success_message=None, error_message=None, error_nature=None):
        if self.is_openrosa_version3:
            instance_ok = instance.is_normal or instance.is_duplicate
            has_error = error_message or error_nature
            if instance_ok and not has_error:
                response = openrosa_response.get_openarosa_success_response(message=success_message)
            else:
                error_message = error_message or instance.problem
                response = self.get_retry_response(error_message, error_nature)
        else:
            if instance.is_normal:
                response = openrosa_response.get_openarosa_success_response()
            else:
                response = self.get_v2_submit_error_response(instance)

        # this hack is required for ODK
        response["Location"] = self.location

        # this is a magic thing that we add
        response['X-CommCareHQ-FormID'] = instance.form_id
        return response