Esempio n. 1
0
 def test_raise_exception_event_server_error(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'defaults': {
                     'controller': 'tests.watson.mvc.support.TestController'
                 }
             }
         }
     })
     response = application(sample_environ(PATH_INFO='/'), start_response)
     assert '<h1>Internal Server Error</h1>' in response[0].decode('utf-8')
Esempio n. 2
0
 def test_call(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'defaults': {
                     'controller': 'tests.watson.mvc.support.TestController'
                 }
             }
         },
         'views': {
             'templates': {
                 'watson/mvc/test_applications/testcontroller/post': 'blank'
             }
         }
     })
     response = application(sample_environ(PATH_INFO='/', REQUEST_METHOD='POST', HTTP_ACCEPT='application/json'), start_response)
     assert response == [b'{"content": "Posted Hello World!"}']
Esempio n. 3
0
 def test_application_logic_error(self):
     application = applications.Http({
         'routes': {
             'home': {
                 'path': '/',
                 'defaults': {
                     'controller': 'tests.watson.mvc.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')
Esempio n. 4
0
# -*- coding: utf-8 -*-
# Runs an extremely simple web application on the development server
# and auto-reloads on change.
# This can either be run via `python app.py` or through uWSGI.
import os
import sys
try:
    import watson
except:
    sys.path.append(os.path.abspath('../../..'))
from watson.mvc import applications
from watson.util.server import make_dev_server
from config import local

application = applications.Http(local)

if __name__ == '__main__':
    make_dev_server(application, do_reload=True)
Esempio n. 5
0
application = applications.Http({
    'routes': {
        'home': {
            'path': '/',
            'defaults': {
                'controller': 'simple_hello_world_wsgi_app.MyRestController'
            }
        },
        'hello': {
            'path': '/hello',
            'defaults': {
                'controller': 'simple_hello_world_wsgi_app.MyActionController',
                'action': 'hello'
            }
        },
        'world': {
            'path': '/world',
            'defaults': {
                'controller': 'simple_hello_world_wsgi_app.MyActionController',
                'action': 'world'
            }
        },
        'json_world': {
            'path': '/hello-world.:format',
            'type': 'segment',
            'defaults': {
                'controller': 'simple_hello_world_wsgi_app.MyActionController',
                'action': 'json_world',
            },
            'requires': {
                'format': 'json$'
            }
        },
        'invalid_request': {
            'path': '/invalid',
            'defaults': {
                'controller': 'simple_hello_world_wsgi_app.MyActionController'
            }
        }
    },
    'views': {
        'templates': {
            'myrestcontroller/get': 'blank',  # blank is a blank html template
            'myactioncontroller/hello':
            'blank',  # the first module is stripped from the path
            'myactioncontroller/world': 'blank',
        }
    }
})
Esempio n. 6
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')
Esempio n. 7
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']