Exemple #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')
Exemple #2
0
import pytest

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)