def test_get_named_config(test_type, environment, expected):
    """Assert that the named configurations can be loaded.

    Or that a KeyError is returned for missing config types.
    """
    if test_type == 'valid':
        assert isinstance(config.get_named_config(environment), expected)
    else:
        with pytest.raises(KeyError):
            config.get_named_config(environment)
Beispiel #2
0
    def __init__(self,
                 *,
                 loop=None,
                 cb_handler=None,
                 nats_connection_options=None,
                 stan_connection_options=None,
                 subscription_options=None,
                 config=get_named_config()):
        """Initialize the service to a working state."""
        self.sc = None
        self.nc = None
        self._start_seq = 0
        self._loop = loop
        self.cb_handler = cb_handler
        self.nats_connection_options = nats_connection_options or {}
        self.stan_connection_options = stan_connection_options or {}
        self.subscription_options = subscription_options or {}
        self.config = config

        async def conn_lost_cb(error):
            logger.info('Connection lost:%s', error)
            for i in range(0, 100):
                try:
                    logger.info('Reconnecting, attempt=%i...', i)
                    await self.connect()
                except Exception as e:  # pylint: disable=broad-except; catch all errors from client framework
                    logger.error('Error %s',
                                 e.with_traceback(),
                                 stack_info=True)
                    continue
                break

        self._stan_conn_lost_cb = conn_lost_cb
Beispiel #3
0
def app():
    """Return a session-wide application configured in TEST mode."""
    # _app = create_app('testing')
    _app = Flask(__name__)
    _app.config.from_object(get_named_config('testing'))
    db.init_app(_app)

    return _app
def test_config_dsn_key():
    """Assert that the ProductionConfig is correct.

    The object either uses the SENTRY_DSN from the environment
    and initializes Sentry, or it doesn't.
    """
    from flask import Flask
    from entity_filer.config import get_named_config
    config._Config.SENTRY_DSN = None  # pylint: disable=protected-access; for whitebox testing
    app = Flask(__name__)
    app.config.from_object(get_named_config('production'))
    assert app.config.get('SENTRY_DSN') is None

    # Assert that the SENTRY_DSN is set to the assigned environment value
    dsn = 'http://secret_key@localhost:9000/project_id'
    config._Config.SENTRY_DSN = dsn  # pylint: disable=protected-access; for whitebox testing
    reload(config)
    app = Flask(__name__)
    app.config.from_object(get_named_config('production'))
    assert app.config.get('SENTRY_DSN') is not None
Beispiel #5
0
from entity_filer import config
from entity_filer.filing_processors import (
    alteration,
    annual_report,
    change_of_address,
    change_of_directors,
    change_of_name,
    correction,
    incorporation_filing,
    transition,
    voluntary_dissolution,
)
from entity_filer.filing_processors.filing_components import name_request

qsm = QueueServiceManager()  # pylint: disable=invalid-name
APP_CONFIG = config.get_named_config(os.getenv('DEPLOYMENT_ENV', 'production'))
FLASK_APP = Flask(__name__)
FLASK_APP.config.from_object(APP_CONFIG)
db.init_app(FLASK_APP)


def get_filing_types(legal_filings: dict):
    """Get the filing type fee codes for the filing.

    Returns: {
        list: a list of filing types.
    }
    """
    filing_types = []
    for k in legal_filings['filing'].keys():
        if Filing.FILINGS.get(k, None):
Beispiel #6
0
                if filing.get('changeOfAddress'):
                    change_of_address.process(business, filing)
                if filing.get('changeOfDirectors'):
                    change_of_directors.process(business, filing)

            filing_submission.transaction_id = transaction.id
            db.session.add(business)

        filing_submission.payment_completion_date = datetime.datetime.utcnow()
        db.session.add(filing_submission)
        db.session.commit()
        return


FLASK_APP = Flask(__name__)
FLASK_APP.config.from_object(get_named_config('production'))
db.init_app(FLASK_APP)


async def cb_subscription_handler(msg: nats.aio.client.Msg):
    """Use Callback to process Queue Msg objects."""
    try:
        logger.info('Received raw message seq:%s, data=  %s', msg.sequence, msg.data.decode())
        payment_token = extract_payment_token(msg)
        logger.debug('Extracted payment token: %s', payment_token)
        process_filing(payment_token, FLASK_APP)
    except OperationalError as err:
        logger.error('Queue Blocked - Database Issue: %s', json.dumps(payment_token), exc_info=True)
        raise err  # We don't want to handle the error, as a DB down would drain the queue
    except (QueueException, Exception):  # pylint: disable=broad-except
        # Catch Exception so that any error is still caught and the message is removed from the queue