예제 #1
0
def test_libres_context(postgres_dsn):
    Base = declarative_base()

    class App(Framework, LibresIntegration):
        pass

    app = App()
    app.configure_application(dsn=postgres_dsn, base=Base)
    app.namespace = "libres"
    app.set_application_id("libres/foo")
    app.session_manager.set_current_schema("libres-foo")

    tables = app.session().execute(
        "SELECT table_name FROM information_schema.tables " "WHERE table_schema = 'libres-foo'"
    )

    tables = set(r[0] for r in tables.fetchall())

    assert tables == {"allocations", "resources", "reserved_slots", "reservations"}

    scheduler = new_scheduler(app.libres_context, uuid4(), "Europe/Zurich")
    assert scheduler.managed_allocations().count() == 0

    scheduler.allocate((datetime(2015, 7, 30, 11), datetime(2015, 7, 30, 12)))
    assert scheduler.managed_allocations().count() == 1

    assert app.session_manager is app.libres_context.get_service("session_provider")
예제 #2
0
def test_libres_context(postgres_dsn):
    Base = declarative_base()

    class App(Framework, LibresIntegration):
        pass

    app = App()
    app.configure_application(dsn=postgres_dsn, base=Base)
    app.namespace = 'libres'
    app.set_application_id('libres/foo')
    app.session_manager.set_current_schema('libres-foo')

    tables = app.session().execute(
        "SELECT table_name FROM information_schema.tables "
        "WHERE table_schema = 'libres-foo'"
    )

    tables = set(r[0] for r in tables.fetchall())

    assert tables == {
        'allocations',
        'resources',
        'reserved_slots',
        'reservations'
    }

    scheduler = new_scheduler(app.libres_context, uuid4(), 'Europe/Zurich')
    assert scheduler.managed_allocations().count() == 0

    scheduler.allocate((datetime(2015, 7, 30, 11), datetime(2015, 7, 30, 12)))
    assert scheduler.managed_allocations().count() == 1

    assert app.session_manager is app.libres_context.get_service(
        'session_provider')
예제 #3
0
파일: conftest.py 프로젝트: seantis/libres
def new_test_scheduler(dsn, context=None, name=None):
    context = context or new_uuid().hex
    name = name or new_uuid().hex

    context = registry.register_context(context, replace=True)
    context.set_setting('dsn', dsn)

    return new_scheduler(context=context, name=name, timezone='Europe/Zurich')
예제 #4
0
    def get_scheduler(self, libres_context):
        assert self.id, "the id needs to be set"
        assert self.timezone, "the timezone needs to be set"

        return new_scheduler(libres_context, self.id, self.timezone)
예제 #5
0
    def get_scheduler(self, libres_context):
        assert self.id, "the id needs to be set"
        assert self.timezone, "the timezone needs to be set"

        return new_scheduler(libres_context, self.id, self.timezone)
예제 #6
0
파일: run.py 프로젝트: seantis/libres
        scheduler.rollback()
        raise

    return json.dumps(
        {'status': 'success', 'message': 'A reservation has been made'}
    )


@app.route('/')
def index():
    return render_template('index.html')


if __name__ == '__main__':

    postgresql = Postgresql()

    try:
        context = libres.registry.register_context('flask-exmaple')
        context.set_setting('dsn', postgresql.url())
        scheduler = libres.new_scheduler(
            context, 'Test Scheduler', timezone='Europe/Zurich'
        )
        scheduler.setup_database()
        scheduler.commit()

        app.run(debug=True)

    finally:
        postgresql.stop()