Example #1
0
def add_garage():
    if not Garage.reg_mode:
        return wrap_status_code(403)

    new_garage = Garage.add_garage()
    ret = {'status': 201, 'api_key': new_garage.api_key}
    return json.dumps(ret), 201
Example #2
0
def add_smoke_event():
    api_key = request.headers.get('apikey')
    garage = Garage.get_garage_by_key(api_key)

    if garage is None:
        return wrap_status_code(403)

    garage.add_smoke_event()

    return wrap_status_code(201)
Example #3
0
def add_report_event():
    api_key = request.headers.get('apikey')
    garage = Garage.get_garage_by_key(api_key)

    if garage is None:
        return wrap_status_code(403)

    garage.add_report_event()

    ret = {'status': 201, 'period': garage.period}
    return json.dumps(ret), 201
Example #4
0
def app_client():
    # set app config to testing via env var
    testing_utils.setup()

    from garage_system import config_manager
    config_manager.set_default_password()

    # initialize app with testing config
    # (garage module imports db from garage_system)
    from garage_system import db
    db.create_all(
    )  # reinitialize db scheme (because other tests might screw it up)

    from garage_system.mod_main.models.garage import Garage
    test_garage = Garage.add_garage()
    test_garage.api_key = 'testing_key'  # we need to know garage api key
    db.session.commit()  # commit new key

    # add some event we can check
    # make sure we get more than one page of events
    from garage_system.mod_main.controllers import PAGE_SIZE
    for i in range(0, PAGE_SIZE * 2):
        if i % 2 == 0:
            test_garage.add_smoke_event()
        else:
            test_garage.add_report_event()

    # to make sure garage is in ok state
    test_garage.add_report_event()

    from garage_system import app
    # set logged in flag to be true for all tests
    yield app.test_client()

    # teardown (delete db)
    testing_utils.teardown()
    # load empty config
    config_manager.reload_config()