def test_match_route_returns_controller(self): self.app.make('Route').url = '/view' self.app.bind('WebRoutes', [ Match(['GET', 'POST']).route('/view', ControllerTest.returns_a_view) ]) self.provider.boot(self.app.make('Route'), self.app.make('Request'), self.app.make(Response)) assert self.app.make('Response') == 'hey'
def match(method_type, url, controller): """Shortcut for Match HTTP class. Arguments: method_type {list} -- A list of the method types you want to accept url {string} -- The url you want to use for the route controller {string|object} -- This can be a string controller or a normal object controller Returns: masonite.routes.Get -- The Masonite Get class. """ from masonite.routes import Match return Match(method_type).route(url, controller)
def test_route_can_have_multiple_routes(self): assert Match(['GET', 'POST']).route( 'test/url', 'TestController@show').method_type == ['GET', 'POST']
def test_match_routes_raises_exception_with_non_list_method_types(self): with pytest.raises(RouteException): assert Match('get').route( 'test/url', 'TestController@show').method_type == ['GET', 'POST']
def test_match_routes_convert_lowercase_to_uppercase(self): assert Match(['Get', 'Post']).route( 'test/url', 'TestController@show').method_type == ['GET', 'POST']
def test_match_routes_raises_exception_with_non_list_method_types(self): with self.assertRaises(RouteException): self.assertEqual( Match('get').route('test/url', 'TestController@show').method_type, ['GET', 'POST'])
def test_match_route_returns_controller(self): self.routes(only=[Match(['GET', 'POST']).route('/view', ControllerTest.returns_a_view)]) self.assertTrue(self.get('/view').contains('hey'))
def ComponentRoute(component, controller): return Match(['Get', 'POST'], f'/livewire/props/{component}', f'{controller}@show')