Example #1
0
def main(argv):
    '''
    Main entry point into the program.
    '''

    # Get arguments and argument parser.
    (args, parser) = app.cli(argv)

    # Initialize logging and set verbosity level.
    logger = logging.get_logger(__name__)

    logger.debug(f'Program arguments: {argv}')
    # Check if any command arguments have been passed.
    if (len(argv) <= 1):
        # No arguments passed.
        logger.warning(f'No command arguments passed')
        #parser.print_help()
        #sys.exit(errno.EAGAIN)

    if args.list_configs:
        configs = settings.list_configs()
        print(configs)
        return os.EX_OK

    # Initialize our app.
    try:
        app.init(args)
    except Exception as e:
        logger.exception(e)
        logger.failure(f'App initialization failed: {e.errno}')
        parser.print_help()
        return os.EX_SOFTWARE

    # Load application configuration.
    try:
        config = app.load_config(args)
    except Exception as e:
        logger.exception(e)
        logger.failure(f'App configuration failed: {e.errno}')
        parser.print_help()
        return os.EX_CONFIG

    # Do something with config before running main app logic.

    # Run main app logic
    try:
        exit_code = app.process(args, config)
    except Exception as e:
        logger.exception(e)
        logger.failure(f'App processing failed: {e.errno}')
        parser.print_help()
        return os.EX_SOFTWARE

    # Handle anything else you need to, we're getting out of here.

    return exit_code
def test_config_is_loaded(app, revert_config):
    assert app.config['API_KEY'] == 'my-secret-key'

    os.environ['VCAP_SERVICES'] = json.dumps({
        "user-provided": [{
            "credentials": {
                "api_host": "some domain",
                "api_key": "some secret key"
            },
            "label": "user-provided",
            "name": "notify-template-preview",
            "syslog_drain_url": "",
            "tags": [],
            "volume_mounts": []
        }]
    })

    load_config(app)

    assert app.config['API_KEY'] == 'some secret key'
Example #3
0
    def test_load_config(self):
        """ Test that verifies the app loads the right config """

        conf = load_config('alde_configuration.ini')

        self.assertEquals('sqlite:////tmp/test.db', conf['SQL_LITE_URL'])
        self.assertEquals('5000', conf['PORT'])
        self.assertEquals('/tmp', conf['APP_UPLOAD_FOLDER'])
        self.assertEquals('/tmp', conf['APP_PROFILE_FOLDER'])
        self.assertEquals(
            ["RIGID", "MOULDABLE", "CHECKPOINTABLE", "MALLEABLE"],
            conf['APP_TYPES'])
        self.assertEquals('/tmp/comparator', conf['COMPARATOR_PATH'])
        self.assertEquals('comparator_file.csv', conf['COMPARATOR_FILE'])
        self.assertEquals('127.0.0.1', conf['HOST'])
Example #4
0
    def test_load_config_envs(self, mock_getenv):
        mock_getenv.return_value = "5001"

        conf = load_config('alde_configuration.ini')

        self.assertEquals('5001', conf['PORT'])