Exemplo n.º 1
0
def api_client(wired_device, wireless_device, sample_member3):
    from ..context import app
    with app.app.test_client() as c:
        db.init_db(DATABASE, testing=True)
        prep_db(db.get_db().get_session(), wired_device, wireless_device,
                sample_member3)
        yield c
Exemplo n.º 2
0
def api_client(sample_port1, sample_port2, sample_room1):
    from ..context import app
    with app.app.test_client() as c:
        db.init_db(db_settings, testing=True)
        prep_db(db.get_db().get_session(), sample_port1, sample_port2,
                sample_room1)
        yield c
Exemplo n.º 3
0
def api_client(sample_naina, sample_naina_expired):
    with app.app.test_client() as c:
        db.init_db(db_settings, testing=True)
        s = db.get_db().get_session()

        s.add(sample_naina_expired)
        s.add(sample_naina)
        s.commit()

        yield c
Exemplo n.º 4
0
def api_client(sample_member1, sample_member2, sample_member13,
               wired_device, wireless_device,
               sample_room1, sample_room2, sample_vlan):
    from .context import app
    with app.app.test_client() as c:
        db.init_db(DATABASE, testing=True)
        prep_db(db.get_db().get_session(),
                sample_member1,
                sample_member2,
                sample_member13,
                wired_device,
                wireless_device,
                sample_room1,
                sample_room2,
                sample_vlan)
        yield c
Exemplo n.º 5
0
def api_client(sample_transaction):
    from .context import app
    with app.app.test_client() as c:
        db.init_db(db_settings, testing=True)
        prep_db(db.get_db().get_session(), sample_transaction)
        yield c
Exemplo n.º 6
0
Arquivo: main.py Projeto: bonnetn/adh6
def init(testing=True):
    """
    Initialize and wire together the dependency of the application.
    """
    if testing:
        configuration = TEST_CONFIGURATION
    else:
        configuration = CONFIGURATION

    Database.init_db(configuration.DATABASE, testing=testing)

    # Repositories:
    ping_repository = PingSQLRepository()
    member_sql_repository = MemberSQLRepository()
    network_object_sql_repository = NetworkObjectSQLRepository()
    device_sql_repository = DeviceSQLRepository()
    room_sql_repository = RoomSQLRepository()
    elk_repository = ElasticSearchRepository(configuration)
    money_repository = MoneySQLRepository()
    switch_network_manager = SwitchSNMPNetworkManager()
    account_sql_repository = AccountSQLRepository()
    product_sql_repository = ProductSQLRepository()
    payment_method_sql_repository = PaymentMethodSQLRepository()
    transaction_sql_repository = TransactionSQLRepository()
    account_type_sql_repository = AccountTypeSQLRepository()

    # Managers
    health_manager = HealthManager(ping_repository)
    switch_manager = SwitchManager(
        switch_repository=network_object_sql_repository, )
    port_manager = PortManager(port_repository=network_object_sql_repository, )
    device_manager = DeviceManager(
        device_repository=device_sql_repository,
        member_repository=member_sql_repository,
        room_repository=room_sql_repository,
        vlan_repository=network_object_sql_repository,
        ip_allocator=device_sql_repository,
    )
    member_manager = MemberManager(
        member_repository=member_sql_repository,
        money_repository=money_repository,
        membership_repository=member_sql_repository,
        logs_repository=elk_repository,
        configuration=configuration,
    )
    room_manager = RoomManager(room_repository=room_sql_repository, )
    account_manager = AccountManager(
        account_repository=account_sql_repository,
        member_repository=member_sql_repository,
    )
    product_manager = ProductManager(
        product_repository=product_sql_repository, )

    payment_method_manager = PaymentMethodManager(
        payment_method_repository=payment_method_sql_repository)
    transaction_manager = TransactionManager(
        transaction_repository=transaction_sql_repository, )
    account_type_manager = AccountTypeManager(
        account_type_repository=account_type_sql_repository)

    # HTTP Handlers:
    health_handler = HealthHandler(health_manager)
    transaction_handler = TransactionHandler(transaction_manager)
    member_handler = MemberHandler(member_manager)
    device_handler = DeviceHandler(device_manager)
    room_handler = RoomHandler(room_manager)
    switch_handler = SwitchHandler(switch_manager)
    port_handler = PortHandler(port_manager, switch_manager,
                               switch_network_manager)
    temporary_account_handler = TemporaryAccountHandler()
    account_type_handler = AccountTypeHandler(account_type_manager)
    payment_method_handler = PaymentMethodHandler(payment_method_manager)
    account_handler = AccountHandler(account_manager)
    product_handler = ProductHandler(product_manager)

    # Connexion will use this function to authenticate and fetch the information of the user.
    if os.environ.get('TOKENINFO_FUNC') is None:
        os.environ[
            'TOKENINFO_FUNC'] = 'src.interface_adapter.http_api.auth.token_info'

    app = connexion.FlaskApp(__name__, specification_dir='openapi')
    app.add_api(
        'swagger.yaml',
        # resolver=RestyResolver('src.interface_adapter.http_api'),
        resolver=ADHResolver({
            'health': health_handler,
            'transaction': transaction_handler,
            'member': member_handler,
            'device': device_handler,
            'room': room_handler,
            'switch': switch_handler,
            'port': port_handler,
            'temporary_account': temporary_account_handler,
            'account_type': account_type_handler,
            'payment_method': payment_method_handler,
            'account': account_handler,
            'product': product_handler,
        }),
        validate_responses=True,
        strict_validation=True,
        pythonic_params=True,
        auth_all_paths=True,
    )
    app.app.config.update(configuration.API_CONF)

    return app