def test_routing_by_url(self):
     test_handler = '<xml></xml>'
     routes = {'test.ru': {'/handler': test_handler}}
     expecting_handler = EmptyEnvironment().expect(**routes)
     self.assertRaises(NotImplementedError, expecting_handler.route_request,
                       HTTPRequest('http://test.ru/404'))
     self.assertEquals(
         expecting_handler.route_request(
             HTTPRequest('http://test.ru/handler')).body, test_handler)
 def test_routing_by_url(self):
     test_handler = '<xml></xml>'
     routes = {
         'test.ru': {
             '/handler': test_handler
         }
     }
     expecting_handler = EmptyEnvironment().expect(**routes)
     self.assertRaises(NotImplementedError, expecting_handler.route_request, HTTPRequest('http://test.ru/404'))
     self.assertEquals(expecting_handler.route_request(HTTPRequest('http://test.ru/handler')).body, test_handler)
    def test_call_function(self):
        result = EmptyEnvironment().expect(
            serviceHost={
                '/vacancy/1234': (200, '<b><a>1</a></b>'),
                '/employer/1234': '<b><a>2</a></b>'
            }
        ).call_function(_function_under_test)

        self.assertEqual(result.get_xml_response().findtext('result'), '3')
        self.assertEqual(result.get_status(), 400)
        self.assertEqual(result.get_headers().get('X-Foo'), 'Bar')
        self.assertEqual(
            result.get_text_response(),
            '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<doc frontik="true"><result>3</result></doc>'
        )
Example #4
0
    def test_config(self):
        class CheckConfigHandler(PageHandler):
            def get_page(self):
                assert self.config.config_param

        EmptyEnvironment().configure(
            config_param=True).call_get(CheckConfigHandler)
Example #5
0
    def test_exception(self):
        def _test_function(handler):
            def _inner():
                raise HTTPError(500, 'fail')
            _inner()

        try:
            EmptyEnvironment().call_function(_test_function)
        except Exception as e:
            self.assertEqual(e.status_code, 500)
            self.assertEqual(e.log_message, 'fail')

            tb = ''.join(traceback.format_tb(sys.exc_traceback))
            self.assertIn('_inner()', tb)
Example #6
0
    def test_exception(self):
        class ExceptionHandler(PageHandler):
            def get_page(self):
                def _inner():
                    raise HTTPError(500, 'fail')

                _inner()

        try:
            EmptyEnvironment().call_get(ExceptionHandler,
                                        raise_exceptions=True)
        except HTTPError as e:
            self.assertEqual(e.status_code, 500)
            self.assertEqual(e.log_message, 'fail')

            tb = ''.join(traceback.format_tb(sys.exc_traceback))
            self.assertIn('_inner()', tb)
        else:
            self.fail('HTTPError must be raised')
    def test_call_function(self):
        result = EmptyEnvironment().expect(
            serviceHost={
                '/vacancy/1234': (200, '<b><a>1</a></b>'),
                '/employer/1234': '<b><a>2</a></b>'
            }).call_function(_function_under_test)

        self.assertEqual(result.get_xml_response().findtext('result'), '3')
        self.assertEqual(result.get_status(), 400)
        self.assertEqual(result.get_headers().get('X-Foo'), 'Bar')
        self.assertEqual(
            result.get_text_response(),
            '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<doc frontik="true"><result>3</result></doc>'
        )
 def test_call_get(self):
     result = EmptyEnvironment().add_arguments({'param': 'world'}).call_get(Page)
     self.assertEqual(result.get_json_response()['Hello'], 'world')
 def test_call_get(self):
     result = EmptyEnvironment().add_arguments({
         'param': 'world'
     }).call_get(Page)
     self.assertEqual(result.get_json_response()['Hello'], 'world')