コード例 #1
0
 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
コード例 #2
0
            "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')
コード例 #3
0
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')
コード例 #4
0
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')
コード例 #5
0

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')
コード例 #6
0
        "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')
コード例 #7
0
            "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)
コード例 #8
0
ファイル: conf_auth_right.py プロジェクト: ra2003/crax
    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')
コード例 #9
0
ファイル: common_tests.py プロジェクト: ra2003/crax
async def create_crax_server():
    config = Config(Crax("tests.config_files.conf_minimal"))
    server = Server(config)
    await server.serve()
コード例 #10
0
ファイル: app.py プロジェクト: ra2003/crax
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)
コード例 #11
0
        } 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)
コード例 #12
0
ファイル: conf_db_missed.py プロジェクト: ra2003/crax
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')
コード例 #13
0
ファイル: app.py プロジェクト: ape364/crax_wiki
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")
コード例 #14
0
ファイル: conf_rest.py プロジェクト: ra2003/crax
        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')
コード例 #15
0
ファイル: conf.py プロジェクト: ape364/crax
        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')
コード例 #16
0
            "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')