Testing helpers for Kyoukai.
Classes
TestKyoukai (*args, …) |
A special subclass that allows you to easily test your Kyoukai-based app. |
kyoukai.testing.
_TestingBpCtxManager
(app: kyoukai.testing.TestKyoukai)[source]¶Bases: object
A context manager that is returned from testing_bp()
. When entered, this will produce a new
Blueprint object, that is then set onto the test application as the root blueprint.
After exiting, it will automatically restore the old root Blueprint onto the application, allowing complete isolation of individual test routes away from eachother.
kyoukai.testing.
TestKyoukai
(*args, base_context: asphalt.core.context.Context = None, **kwargs)[source]¶Bases: kyoukai.app.Kyoukai
A special subclass that allows you to easily test your Kyoukai-based app.
Parameters: | base_context (Optional [Context ]) – The base context to use for all request testing. |
---|
wrap_existing_app
(base_context=None)[source]¶Wraps an existing app in a test frame.
This allows easy usage of writing unit tests:
# main.py
kyk = Kyoukai("my_app")
# test.py
testing = TestKyoukai.wrap_existing_app(other_app)
# use testing as you would normally
Parameters: |
|
---|
testing_bp
()[source]¶Context handler that allows with TestKyoukai.testing_bp() as bp:
You can then register items onto this new root blueprint until __exit__, which will then destroy the blueprint.
Return type: | _TestingBpCtxManager |
---|
inject_request
(self, headers, url, method='GET', body=None)[source]¶Injects a request into the test client.
This will automatically create the correct context.
Parameters: | |
---|---|
Return type: | |
Returns: | The result. |
finalize
(**map_options)¶Finalizes the app and blueprints.
This will calculate the current werkzeug.routing.Map
which is required for
routing to work.
Parameters: | map_options – The options to pass to the Map for routing. |
---|---|
Return type: | Map |
handle_httpexception
(self, ctx, exception, environ=None)¶Handle a HTTP Exception.
Parameters: |
|
---|---|
Return type: | |
Returns: | A |
log_route
(request, code)¶Logs a route invocation.
Parameters: |
---|
process_request
(self, request, parent_context)¶Processes a Request and returns a Response object.
This is the main processing method of Kyoukai, and is meant to be used by one of the HTTP server backends, and not by client code.
Parameters: |
|
---|---|
Return type: | |
Returns: | A |
register_blueprint
(child)¶Registers a child blueprint to this app’s root Blueprint.
This will set up the Blueprint tree, as well as setting up the routing table when finalized.
Parameters: | child (Blueprint ) – The child Blueprint to add. This must be an instance of Blueprint . |
---|
request_class
¶alias of Request
response_class
¶alias of Response
run
(ip='127.0.0.1', port=4444, *, component=None)¶Runs the Kyoukai server from within your code.
This is not normally invoked - instead Asphalt should invoke the Kyoukai component. However, this is here for convenience.
start
(self, ip='127.0.0.1', port=4444, *, component=None, base_context=None)¶Runs the Kyoukai component asynchronously.
This will bypass Asphalt’s default runner, and allow you to run your app easily inside something else, for example.
Parameters: |
|
---|