def test_response(self):
     ioc = container.IocContainer()
     ioc.add('application.config', {
         'cors': {},
     })
     route = routes.Literal(name='test',
                            path='/',
                            accepts=('GET', 'OPTIONS'))
     route_match = routes.RouteMatch(route=route, params={})
     response = messages.Response()
     event = types.Event(
         name='test',
         params={
             'context': {
                 'response':
                 response,
                 'request':
                 messages.Request.from_environ(
                     sample_environ(REQUEST_METHOD='OPTIONS')),
                 'route_match':
                 route_match
             }
         })
     listener = listeners.Request()
     listener.container = ioc
     listener(event)
     assert response._cors_processed
 def test_forward_no_method(self):
     controller = SampleActionController()
     controller.container = IocContainer()
     request = Request.from_environ(sample_environ())
     context = {'request': request}
     controller.event = types.Event('test', params={'context': context})
     controller.__action__ = 'do_method_forward'
     assert controller.do_method_forward() == 'Another Response'
Exemple #3
0
    def event(self):
        """The event that was triggered that caused the execution of the
        controller.

        Returns:
            watson.events.types.Event
        """
        if not self._event:
            self._event = types.Event(events.DISPATCH_EXECUTE,
                                      params={'context': {}})
        return self._event
Exemple #4
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)
Exemple #5
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)
Exemple #6
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
Exemple #7
0
 def test_render_listener(self):
     vm = views.Model()
     params = {'view_model': vm}
     event = types.Event('name', params=params)
     self.panel.render_listener(event)
     assert self.panel.view_model is vm
Exemple #8
0
 def test_route_match_listener(self):
     rm = routes.RouteMatch('test', {})
     params = {'context': {'route_match': rm}}
     event = types.Event('name', params=params)
     self.panel.route_match_listener(event)
     assert self.panel.route_match is rm
 def test_get_event(self):
     base = controllers.HttpMixin()
     base.event = types.Event('test')
     assert isinstance(base.event, types.Event)
 def test_forward(self):
     controller = SampleActionController()
     request = Request.from_environ(sample_environ())
     context = {'request': request}
     controller.event = types.Event('test', params={'context': context})
     assert controller.do_forward() == 'Response'