async def test_publish_event(app, session, stan_server, event_loop, client_id, entity_stan, future): """Assert that filing event is placed on the queue.""" # Call back for the subscription from entity_queue_common.service import ServiceWorker from entity_filer.worker import APP_CONFIG, publish_event, qsm from legal_api.models import Business, 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) event_handler_subject = APP_CONFIG.ENTITY_EVENT_PUBLISH_OPTIONS['subject'] await entity_stan.subscribe( subject=event_handler_subject, queue=f'entity_queue.{event_handler_subject}', durable_name=f'entity_durable_name.{event_handler_subject}', cb=cb_file_handler) s = ServiceWorker() s.sc = entity_stan qsm.service = s # Setup filing = Filing() filing.id = 101 filing.effective_date = datetime.utcnow().replace(tzinfo=timezone.utc) filing.filing_json = ANNUAL_REPORT business = Business() business.identifier = 'CP1234567' business.legal_name = 'CP1234567 - Legal Name' # Test await publish_event(business, filing) try: await asyncio.wait_for(future, 2, loop=event_loop) except Exception as err: print(err) # check it out assert len(msgs) == 1 event_msg = json.loads(msgs[0].data.decode('utf-8')) assert event_msg['filing']['filingId'] == 101 assert event_msg['filing']['identifier'] == 'CP1234567' assert event_msg['filing']['legalFilings'] == ['annualReport']
async def test_publish_email_message(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_email_message, 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.EMAIL_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 filing.filing_type = 'incorporationApplication' filing_date = datetime.datetime.utcnow() filing.filing_date = filing_date filing.effective_date = filing_date await publish_email_message(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_data_from_msg(msgs[0], 'id') == filing.id assert get_data_from_msg(msgs[0], 'type') == filing.filing_type assert get_data_from_msg(msgs[0], 'option') == 'filed'
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