def test_get_filing_id_from_msg(): """Assert the identifier of the filing in the NATS msg.""" # setup identifier = 'test_id' token = {'filing': {'id': identifier}} msg = Msg() msg.proto = protocol.MsgProto msg.proto.data = json.dumps(token).encode('utf-8') assert identifier == messages.get_filing_id_from_msg(msg) assert not messages.get_filing_id_from_msg(None)
async def test_publish_filing(app, session, stan_server, event_loop, client_id, entity_stan, future): """Assert that payment tokens can be retrieved and decoded from the Queue.""" # Call back for the subscription from entity_queue_common.service import ServiceWorker from entity_pay.worker import APP_CONFIG, publish_filing, qsm from legal_api.models import Filing # file handler callback msgs = [] async def cb_file_handler(msg): nonlocal msgs nonlocal future msgs.append(msg) if len(msgs) == 1: future.set_result(True) file_handler_subject = APP_CONFIG.FILER_PUBLISH_OPTIONS['subject'] await subscribe_to_queue(entity_stan, file_handler_subject, f'entity_queue.{file_handler_subject}', f'entity_durable_name.{file_handler_subject}', cb_file_handler) s = ServiceWorker() s.sc = entity_stan qsm.service = s # Test filing = Filing() filing.id = 101 await publish_filing(filing) try: await asyncio.wait_for(future, 2, loop=event_loop) except Exception as err: print(err) # check it out assert len(msgs) == 1 assert get_filing_id_from_msg(msgs[0]) == filing.id
async def test_cb_subscription_handler(app, session, stan_server, event_loop, client_id, entity_stan, future): """Assert that payment tokens can be retrieved and decoded from the Queue.""" # Call back for the subscription from entity_queue_common.service import ServiceWorker from entity_pay.worker import APP_CONFIG, cb_subscription_handler, get_filing_by_payment_id, qsm from legal_api.models import Business, Filing from tests.unit import create_filing, create_business # vars uuid = str(random.SystemRandom().getrandbits(0x58)) payment_id = uuid identifier = 'CP1234567' # entity_subject = os.getenv('LEGAL_FILING_STAN_SUBJECT') # entity_queue = os.getenv('LEGAL_FILING_STAN_QUEUE') # entity_durable_name = os.getenv('LEGAL_FILING_STAN_DURABLE_NAME') entity_subject = f'test_subject.{uuid}' entity_queue = f'test_queue.{uuid}' entity_durable_name = f'test_durable.{uuid}' # setup business = create_business(identifier) business_id = business.id # create_filing(payment_id, AR_FILING, business.id) create_filing(payment_id, None, business.id) # register the handler to test it entity_subject = await subscribe_to_queue(entity_stan, entity_subject, entity_queue, entity_durable_name, cb_subscription_handler) # file handler callback msgs = [] async def cb_file_handler(msg): nonlocal msgs nonlocal future msgs.append(msg) if len(msgs) == 1: future.set_result(True) file_handler_subject = APP_CONFIG.FILER_PUBLISH_OPTIONS['subject'] await subscribe_to_queue(entity_stan, file_handler_subject, f'entity_queue.{file_handler_subject}', f'entity_durable_name.{file_handler_subject}', cb_file_handler) s = ServiceWorker() s.sc = entity_stan qsm.service = s # add payment tokens to queue await helper_add_payment_to_queue(entity_stan, entity_subject, payment_id=payment_id, status_code='COMPLETED') try: await asyncio.wait_for(future, 2, loop=event_loop) except Exception as err: print(err) # Get modified data filing = get_filing_by_payment_id(payment_id) business = Business.find_by_internal_id(business_id) # check it out # assert filing.transaction_id assert filing.business_id == business_id assert filing.status == Filing.Status.PAID.value assert len(msgs) == 1 assert get_filing_id_from_msg(msgs[0]) == filing.id