def test_openapi_schema_generation(monkeypatch: Any,
                                   include_admin_routes: bool,
                                   schema_path: Path) -> None:
    clear_caches()
    monkeypatch.setenv("APP_INCLUDE_ADMIN_ROUTES", include_admin_routes)
    schema = get_app().openapi()

    save_schema(schema, schema_path)
    assert schema == load_schema(schema_path)
Exemplo n.º 2
0
def app(setup_database, db_session):
    app = get_app()

    def override_get_db():
        yield db_session

    app.dependency_overrides[get_db] = override_get_db

    yield app
Exemplo n.º 3
0
def create_test_database(database_uri: str) -> None:
    create_database(database_uri)

    app = get_app()
    engine = get_engine()
    metadata = get_configured_metadata(app)
    metadata.create_all(bind=engine)
    initialize_database(engine)

    create_test_data()
Exemplo n.º 4
0
def get_test_app() -> Iterator[FastAPI]:
    assert get_app_settings(
    ).testing is True  # requires APP_TESTING env var to be true

    app = get_app()
    engine = get_engine()
    metadata = get_configured_metadata(app)
    metadata.create_all(bind=engine)
    initialize_app_database(engine)

    yield app
Exemplo n.º 5
0
#! /usr/bin/env python

import logging

from flask_script import Shell
from flask_migrate import Migrate, MigrateCommand

from app.main import create_app as get_app
app = get_app()

from app.main import db, manager

migrate = Migrate(app, db)
logger = logging.getLogger('app')

manager.add_command('db', MigrateCommand)


def make_shell_context():
    return_dict = {'app': app, 'db': db, 'session': db.session}

    def go(obj):
        db.session.add(obj)
        db.session.commit()

    return_dict['go'] = go
    return return_dict


# convenience to have all of the above objects available
manager.add_command("shell", Shell(make_context=make_shell_context))
Exemplo n.º 6
0
def test_client():
    app = get_app()
    with TestClient(app) as test_client:
        yield test_client
Exemplo n.º 7
0
section = config.config_ini_section

url = config.get_main_option('sqlalchemy.url')
if url is None or url == '':
    config.set_section_option("alembic", "sqlalchemy.url", str(DB_DSN))

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = None
get_app()
target_metadata = db

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.
Exemplo n.º 8
0
# # this is the Alembic Config object, which provides
# # access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = None

target_metadata = get_configured_metadata(get_app())

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.
Exemplo n.º 9
0
from copy import deepcopy
from typing import Dict, List
from fastapi.testclient import TestClient

from app.core.config import ApiMode, Settings
from app.main import get_app

from . import api_utils

_api_client = TestClient(get_app(Settings(API_MODE=ApiMode.guardian)))


def create_guardian(guardian_id: str, sequence_order: int,
                    number_of_guardians: int, quorum: int) -> Dict:
    request = {
        "id": guardian_id,
        "sequence_order": sequence_order,
        "number_of_guardians": number_of_guardians,
        "quorum": quorum,
    }
    return api_utils.send_post_request(_api_client, "guardian", request)


def create_guardian_backup(guardian: Dict) -> Dict:
    auxiliary_public_key = {
        "owner_id": guardian["id"],
        "sequence_order": guardian["sequence_order"],
        "key": guardian["auxiliary_key_pair"]["public_key"],
    }
    request = {
        "guardian_id":
Exemplo n.º 10
0
from typing import Dict, List, Optional
from fastapi.testclient import TestClient

from app.core.config import ApiMode, Settings
from app.main import get_app

from . import api_utils

_api_client = TestClient(get_app(Settings(API_MODE=ApiMode.mediator)))


def combine_election_keys(election_public_keys: List[Dict]) -> Dict:
    """
    Combine the public keys of all guardians into a single ElGamal public key
    for use throughout the election
    """
    request = {"election_public_keys": election_public_keys}
    return api_utils.send_post_request(_api_client, "key/election/combine",
                                       request)


def create_election_context(description: Dict, elgamal_public_key: str,
                            number_of_guardians: int, quorum: int) -> Dict:
    """
    Construct an encryption context for use throughout the election to encrypt and decrypt data
    """
    request = {
        "description": description,
        "elgamal_public_key": elgamal_public_key,
        "number_of_guardians": number_of_guardians,
        "quorum": quorum,