def __init__(self, test_func, *args, settings=None, debug=False, on_startup=None): self.func = test_func self.on_startup = on_startup if settings is None: self.app = Crax() else: self.app = Crax(settings=settings, debug=debug, on_startup=on_startup) self.args = args
"host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, "custom": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='app_four.conf')
SECRET_KEY = "qwerty1234567" MIDDLEWARE = [ "crax.auth.middleware.AuthMiddleware", "crax.middleware.x_frame.XFrameMiddleware", "crax.middleware.max_body.MaxBodySizeMiddleware", "crax.auth.middleware.SessionMiddleware", "crax.middleware.cors.CorsHeadersMiddleware", ] APPLICATIONS = ["test_app_common", "test_app_auth"] URL_PATTERNS = url_list STATIC_DIRS = ["static", "test_app/static"] DATABASES = { "users": { "driver": "postgresql", "host": "127.0.0.1", "user": "******", "password": "******", "name": "testing_users", } } ERROR_HANDLERS = { "500_handler": Handler500, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_auth_no_default_db')
try: from test_app_auth.routers import Handler500 from test_app_auth.urls_auth import url_list except ImportError: from ..test_app_auth.routers import Handler500 from ..test_app_auth.urls_auth import url_list ALLOWED_HOSTS = ["*"] BASE_URL = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = "qwerty1234567" MIDDLEWARE = [ "crax.auth.middleware.AuthMiddleware", "crax.middleware.x_frame.XFrameMiddleware", "crax.middleware.max_body.MaxBodySizeMiddleware", "crax.auth.middleware.SessionMiddleware", "crax.middleware.cors.CorsHeadersMiddleware", ] APPLICATIONS = ["test_app_common", "test_app_auth"] URL_PATTERNS = url_list STATIC_DIRS = ["static", "test_app_common/static"] DATABASES = [] ERROR_HANDLERS = { "500_handler": Handler500, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_db_wrong_type')
if "TRAVIS" not in os.environ: DATABASES = { "default": { "driver": TEST_MODE, "host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], }, } ERROR_HANDLERS = { "500_handler": Handler500, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_auth_right_no_db_options')
"name": "MIT", "url": "https://opensource.org/licenses/MIT" }, servers=[ { "url": "http://127.0.0.1:8000", "description": "Development server http" }, { "url": "https://127.0.0.1:8000", "description": "Staging server" }, ], basePath="/api", ) X_FRAME_OPTIONS = "DENY" ENABLE_CSRF = True def square_(a): return a * a def hello(): return "Hello world" TEMPLATE_FUNCTIONS = [square_, hello] app = Crax(settings='tests.config_files.conf_csrf')
"url": "http://127.0.0.1:8000", "description": "Development server http" }, { "url": "https://127.0.0.1:8000", "description": "Staging server" }, ], basePath="/api", ) def square_(a): return a * a def hello(): return "Hello world" TEMPLATE_FUNCTIONS = [square_, hello] CORS_OPTIONS = { "origins": ["*"], "methods": ["*"], "headers": ["content-type"], "cors_cookie": "Allow-By-Cookie", } DISABLE_LOGS = False app = Crax(settings="test_selenium.app", debug=True)
DATABASES = { "default": { "driver": TEST_MODE, "host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } ERROR_HANDLERS = { "500_handler": Handler500, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_auth_right')
async def create_crax_server(): config = Config(Crax("tests.config_files.conf_minimal")) server = Server(config) await server.serve()
import os from crax import Crax from .urls import url_list BASE_URL = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = "qwerty1234567" MIDDLEWARE = [ "crax.auth.middleware.AuthMiddleware", "crax.auth.middleware.SessionMiddleware", ] APPLICATIONS = ["streams"] URL_PATTERNS = url_list STATIC_DIRS = ["static", "streams/static"] DATABASES = { "default": { "driver": "sqlite", "name": f"/{BASE_URL}/test_crax.sqlite" }, } app = Crax(settings="streams.app", debug=True)
} for row_id, number in updates] async with connection_pool.acquire() as connection: statement = await connection.prepare(READ_ROW_SQL) for row_id, number in updates: await statement.fetchval(row_id) await connection.executemany(WRITE_ROW_SQL, updates) self.context = worlds class TestSingleFortunes(TemplateView): template = "fortune.html" async def get(self): async with connection_pool.acquire() as connection: fortunes = await connection.fetch('SELECT * FROM Fortune') fortunes.append([0, 'Additional fortune added at request time.']) fortunes.sort(key=itemgetter(1)) self.context["fortunes"] = fortunes APPLICATIONS = ["hello"] URL_PATTERNS = [ Route(Url('/json'), JSONResponse(None, {'message': 'Hello, world!'})), Route(Url('/plaintext'), BaseResponse(None, b'Hello, world!')), Route(Url('/db'), TestSingleQuery), Route(Url('/queries'), TestMultiQueries), Route(Url('/updates'), TestUpdates), Route(Url('/fortunes'), TestSingleFortunes) ] app = Crax('hello.app', debug=True, on_startup=setup_database)
from crax import Crax try: from test_app_auth.routers import Handler500 from test_app_auth.urls_auth import url_list except ImportError: from ..test_app_auth.routers import Handler500 from ..test_app_auth.urls_auth import url_list ALLOWED_HOSTS = ["*"] BASE_URL = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = "qwerty1234567" MIDDLEWARE = [ "crax.auth.middleware.AuthMiddleware", "crax.middleware.x_frame.XFrameMiddleware", "crax.middleware.max_body.MaxBodySizeMiddleware", "crax.auth.middleware.SessionMiddleware", "crax.middleware.cors.CorsHeadersMiddleware", ] APPLICATIONS = ["test_app_common", "test_app_auth"] URL_PATTERNS = url_list STATIC_DIRS = ["static", "test_app_common/static"] ERROR_HANDLERS = { "500_handler": Handler500, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_db_missed')
class Docs(TemplateView): template = 'index.html' scope = os.listdir('crax_docs/templates') class NotFoundHandler(TemplateView): template = '404.html' async def get(self): self.status_code = 404 class ServerErrorHandler(TemplateView): template = '500.html' BASE_URL = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) URL_PATTERNS = [ Route(Url('/'), Home), Route(urls=( Url('/documentation', masquerade=True), Url('/documentation/_sources/', masquerade=True)), handler=Docs), ] DISABLE_LOGS = False ERROR_HANDLERS = {'404_handler': NotFoundHandler, '500_handler': ServerErrorHandler} APPLICATIONS = ['crax_docs'] app = Crax(settings="crax_docs.app")
host = "127.0.0.1" return host if "TRAVIS" not in os.environ: DATABASES = { "default": { "driver": TEST_MODE, "host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='tests.config_files.conf_rest')
host = "127.0.0.1" return host if "TRAVIS" not in os.environ: DATABASES = { "default": { "driver": TEST_MODE, "host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='app_one.conf')
"host": get_db_host(), "user": "******", "password": "******", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } else: DATABASES = { "default": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, "custom": { "driver": TEST_MODE, "host": "127.0.0.1", "user": DB_USERS[TEST_MODE], "password": "", "name": DB_NAMES[TEST_MODE], "options": OPTIONS, }, } X_FRAME_OPTIONS = "DENY" app = Crax(settings='app_five.conf')