Пример #1
0
 def test_call(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller':
                     'tests.watson.framework.support.TestController'
                 },
                 'requires': {
                     'format': 'json'
                 }
             }
         },
         'views': {
             'templates': {
                 'watson/mvc/test_applications/testcontroller/post': 'blank'
             }
         },
         'debug': {
             'enabled': True
         }
     })
     environ = sample_environ(PATH_INFO='/',
                              REQUEST_METHOD='POST',
                              HTTP_ACCEPT='application/json')
     response = application(environ, start_response)
     assert response == [b'{"content": "Posted Hello World!"}']
Пример #2
0
 def setup(self):
     app = applications.Http()
     p = Profile({
         'enabled': True,
         'sort': 'time',
         'max_results': 20
     }, app.container.get('jinja2_renderer'), app)
     self.app = app
     self.panel = p
Пример #3
0
 def test_last_exception(self):
     # occurs when exceptions have been raised from others
     environ = sample_environ()
     context = {'request': Request.from_environ(environ)}
     app = applications.Http()
     response, view_model = app.exception(last_exception=True,
                                          exception=Exception('test'),
                                          context=context)
     assert '<h1>Internal Server Error</h1>' in response.body
Пример #4
0
 def test_output(self):
     app = applications.Http({
         'debug': {
             'enabled': True
         },
     })
     renderer_config = app.config['views']['renderers']['jinja2']['config']
     renderer = Jinja2(config=renderer_config, application=app)
     assert renderer._debug_mode
Пример #5
0
 def setup(self):
     app = applications.Http()
     p = Request(
         {'enabled': True}, app.container.get('jinja2_renderer'), app)
     self.app = app
     self.panel = p
     params = {
         'context': {
             'request': messages.Request.from_environ(support.sample_environ())
         }
     }
     p.event = types.Event('test', params=params)
Пример #6
0
 def test_execute(self):
     app = applications.Http(
         {'debug': {
             'enabled': True,
             'toolbar': {
                 'bar': ''
             }
         }})
     event = types.Event('test', target=app)
     listener = listeners.Init()
     listener.container = app.container
     tb = listener(event)
     assert isinstance(tb, toolbar.Toolbar)
Пример #7
0
 def test_raise_exception_event_server_error(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller':
                     'tests.watson.framework.support.TestController'
                 }
             }
         }
     })
     response = application(sample_environ(PATH_INFO='/'), start_response)
     assert '<h1>Internal Server Error</h1>' in response[0].decode('utf-8')
Пример #8
0
 def test_render(self):
     app = applications.Http()
     tb = toolbar.Toolbar(
         {
             'panels': {
                 'tests.watson.framework.debug.support.Panel': {'enabled': True}
             }
         },
         app, app.container.get('jinja2_renderer'))
     params = {
         'context': {
             'request': messages.Request.from_environ({}),
             'response': messages.Response(200, body='<html><body></body></html>')
         },
         'view_model': views.Model(format='html')
     }
     event = types.Event('render', params=params)
     response = tb.render(event)
     assert '<!-- Injected Watson Debug Toolbar -->' in response.body
Пример #9
0
 def test_execute(self):
     app = applications.Http()
     listener = listeners.Render(config.views)
     context = {
         'response': Response(200),
     }
     vm = views.Model(format='text/plain', data={'content': 'test'})
     params = {'context': context, 'view_model': vm, 'container': app.container}
     event = Event('render', params=params)
     # error raised as no template exists
     with raises(InternalServerError):
         listener(event)
     with raises(InternalServerError):
         vm.format = 'exe'
         listener(event)
     vm.format = 'json'
     response = listener(event)
     assert response.status_code == 200
     assert response.headers['Content-Type'] == 'application/json'
Пример #10
0
 def test_application_logic_error(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller':
                     'tests.watson.framework.support.SampleActionController',
                     'action': 'blah_syntax_error'
                 }
             }
         },
         'views': {
             'templates': {
                 'watson/mvc/test_applications/testcontroller/blah_syntax_error':
                 'blank'
             }
         }
     })
     response = application(sample_environ(PATH_INFO='/'), start_response)
     assert '<h1>Internal Server Error</h1>' in response[0].decode('utf-8')
Пример #11
0
 def test_json_output(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'options': {
                     'controller':
                     'tests.watson.framework.support.AnotherSampleActionController',
                 },
                 'defaults': {
                     'action': 'json'
                 },
             }
         },
         'debug': {
             'enabled': True
         }
     })
     environ = sample_environ(PATH_INFO='/',
                              REQUEST_METHOD='GET',
                              HTTP_ACCEPT='application/json')
     response = application(environ, start_response)
     assert response == [b'{"name": "value"}']
Пример #12
0
# -*- coding: utf-8 -*-
from watson.framework import applications
from namet.config import base as config

application = applications.Http(config)
Пример #13
0
 def test_no_dispatcher_render(self):
     with raises(KeyError):
         # No context specified
         app = applications.Http()
         app.render(with_dispatcher=False)
Пример #14
0
 def setup(self):
     app = applications.Http()
     p = Application({'enabled': True},
                     app.container.get('jinja2_renderer'), app)
     self.app = app
     self.panel = p
Пример #15
0
 def test_create(self):
     application = applications.Http()
     assert isinstance(application.container, IocContainer)
     assert application.config == module_to_dict(config, '__')
     application_module = applications.Http(sample_config)
     assert application_module.config['debug']['enabled']
Пример #16
0
 def test_panel(self):
     p = support.SamplePanel({}, None, applications.Http())
     with raises(NotImplementedError):
         str(p)
     with raises(NotImplementedError):
         p.render_key_stat()
Пример #17
0
 def test_raise_exception_event_not_found(self):
     application = applications.Http()
     response = application(sample_environ(PATH_INFO='/'), start_response)
     assert '<h1>Not Found</h1>' in response[0].decode('utf-8')
Пример #18
0
 def test_no_exception_class(self):
     app = applications.Http({'exceptions': None})
     assert app.exception_class is exceptions.ApplicationError