Ejemplo n.º 1
0
def test_start_app_routine(get_config, default_config, get_from_queue,
                           monkeypatch):
    """ Test all client components was initialized and can be start successfully """
    # write device config
    devcfg = get_config(DeviceConfig,
                        default_config('dev'),
                        fname='test_cfg.yml')
    devcfg.save()
    # write system config with device config file location
    syscfg = get_config(SystemConfig, default_config('sys'))
    # create device from system config
    device = BaseDevice(syscfg, devcfg)
    syscfg.update({'device': device})

    test_queue = Queue()

    # Mqtt client is a process, monkeypatching "run" method not working because of it
    monkeypatch.setattr(MQTTClient, 'start', lambda *a: test_queue.put('mqtt'))
    monkeypatch.setattr(Router, 'run', lambda *a: test_queue.put('router'))
    # BaseDevice is not a threading interface at all, so no join later
    monkeypatch.setattr(BaseDevice, 'run', lambda *a: test_queue.put('device'))

    monkeypatch.setattr(MQTTClient, 'join', lambda *a: True)
    monkeypatch.setattr(Router, 'join', lambda *a: True)

    start_app(app_config=syscfg, device=device)

    result = list(get_from_queue(test_queue))
    for service in ['mqtt', 'router', 'device']:
        assert service in result, f'{service} not started'
Ejemplo n.º 2
0
def test_app_integrity(get_config, get_root, default_config, monkeypatch):
    """ Starting skaben test """

    app_config_path = os.path.join(get_root, "res", "system_config.yml")
    dev_config_path = os.path.join(get_root, "res", "device_config.yml")

    devcfg = get_config(LockConfig, default_config('dev'), dev_config_path)
    syscfg = get_config(SystemConfig, default_config('sys'), app_config_path)

    monkeypatch.setattr(Router, "start", lambda *a: True)
    monkeypatch.setattr(Router, "join", lambda *a: True)
    monkeypatch.setattr(MQTTClient, "start", lambda *a: True)
    monkeypatch.setattr(MQTTClient, "join", lambda *a: True)
    monkeypatch.setattr(LockDevice, "run", lambda *a: True)
    monkeypatch.setattr(LockDevice, "close", lambda *a: True)
    monkeypatch.setattr(LockDevice, "gpio_setup", lambda *a: True)

    device = LockDevice(syscfg, devcfg)

    start_app(app_config=syscfg, device=device)
Ejemplo n.º 3
0
from device import BoilerplateDevice
from config import BoilerplateConfig

root = os.path.abspath(os.path.dirname(__file__))

sys_config_path = os.path.join(root, 'conf', 'system.yml')
dev_config_path = os.path.join(root, 'conf', 'device.yml')

if __name__ == "__main__":
    #
    # DO NOT FORGET TO RUN ./pre-run.sh install BEFORE FIRST START
    #

    # setting system config (immutable)
    app_config = SystemConfig(sys_config_path, root=root)
    # making device config (mutable, in-game)
    dev_config = BoilerplateConfig(dev_config_path)
    # <-- perform specific device config operations
    # which should be run once before main program
    # like making asset paths if you using DeviceConfigExtendede
    # dev_config.make_asset_paths()

    # instantiating device
    device = BoilerplateDevice(app_config, dev_config)
    # <-- perform specific device operations
    # which should be run once before main program
    # like device.gpio_setup() for lock device

    # start application
    start_app(app_config=app_config, device=device)