def test_05_raising_exception_during_qweb_response_rendering(self):
        """
        Test that an exception is raised during an Odoo's response processing.

        This test use a double 'mocking' strategy:
            - Python's mock library, to mock a method and make it returning
              the exception
            - Odoo's _patch_method(), to swap an Odoo's model's method
              with another custom-defined one
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        self.req.session.db = DB_NAME  # put DB name into request session data
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        self.assertIsNotNone(
            request.session.db, 'Database not in the request object. '
            'Test aborted.')

        # Extract and hack part of the Odoo's Root.dispatch() method,
        # and use it to generate a valid Odoo's Response object.
        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result
    def test_04_sending_odoo_qweb_template_response(self):
        """
        Test that an Odoo's response is correctly processed
        and has our 'cookies time fix'.

        Send a 'qweb template' response via a Odoo's Response instance.
        Make sure that the Response.flatten() method is called
        and the response has our 'cookies time fix'.
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        root.setup_db(self.req)
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result
예제 #3
0
    def test_05_raising_exception_during_qweb_response_rendering(self):
        """
        Test that an exception is raised during an Odoo's response processing.

        This test use a double 'mocking' strategy:
            - Python's mock library, to mock a method and make it returning
              the exception
            - Odoo's _patch_method(), to swap an Odoo's model's method
              with another custom-defined one
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        self.req.session.db = DB_NAME  # put DB name into request session data
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        self.assertIsNotNone(request.session.db,
                             'Database not in the request object. '
                             'Test aborted.')

        # Extract and hack part of the Odoo's Root.dispatch() method,
        # and use it to generate a valid Odoo's Response object.
        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result
예제 #4
0
    def test_04_sending_odoo_qweb_template_response(self):
        """
        Test that an Odoo's response is correctly processed
        and has our 'cookies time fix'.

        Send a 'qweb template' response via a Odoo's Response instance.
        Make sure that the Response.flatten() method is called
        and the response has our 'cookies time fix'.
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        root.setup_db(self.req)
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result
 def test_03_sending_string_response(self):
     """
     Sending a base string as a response and expecting it to be converted
     to a response with cookie set to cookie fix time.
     """
     root = Root()
     self.req.app = root
     explicit_session = root.setup_session(self.req)
     root.setup_db(self.req)
     root.setup_lang(self.req)
     request = root.get_request(self.req)
     result = 'This is an example basestring response'
     response = root.get_response(request, result, explicit_session)
     cookie = [h for h in response.headers if h[0] == 'Set-Cookie'][0]
     cookies = [l for l in cookie[1].split('; ')]
     cookie_data = [kv.split('=') for kv in cookies]
     cookie_age = [int(c[1]) for c in cookie_data if c[0] == 'Max-Age'][0]
     err = 'Our cookie fix is not converting basestring as expected'
     self.assertEqual(cookie_age, 3600 * 12, err)
예제 #6
0
 def test_03_sending_string_response(self):
     """
     Sending a base string as a response and expecting it to be converted
     to a response with cookie set to cookie fix time.
     """
     root = Root()
     self.req.app = root
     explicit_session = root.setup_session(self.req)
     root.setup_db(self.req)
     root.setup_lang(self.req)
     request = root.get_request(self.req)
     result = 'This is an example basestring response'
     response = root.get_response(request, result, explicit_session)
     cookie = [h for h in response.headers if h[0] == 'Set-Cookie'][0]
     cookies = [l for l in cookie[1].split('; ')]
     cookie_data = [kv.split('=') for kv in cookies]
     cookie_age = [int(c[1]) for c in cookie_data if c[0] == 'Max-Age'][0]
     err = 'Our cookie fix is not converting basestring as expected'
     self.assertEqual(cookie_age, 3600*12, err)
    def test_01_nh_cookie_fix(self):
        """Using an instance of the app with the cookie fix applied
        and get a response using the usual database way of working.
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        root.setup_db(self.req)
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result
예제 #8
0
    def test_01_nh_cookie_fix(self):
        """Using an instance of the app with the cookie fix applied
        and get a response using the usual database way of working.
        """
        root = Root()
        self.req.app = root
        explicit_session = root.setup_session(self.req)
        root.setup_db(self.req)
        root.setup_lang(self.req)
        request = root.get_request(self.req)

        def _dispatch_nodb():
            try:
                func, arguments = root.nodb_routing_map.bind_to_environ(
                    request.httprequest.environ).match()
            except werkzeug.exceptions.HTTPException, e:
                return request._handle_exception(e)
            request.set_handler(func, arguments, "none")
            result = request.dispatch()
            return result