def test_registering_helper_works(self):
        from types import GeneratorType

        from sijax.plugin.upload import func_name_by_form_id

        class CustomResponse(UploadResponse): pass

        def process_request(inst):
            self.assertTrue(inst.is_sijax_request)
            response = inst.process_request()
            self.assertTrue(isinstance(response, GeneratorType))
            # something needs to "move the generator forward" if we want
            # to proceed in the call chain
            for string in response:
                pass

        call_history = []

        def invalid_call(obj_response, callback):
            self.fail("Invalid call handler triggered!")

        inst = Sijax()
        cls = inst.__class__
        inst.register_event(cls.EVENT_INVALID_CALL, invalid_call)

        def my_callback(obj_response, files, form_values):
            self.assertTrue(isinstance(obj_response, UploadResponse))
            self.assertTrue(isinstance(obj_response, StreamingIframeResponse))
            call_history.append("my_callback")
            call_history.append(obj_response.form_id)
            call_history.append(type(obj_response).__name__)
            call_history.append(files["file"]) # reaching into the file object

            # ensure that from all the post data, only the valid (non-system)
            # stuff made it through
            self.assertEqual({"form_key": "value", "form_key2": 15}, form_values)

        def my_callback2(obj_response, custom_arg1, custom_arg2, form_values):
            self.assertTrue(isinstance(obj_response, UploadResponse))
            self.assertTrue(isinstance(obj_response, StreamingIframeResponse))
            call_history.append("custom_callback")
            call_history.append(obj_response.form_id)
            call_history.append(type(obj_response).__name__)
            call_history.append(custom_arg1)
            call_history.append(custom_arg2)

            # ensure that from all the post data, only the valid (non-system)
            # stuff made it through
            self.assertEqual({"form_key": "value", "form_key2": 15}, form_values)

        form_id = "my_form"
        # the developer usually doesn't need to know the public system assigned
        # name of the callback function.. we'll need it though to fake the request
        public_callback_name = func_name_by_form_id(form_id)
        request_args_json = '["%s"]' % form_id
        post = {}
        post[cls.PARAM_REQUEST] = public_callback_name
        post[cls.PARAM_ARGS] = request_args_json
        post["form_key"] = "value"
        post["form_key2"] = 15
        inst.set_data(post)

        files = {"file": "object", "passed": "here"}
        register_upload_callback(inst, form_id, my_callback, args_extra=(files,))
        process_request(inst)


        # let's see if we can override the default args and the response
        # class during callback registration
        params_custom = {cls.PARAM_RESPONSE_CLASS: CustomResponse}
        register_upload_callback(inst, form_id, my_callback2, args_extra=("custom1", "custom2"), **params_custom)
        process_request(inst)

        call_history_expected = [
            "my_callback", form_id, "UploadResponse", "object",
            "custom_callback", form_id, "CustomResponse", "custom1", "custom2"
        ]
        self.assertEqual(call_history_expected, call_history)
dataset/ETHPy150Open spantaleev/sijax-python/tests/sijax_tests.py/SijaxUploadTestCase.test_registering_helper_works/original