Esempio n. 1
0
async def tortoise_db():
    db_url = environ.get("TORTOISE_TEST_DB", "sqlite://:memory:")
    config = getDBConfig(app_label="models", db_url=db_url, modules=settings.APP_MODELS)
    try:
        await Tortoise.init(config)
        await Tortoise._drop_databases()
    except DBConnectionError:
        pass

    await Tortoise.init(config)
    await Tortoise.generate_schemas()

    yield

    await Tortoise.close_connections()
Esempio n. 2
0
    def truncate_all(self, force: bool = False) -> None:
        if not (environ.get("TESTING") == "TRUE" or force):
            raise Exception("can only truncate while testing or set to force")

        if not self.engine:
            raise Exception("no engine configured")

        with contextlib.closing(self.engine.connect()) as conn:
            trans = conn.begin()
            for table in reversed(metadata.sorted_tables):
                try:
                    conn.execute(table.delete())
                except:
                    pass
            trans.commit()
Esempio n. 3
0
        return JSONResponse(
            dict(
                success=False,
                message='"content" may not be empty.',
                execution_time=start - time.time(),
            )
        )
    minified = htmlmin.minify(content, remove_empty_space=True)
    encoded = base64.b64encode(minified.encode())
    base64_string = f"data:text/html;base64,{encoded.decode()}"
    payload = dict(
        success=True,
        content_length=len(content),
        minified_content_length=(len(minified)),
        base64_string_length=len(base64_string),
        base64_string=base64_string,
        execution_time=time.time() - start,
    )
    return JSONResponse(payload)


DEBUG = environ.get("DEBUG", "False").strip().lower() == "true"
app = Starlette(
    debug=DEBUG,
    routes=[
        Route("/", index, methods=["GET"]),
        Route("/render", render, methods=["GET"]),
        Route("/api", api, methods=["POST"]),
    ],
)
Esempio n. 4
0
from passlib.context import CryptContext
from starlette.config import Config, environ
from starlette.datastructures import CommaSeparatedStrings

config = Config(".env")

BASE_PATH_API = config('BASE_PATH_API')

SECRET_KEY = config('SECRET_KEY')
ALGORITHM = "HS256"
PWD_CONTEXT = CryptContext(schemes=["bcrypt"], deprecated="auto")

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=CommaSeparatedStrings)

DEBUG = config('DEBUG', cast=bool, default=False)

ACCESS_TOKEN_EXPIRES = config('ACCESS_TOKEN_EXPIRES', default=24 * 7)
MONGODB_NAME = config("MONGODB_NAME")
MONGODB_URI = config("MONGODB_URI")

database_name = MONGODB_NAME
if environ.get('TESTING') == 'TRUE':
    database_name = f'test-{database_name}'
Esempio n. 5
0
from typing import Optional

from starlette.config import Config, environ
from starlette.datastructures import Secret

config = Config("test.env" if environ.get("TESTING", False) else ".env")

DEBUG = config("DEBUG", cast=bool, default=False)
TESTING = config("TESTING", cast=bool, default=False)

DB_DRIVER = config("DB_DRIVER", default="postgres")
DB_HOST = config("DB_HOST", default=None)
DB_PORT = config("DB_PORT", cast=int, default=None)
DB_USER = config("DB_USER", default=None)
DB_PASSWORD = config("DB_PASSWORD", cast=Secret, default=None)
DB_DATABASE = config("DB_DATABASE", default=None)

if DB_DATABASE is not None and TESTING:
    DB_DATABASE = f"test_{DB_DATABASE}"


def make_dsn(
    driver: str,
    user: str,
    password: str,
    host: str,
    port: Optional[int],
    database: Optional[str] = None,
) -> str:
    port_str = ""
    if port is not None: