コード例 #1
0
async def test_on_close_callback(caplog):
    """Assert the on_close callback logs a warning."""
    error_msg = 'Closed connection to NATS'
    with caplog.at_level(logging.WARNING):
        queue = QueueService()
        await queue.on_close()

        assert error_msg in caplog.text
コード例 #2
0
async def test_on_disconnect_callback(caplog):
    """Assert the on_disconnect callback logs a warning."""
    error_msg = 'Disconnected from NATS'
    with caplog.at_level(logging.WARNING):
        queue = QueueService()
        await queue.on_disconnect()

        assert error_msg in caplog.text
コード例 #3
0
async def test_error_callback(caplog):
    """Assert the on_error callback logs a warning."""
    error_msg = 'test error'
    with caplog.at_level(logging.WARNING):
        queue = QueueService()
        await queue.on_error(e=Exception(error_msg))

        assert error_msg in caplog.text
コード例 #4
0
def test_publish_colin_filing_managed(app_ctx, stan_server):
    """Assert that payment tokens can be retrieved and decoded from the Queue."""
    # SETUP
    msgs = []
    this_loop = asyncio.get_event_loop()
    # this_loop = event_loop
    future = asyncio.Future(loop=this_loop)
    queue = QueueService(app_ctx, this_loop)
    this_loop.run_until_complete(queue.connect())

    async def cb(msg):
        nonlocal msgs
        nonlocal future
        msgs.append(msg)
        if len(msgs) == 5:
            future.set_result(True)

    this_loop.run_until_complete(
        queue.stan.subscribe(subject=queue.subject,
                             queue='colin_queue',
                             durable_name='colin_queue',
                             cb=cb))

    # TEST - add some messages to the queue
    for i in range(0, 5):
        payload = {
            'colinFiling': {
                'id': 1234 + i,
            }
        }
        queue.publish_json(payload=payload)
    try:
        this_loop.run_until_complete(
            asyncio.wait_for(future, 2, loop=this_loop))
    except Exception as err:
        print(err)

    # CHECK the colinFilings were retrieved from the queue
    assert len(msgs) == 5
    for i in range(0, 5):
        m = msgs[i]
        assert 'colinFiling' in m.data.decode('utf-8')
        assert 1234 + i == dpath.util.get(json.loads(m.data.decode('utf-8')),
                                          'colinFiling/id')
コード例 #5
0
async def test_queue_properties_with_no_flask_ctx():
    """Assert that the queue clients cannot be checked."""
    queue = QueueService()

    assert not queue.nats
    assert not queue.stan
    assert queue.is_closed
    assert not queue.is_connected

    await queue.connect()
    assert not queue.is_connected
コード例 #6
0
async def test_on_reconnect_callback(caplog, app_ctx, stan_server):
    """Assert the reconnect callback logs a warning."""
    error_msg = 'Reconnected to NATS'
    with caplog.at_level(logging.WARNING):
        queue = QueueService(app_ctx)
        await queue.connect()
        await queue.on_reconnect()

        assert error_msg in caplog.text
        assert queue.nats.connected_url.netloc in caplog.text
        await queue.close()
コード例 #7
0
async def test_queue_connect_to_nats(app_ctx, stan_server):
    """Assert that the service can connect to the STAN Queue."""
    queue = QueueService(app_ctx)

    # sanity check
    assert not queue.is_connected

    # test
    await queue.connect()
    assert queue.is_connected

    await queue.connect()
    assert queue.is_connected

    await queue.close()
    assert queue.is_closed
コード例 #8
0
                # update lear with new tax ids from colin
                application.logger.debug(f'Updating tax ids for {tax_ids.keys()} in lear...')
                response = requests.post(
                    application.config['LEGAL_URL'] + '/internal/tax_ids',
                    json=tax_ids,
                    headers={'Content-Type': 'application/json', 'Authorization': f'Bearer {token}'}
                )
                if response.status_code != 201:
                    application.logger.error('legal-updater failed to update tax_ids in lear.')
                    raise Exception

                await send_emails(tax_ids, application)

                application.logger.debug('Successfully updated tax ids in lear.')
            else:
                application.logger.debug('No tax ids in colin to update in lear.')
        else:
            application.logger.debug('No businesses in lear with outstanding tax ids.')

    except Exception as err:
        application.logger.error(err)


if __name__ == '__main__':
    application = create_app()
    with application.app_context():
        update_filings(application)
        event_loop = asyncio.get_event_loop()
        qsm = QueueService(app=application, loop=event_loop)
        event_loop.run_until_complete(update_business_nos(application))
コード例 #9
0
async def test_queue_flask_teardown(app_ctx):
    """Assert that the service can connect to the STAN Queue."""
    queue = QueueService(app_ctx)
    queue.teardown(exception=None)
    assert queue.is_closed