def setup_method(self):
     self.request = Request(generate_wsgi())
     self.middleware = MaintenanceModeMiddleware(self.request)
     down_path = os.path.join(application.BASE_DIRECTORY, 'bootstrap/down')
     down = os.path.exists(down_path)
     if down:
         os.remove(down_path)
Пример #2
0
    def contains(self, value):
        wsgi = generate_wsgi()
        wsgi['PATH_INFO'] = self.route.route_url
        wsgi['REQUEST_METHOD'] = self.route.method_type[0]
        self.container = self._run_container(wsgi).container

        return value in self.container.make('Response')
Пример #3
0
    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
Пример #4
0
    def run_container(self, wsgi_values={}):
        wsgi = generate_wsgi()
        wsgi.update(wsgi_values)
        self.container.bind('Environ', wsgi)
        self.container.make('Request')._test_user = self.acting_user
        print(id(self.container))
        self.container.make('Request').load_app(self.container)
        if self._with_subdomains:
            self.container.make('Request').activate_subdomains()

        if self.route_middleware is not False:
            print('bind new middleware', self.route_middleware)
            self.container.bind('RouteMiddleware', self.route_middleware)

        if self.http_middleware is not False:
            self.container.bind('HttpMiddleware', self.http_middleware)

        try:
            for provider in self.container.make('WSGIProviders'):
                self.container.resolve(provider.boot)
        except Exception as e:
            if self._exception_handling:
                self.container.make('ExceptionHandler').load_exception(e)
            else:
                raise e
Пример #5
0
    def canView(self):
        wsgi = generate_wsgi()
        wsgi['PATH_INFO'] = self.route.route_url
        wsgi['RAW_URI'] = self.route.route_url
        self.container = self._run_container(wsgi).container

        return self.container.make('Request').get_status_code() == '200 OK'
Пример #6
0
 def setUp(self):
     self.app = App()
     self.request = Request(generate_wsgi()).load_app(self.app)
     self.app.bind('Request', self.request)
     self.app.bind('StatusCode', None)
     self.response = Response(self.app)
     self.app.bind('Response', self.response)
Пример #7
0
 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 setUp(self):
     self.app = App()
     self.app.bind('StatusCode', '404 Not Found')
     self.app.bind(
         'Request',
         Request(None).load_app(self.app).load_environ(generate_wsgi()))
     self.app.simple(Response(self.app))
     self.app.bind('ViewClass', View(self.app))
     self.app.bind('View', self.app.make('ViewClass').render)
Пример #9
0
 def json(self, url, data, method=['POST']):
     wsgi = generate_wsgi()
     wsgi['PATH_INFO'] = url
     wsgi['CONTENT_TYPE'] = 'application/json'
     wsgi['REQUEST_METHOD'] = method
     wsgi['CONTENT_LENGTH'] = len(str(json.dumps(data)))
     wsgi['wsgi.input'] = io.StringIO(json.dumps(data))
     self.container = TestSuite().create_container(wsgi=wsgi).container
     return MockJson(url, self.container)
Пример #10
0
 def setup_method(self):
     self.app = App()
     self.app.bind(
         'Request',
         Request(None).load_app(self.app).load_environ(generate_wsgi()))
     self.app.bind('Application', MockApplicationConfig)
     self.app.bind('ViewClass', View(self.app))
     self.app.bind('View', self.app.make('ViewClass').render)
     self.hook = ServerErrorExceptionHook().load(self.app)
 def setUp(self):
     self.app = App()
     self.app.bind('Container', self.app)
     self.app.bind(
         'Request',
         Request(None).load_app(self.app).load_environ(generate_wsgi()))
     self.app.simple(Response)
     self.app.bind('Application', MockApplicationConfig)
     self.app.bind('ViewClass', View(self.app))
     self.app.bind('View', self.app.make('ViewClass').render)
Пример #12
0
    def status(self, value=None):
        wsgi = generate_wsgi()
        wsgi['PATH_INFO'] = self.route.route_url
        wsgi['REQUEST_METHOD'] = self.route.method_type[0]
        self.container = self._run_container(wsgi).container

        if not value:
            return self.container.make('Request').get_status_code()

        return self.container.make('Request').get_status_code() == value
Пример #13
0
 def run_container(self, wsgi_values={}):
     wsgi = generate_wsgi()
     wsgi.update(wsgi_values)
     self.container.bind('Environ', wsgi)
     self.container.make('Request')._test_user = self.acting_user
     try:
         for provider in self.container.make('WSGIProviders'):
             self.container.resolve(provider.boot)
     except Exception as e:
         if self._exception_handling:
             self.container.make('ExceptionHandler').load_exception(e)
         else:
             raise e
Пример #14
0
 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
Пример #15
0
    def test_request_validation_redirects_back_with_session(self):
        wsgi = generate_wsgi()
        self.app.bind('Application', self.app)
        self.app.bind('SessionCookieDriver', SessionCookieDriver)
        self.app.bind('Environ', wsgi)

        request = self.app.make('Request')
        request.load_environ(wsgi)

        request.request_variables = {'id': 1, 'name': 'Joe'}

        errors = request.validate(required('user'))

        request.session = SessionManager(self.app).driver('cookie')
        request.key('UKLAdrye6pZG4psVRPZytukJo2-A_Zxbo0VaqR5oig8=')
        self.assertEqual(
            request.redirect('/login').with_errors(errors).redirect_url,
            '/login')
        self.assertEqual(
            request.redirect('/login').with_errors(errors).session.get(
                'errors'), {'user': ['The user field is required.']})
Пример #16
0
    def create_container(self):
        container = App()
        from config import application
        from config import providers

        container.bind('WSGI', generate_wsgi())
        container.bind('Application', application)
        container.bind('Container', container)

        container.bind('ProvidersConfig', providers)
        container.bind('Providers', [])
        container.bind('WSGIProviders', [])

        """Bind all service providers
        Let's register everything into the Service Container. Once everything is
        in the container we can run through all the boot methods. For reasons
        some providers don't need to execute with every request and should
        only run once when the server is started. Providers will be ran
        once if the wsgi attribute on a provider is False.
        """

        for provider in container.make('ProvidersConfig').PROVIDERS:
            located_provider = provider()
            located_provider.load_app(container).register()
            if located_provider.wsgi:
                container.make('WSGIProviders').append(located_provider)
            else:
                container.make('Providers').append(located_provider)

        for provider in container.make('Providers'):
            container.resolve(provider.boot)

        """Get the application from the container
        Some providers may change the WSGI Server like wrapping the WSGI server
        in a Whitenoise container for an example. Let's get a WSGI instance
        from the container and pass it to the application variable. This
        will allow WSGI servers to pick it up from the command line
        """

        return container
Пример #17
0
 def session(self, key):
     wsgi = generate_wsgi()
     wsgi['PATH_INFO'] = self.route.route_url
     wsgi['RAW_URI'] = self.route.route_url
     self.container = self._run_container(wsgi).container
     return self.container.make('Session').get(key)
Пример #18
0
 def get(self, url):
     wsgi = generate_wsgi()
     wsgi['PATH_INFO'] = url
     self.container = TestSuite().create_container(wsgi=wsgi).container
     return MockRequest(url, self.container)
Пример #19
0
 def setUp(self):
     self.app = App()
     self.view = View(self.app)
     self.request = Request(generate_wsgi()).load_app(self.app)
     self.provider = HelpersProvider()
     self.provider.load_app(self.app).boot(self.view, self.request)
Пример #20
0
 def setup_method(self):
     self.app = App()
     self.request = Request(generate_wsgi()).load_app(self.app)
     self.app.bind('Request', self.request)
     self.response = Response(self.app)
Пример #21
0
 def json(self, request_method, url, data):
     wsgi = generate_wsgi()
     wsgi['PATH_INFO'] = url
     wsgi['CONTENT_TYPE'] = 'application/json'
Пример #22
0
 def setup_method(self):
     self.request = Request(generate_wsgi())
     self.middleware = SecureHeadersMiddleware(self.request)
     self.app = TestSuite().create_container().container
     self.app.bind('Request', self.request.load_app(self.app))
     self.request = self.app.make('Request')