Ejemplo n.º 1
0
def main():
    # testing stuff:
    # hello = HelloWorld()
    # hello.hello()
    # hello.hello('Fred')

    # load config:
    config = Config()
    config.loadConfigFromJSONFile(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'config.json'))

    # configure logger:
    loggingConfig = config.getServiceConfig('global').getFeatureConfig('logging')
    logging.basicConfig(
        level=logging.getLevelName(loggingConfig.getValue('level')),
        format='%(asctime)s [%(levelname)s] %(name)s: %(message)s',
        filename=loggingConfig.getValue('path')
    )

    # init ServiceRunner:
    serviceRunner = ServiceRunner(config.getServiceConfig('service_runner'))
    
    # init service TimerCam:
    timerCam = TimerCam(config.getServiceConfig('timer_cam'))
    serviceRunner.registerService(timerCam)

    # # init service TwitterCam:
    twitterCam = TwitterCam(config.getServiceConfig('twitter_cam'))
    serviceRunner.registerService(twitterCam)

    # start ServiceRunner:
    serviceRunner.start()
Ejemplo n.º 2
0
def test_loadConfigFromJSONFile(tmp_path):

    mock_config_file = tmp_path / 'config.json'
    mock_config_file.write_text(json.dumps(config_dict, indent=4))

    config = Config()
    config.loadConfigFromJSONFile(tmp_path / 'config.json')

    # result = json.dumps(config.getConfigDict(), sort_keys=True)
    # compare = json.dumps(config_dict, sort_keys=True)

    # assert result == compare

    assert config.getConfigDict() == config_dict
Ejemplo n.º 3
0
def test_getServiceConfigDict():
    config = Config(config_dict)

    print(config_dict['global'])
    print(config.getServiceConfigDict('service_1'))
    print(config_dict['global'])

    # CONTINUE: tests have unexpected behavior. Either they affect each other or the deep copy of merge() doesn't work.

    # assert config.getServiceConfigDict('service_1') == config_service_1_after_merge_dict
    # assert config.getServiceConfigDict('service_1') == config_dict['service_1']
    assert config.getServiceConfigDict('global') == config_dict['global']

    # Make sure that the deep merge doesn't modify the config_dict:
    assert config.getServiceConfigDict('global') != config_dict['service_1']
Ejemplo n.º 4
0
def test_run_service_inactive(caplog):

    configDict['active'] = False
    config = Config(configDict)

    with caplog.at_level(logging.DEBUG):
        twitterCam = TwitterCam(config)
        result = twitterCam.run(datetime.datetime.now())

    assert result == True
    assert 'Inactive' in caplog.text
Ejemplo n.º 5
0
def test_run_service_inactive(caplog):

    config = Config({
        'active': False,
        'features': {
            'take_picture': { 'active': True },
            'ftps_upload': { 'active': False }
        }
    })

    with caplog.at_level(logging.DEBUG):
        timerCam = TimerCam(config)
        result = timerCam.run(datetime.datetime(year=2001, month=1, day=1))

    assert result == True
    assert 'Inactive' in caplog.text
Ejemplo n.º 6
0
def main():

    config = Config()
    config.loadConfigFromJSONFile('config.json')

    globalConfig = config.getGlobalConfig()
    print(globalConfig.getConfigDict())
    print(globalConfig.getValue('filename_time_format'))

    moduleConfigFTPSUpload = config.getModuleConfig('ftps_upload')
    print(moduleConfigFTPSUpload.getConfigDict())

    print(moduleConfigFTPSUpload.getValue('filename_time_format'))
Ejemplo n.º 7
0
def test_run_provider_inactive(caplog):
    """
    Service will be aborted if no image provider is active.
    """

    config = Config({
        'active': True,
        'features': {
            'take_picture': { 'active': False },
            'ftps_upload': { 'active': False }
        }
    })

    with caplog.at_level(logging.DEBUG):
        timerCam = TimerCam(config)
        result = timerCam.run(datetime.datetime(year=2001, month=1, day=1))

    assert result == False
    assert 'take_picture is inactive' in caplog.text
    assert 'aborted' in caplog.text
Ejemplo n.º 8
0
def test_TwitterCam_isDueToRun():
    twittercam_config = Config({
        "active":
        True,
        "features": {
            "take_picture": {},
            "post_on_twitter": {
                "active": False
            }
        },
        "shots": [{
            "time_of_day": "08:00:00",
            "last_time_executed": "2021-03-01 08:01:51.227604"
        }, {
            "time_of_day": "12:00:00",
            "last_time_executed": "2021-03-02 12:03:23.227604"
        }, {
            "time_of_day": "16:00:00",
            "last_time_executed": None
        }, {
            "time_of_day": "23:00:00",
            "last_time_executed": None
        }]
    })

    timestamp_now = '2021-03-02 11:04:00.000000'
    twitterCam = TwitterCam(twittercam_config)
    assert twitterCam.serviceIsDueToRun(timestamp_now) == True
    assert twitterCam.shotToExecuteNext() == 0

    timestamp_now = '2021-03-02 12:04:00.000000'
    twitterCam = TwitterCam(twittercam_config)
    assert twitterCam.serviceIsDueToRun(timestamp_now) == True
    assert twitterCam.shotToExecuteNext() == 1

    timestamp_now = '2021-03-02 16:04:00.000000'
    twitterCam = TwitterCam(twittercam_config)
    assert twitterCam.serviceIsDueToRun(timestamp_now) == True
    assert twitterCam.shotToExecuteNext() == 2
Ejemplo n.º 9
0
def test_getConfigDict():
    config = Config(config_dict)

    assert config.getConfigDict() == config_dict
Ejemplo n.º 10
0
def test_pass_config_into_constructor():
    config = Config(config_dict)

    assert config.getConfigDict() == config_dict