Ejemplo n.º 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!"}']
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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
Ejemplo n.º 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'
Ejemplo n.º 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')
Ejemplo n.º 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"}']
Ejemplo n.º 12
0
# -*- coding: utf-8 -*-
from watson.framework import applications
from namet.config import base as config

application = applications.Http(config)
Ejemplo n.º 13
0
 def test_no_dispatcher_render(self):
     with raises(KeyError):
         # No context specified
         app = applications.Http()
         app.render(with_dispatcher=False)
Ejemplo n.º 14
0
 def setup(self):
     app = applications.Http()
     p = Application({'enabled': True},
                     app.container.get('jinja2_renderer'), app)
     self.app = app
     self.panel = p
Ejemplo n.º 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']
Ejemplo n.º 16
0
 def test_panel(self):
     p = support.SamplePanel({}, None, applications.Http())
     with raises(NotImplementedError):
         str(p)
     with raises(NotImplementedError):
         p.render_key_stat()
Ejemplo n.º 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')
Ejemplo n.º 18
0
 def test_no_exception_class(self):
     app = applications.Http({'exceptions': None})
     assert app.exception_class is exceptions.ApplicationError