Exemplo n.º 1
0
    def test_flatten_flattens_multiple_lists(self):
        routes = [
            Get().route('/test/1', 'TestController@show').name('create'),
            RouteGroup([
                Get().route('/test/1', 'TestController@show').name('create'),
                Get().route('/test/2', 'TestController@show').name('edit'),
                RouteGroup([
                    Get().route('/test/1',
                                'TestController@show').name('update'),
                    Get().route('/test/2',
                                'TestController@show').name('delete'),
                    RouteGroup([
                        Get().route('/test/3',
                                    'TestController@show').name('update'),
                        Get().route('/test/4',
                                    'TestController@show').name('delete'),
                    ],
                               middleware=('auth')),
                ],
                           name='post.')
            ],
                       prefix='/dashboard')
        ]

        routes = flatten_routes(routes)

        self.assertEqual(routes[3].route_url, '/dashboard/test/1')
        self.assertEqual(routes[3].named_route, 'post.update')
Exemplo n.º 2
0
    def test_group_route_namespace_deep_no_dots(self):
        routes = RouteGroup([
            RouteGroup([
                Get().route('/test/1', 'DeepController@show'),
            ],
                       namespace='deep')
        ],
                            namespace='subdirectory')

        self.assertIsInstance(routes, list)
        self.assertEqual(DeepController, routes[0].controller)
Exemplo n.º 3
0
    def test_group_route_namespace_deep_using_route_values_in_constructor(
            self):
        routes = RouteGroup([
            RouteGroup([
                Get('/test/1', 'DeepController@show'),
            ],
                       namespace='deep.')
        ],
                            namespace='subdirectory.')

        self.assertIsInstance(routes, list)
        self.assertEqual(DeepController, routes[0].controller)
Exemplo n.º 4
0
    def test_group_route_sets_prefix_no_route(self):
        routes = RouteGroup([
            Get('', 'TestController@show'),
        ],
                            prefix='/dashboard')

        self.assertEqual(routes[0].route_url, '/dashboard')
Exemplo n.º 5
0
    def test_group_route_sets_prefix(self):
        routes = RouteGroup([
            Get().route('/test/1', 'TestController@show'),
            Get().route('/test/2', 'TestController@show')
        ],
                            prefix='/dashboard')

        self.assertEqual(routes[0].route_url, '/dashboard/test/1')
Exemplo n.º 6
0
    def test_group_adds_methods(self):
        routes = RouteGroup([
            Get().route('/test/1', 'TestController@show'),
            Get().route('/test/2', 'TestController@show')
        ],
                            add_methods=['OPTIONS'])

        self.assertEqual(routes[0].method_type, ['GET', 'OPTIONS'])
Exemplo n.º 7
0
    def test_group_route_sets_domain(self):
        routes = RouteGroup([
            Get().route('/test/1', 'TestController@show'),
            Get().route('/test/2', 'TestController@show')
        ],
                            domain=['www'])

        self.assertEqual(routes[0].required_domain, ['www'])
Exemplo n.º 8
0
    def test_group_route_namespace(self):
        routes = RouteGroup([
            Get().route('/test/1', 'SubController@show'),
        ],
                            namespace='subdirectory.')

        self.assertIsInstance(routes, list)
        self.assertEqual(SubController, routes[0].controller)
Exemplo n.º 9
0
    def test_group_route_sets_name_for_none_route(self):
        routes = RouteGroup([
            Get().route('/test/1', 'TestController@show').name('create'),
            Get().route('/test/2', 'TestController@show')
        ],
                            name='post.')

        self.assertEqual(routes[0].named_route, 'post.create')
        self.assertEqual(routes[1].named_route, None)
Exemplo n.º 10
0
    def test_group_route_sets_middleware(self):
        routes = RouteGroup([
            Get().route('/test/1',
                        'TestController@show').middleware('another'),
            Get().route('/test/2', 'TestController@show'),
            RouteGroup([
                Get().route('/test/3', 'TestController@show'),
                Get().route('/test/4', 'TestController@show')
            ],
                       middleware=('test', 'test2'))
        ],
                            middleware=('auth', 'user'))

        self.assertIsInstance(routes, list)
        self.assertEqual(['another', 'auth', 'user'],
                         routes[0].list_middleware)
        self.assertEqual(['auth', 'user'], routes[1].list_middleware)
        self.assertEqual(['test', 'test2', 'auth', 'user'],
                         routes[2].list_middleware)
Exemplo n.º 11
0
    def test_route_can_add_compilers_inside_route_group(self):
        self.route.compile('year', r'[0-9]{4}')
        group = RouteGroup(
            [Get().route('/@route:year', 'TestController@show')],
            prefix="/test")

        self.assertEqual(group[0].compile_route_to_regex(),
                         r'^\/test\/[0-9]{4}\/$')

        with self.assertRaises(InvalidRouteCompileException):
            get_route = Get().route('test/@route:none', None)
            get_route.request = self.request
            create_matchurl('/test/1', get_route)
Exemplo n.º 12
0
 Get().domain('test').route('/test', None).middleware('auth'),
 Get().domain('test').route('/unit/test',
                            'TestController@testing').middleware('auth'),
 Get().domain('test').route('/test/route', 'TestController@testing'),
 Get('/json_response', 'TestController@json_response'),
 Post('/test/post/route', 'TestController@post_test'),
 Get('/login', 'TestController@testing').name('login'),
 Get('/v', 'TestController@v').name('v'),
 Get('/', 'TestController@v').name('v'),
 Get('/test/param/@id', 'TestController@testing'),
 Post('/test/json/response/@id', 'TestController@json'),
 Get('/test/set/test/session', 'TestController@session'),
 Get('/test/mail', 'TestController@mail'),
 RouteGroup([
     Get('/test/1', 'TestController@show'),
     Get('/test/2', 'TestController@show')
 ],
            prefix='/example'),
 RouteGroup([
     Get('/deep/1', 'DeepController@show'),
 ],
            prefix='/example',
            namespace='subdirectory.deep.'),
 RouteGroup([
     Get('/test/get', 'UnitTestController@show'),
     Get('/test/param/@post_id', 'UnitTestController@param'),
     Post('/test/post', 'UnitTestController@store').middleware('test'),
     Get('/test/get/params',
         'UnitTestController@get_params').name('get.params'),
     Post('/test/params', 'UnitTestController@params'),
     Post('/test/user', 'UnitTestController@user'),
Exemplo n.º 13
0
 def test_group_route_sets_name(self):
     RouteGroup([
         Get().route('/test/1', 'TestController@show').name('create'),
         Get().route('/test/2', 'TestController@show').name('edit')
     ],
                name='post.')
Exemplo n.º 14
0
from app.http.test_controllers.TestController import TestController
from src.masonite.app import App
from src.masonite.exceptions import InvalidHTTPStatusCode, RouteException
from src.masonite.helpers import config
from src.masonite.helpers.routes import flatten_routes
from src.masonite.helpers.time import cookie_expire_time
from src.masonite.request import Request
from src.masonite.response import Response
from src.masonite.routes import Get, Route, RouteGroup
from src.masonite.testing import generate_wsgi, MockWsgiInput

WEB_ROUTES = flatten_routes([
    Get('/test', 'Controller@show').name('test'),
    RouteGroup([
        Get('/account', 'Controller@show').name('a_account'),
    ], prefix='/a')
])

wsgi_request = generate_wsgi()


class TestRequest(unittest.TestCase):

    def setUp(self):
        self.app = App()
        self.request = Request(wsgi_request.copy()).key(
            'NCTpkICMlTXie5te9nJniMj9aVbPM6lsjeq5iDZ0dqY=').load_app(self.app)
        self.app.bind('Request', self.request)
        self.response = Response(self.app)
        self.app.simple(Response)