class TestFilterScopes: def setup_method(self): from wsgi import container self.app = container self.app.make('Request').environ = generate_wsgi() self.app.make('Request').load_app(self.app) self.app.bind('StatusCode', None) self.provider = RouteProvider() self.provider.app = self.app def test_filter_scopes_filters_dictionary(self): self.app.make('Route').url = '/api' request = self.app.make('Request') request.request_variables = {} request.path = '/api/1' self.app.bind('WebRoutes', UserResourceTest('/api').routes()) self.provider.boot( self.app.make('Route'), self.app.make('Request'), self.app.make(Response), ) assert '"name":' in self.app.make('Response') assert '"email":' in self.app.make('Response') assert '"id":' not in self.app.make('Response')
def setup_method(self): from wsgi import container self.app = container self.app.make('Request').environ = generate_wsgi() self.app.make('Request').load_app(self.app) self.app.bind('StatusCode', None) self.provider = RouteProvider() self.provider.app = self.app
class TestResource: def setup_method(self): from wsgi import container self.app = container self.app.make('Request').environ = generate_wsgi() self.app.make('Request').load_app(self.app) self.app.bind('StatusCode', None) self.provider = RouteProvider() self.provider.app = self.app def test_resource_can_return_response_acting_as_route(self): self.app.make('Route').url = '/api/1' request = self.app.make('Request') request.path = '/api/1' self.app.bind('WebRoutes', ResourceTest('/api').routes()) self.provider.boot( self.app.make('Route'), self.app.make('Request'), self.app.make(Response), ) assert request.is_status(203) assert self.app.make('Response') == 'read_single' def test_resource_returns_correct_routes(self): routes = ResourceTest('/api').routes() assert len(routes) == 5 def test_resource_middleware_returns_json_from_dictionary(self): self.app.make('Route').url = '/api/1' self.app.make('Request').path = '/api/1' self.app.bind('WebRoutes', ResourceJsonTest('/api').routes()) self.provider.boot( self.app.make('Route'), self.app.make('Request'), self.app.make(Response), ) assert self.app.make('Response') == '{"id": 1}' def test_route_groups_middleware(self): group = RouteGroup([ResourceJsonTest('/api').routes()], middleware=('auth', )) assert group[0].list_middleware == ['auth']
def setUp(self): self.app = App() self.app.bind('Environ', generate_wsgi()) self.app.bind('Application', application) self.app.make('Environ') self.app.bind('StatusCode', None) self.app.bind('Request', Request(self.app.make('Environ')).load_app(self.app)) self.app.simple(Response(self.app)) self.app.bind('Csrf', Csrf(self.app.make('Request'))) self.app.bind('Route', Route(self.app.make('Environ'))) self.app.bind('ViewClass', View(self.app)) self.app.bind( 'WebRoutes', [Get().route('/', 'TestController@show').middleware('test')]) self.app.bind('HttpMiddleware', [MiddlewareHttpTest]) self.app.bind('RouteMiddleware', { 'test': MiddlewareTest, 'throttle:1,2': MiddlewareValueTest }) self.provider = RouteProvider() self.provider.app = self.app
def setup_method(self): self.app = App() self.app.bind('Container', self.app) self.app.bind('Environ', generate_wsgi()) self.app.bind('Application', Application) self.app.bind('WebRoutes', []) self.app.bind('Route', Route(self.app.make('Environ'))) self.app.bind('Request', Request( self.app.make('Environ')).load_app(self.app)) self.app.bind('Headers', []) self.app.bind('Csrf', Csrf(self.app.make('Request'))) self.app.bind('StatusCode', '404 Not Found') self.app.bind('HttpMiddleware', middleware.HTTP_MIDDLEWARE) view = View(self.app) self.app.bind('ViewClass', view) self.app.bind('View', view.render) self.provider = RouteProvider() self.provider.app = self.app
class TestResource: def setup_method(self): self.app = App() self.app.bind('Container', self.app) self.app.bind('Environ', generate_wsgi()) self.app.bind('Application', Application) self.app.bind('WebRoutes', []) self.app.bind('Route', Route(self.app.make('Environ'))) self.app.bind('Request', Request( self.app.make('Environ')).load_app(self.app)) self.app.bind('Headers', []) self.app.bind('Csrf', Csrf(self.app.make('Request'))) self.app.bind('StatusCode', '404 Not Found') self.app.bind('HttpMiddleware', middleware.HTTP_MIDDLEWARE) view = View(self.app) self.app.bind('ViewClass', view) self.app.bind('View', view.render) self.provider = RouteProvider() self.provider.app = self.app def test_resource_can_return_response_acting_as_route(self): self.app.make('Route').url = '/api/1' self.app.make('Request').path = '/api/1' self.app.bind('WebRoutes', [ResourceTest('/api')]) self.provider.boot( self.app.make('Route'), self.app.make('Request') ) assert self.app.make('Response') == 'read_single' def test_resource_returns_correct_routes(self): routes = ResourceTest('/api').routes() assert len(routes) == 5 def test_resource_can_return_response_acting_as_route(self): self.app.make('Route').url = '/api/1' self.app.make('Request').path = '/api/1' self.app.bind('WebRoutes', ResourceTest('/api').routes()) self.provider.boot( self.app.make('Route'), self.app.make('Request') ) assert self.app.make('Response') == 'read_single' def test_resource_middleware_returns_json_from_dictionary(self): self.app.make('Route').url = '/api/1' self.app.make('Request').path = '/api/1' self.app.bind('WebRoutes', ResourceJsonTest('/api').routes()) self.provider.boot( self.app.make('Route'), self.app.make('Request') ) assert self.app.make('Response') == '{"id": 1}' def test_output_routes(self): for route in ResourceTest('/api').routes(): print(route.route_url, route.method_type)