Exemple #1
0
def factory_entity_model():
    """Produce a templated entity model."""
    entity = EntityModel(business_identifier='CP1234567',
                         business_number='791861073BC0001',
                         name='Foobar, Inc.')
    entity.save()
    return entity
Exemple #2
0
def test_entity(session):
    """Assert that an Entity can be stored in the service."""
    entity = EntityModel(business_identifier='CP1234567',
                         business_number='791861073BC0001',
                         name='Foobar, Inc.')
    session.add(entity)
    session.commit()
    assert entity.id is not None
Exemple #3
0
def test_entity_find_by_business_id(session):
    """Assert that an Entity can be retrieved via business identifier."""
    entity = EntityModel(business_identifier='CP1234567')
    session.add(entity)
    session.commit()

    business_id = 'CP1234567'

    result_entity = EntityModel.find_by_business_identifier(business_identifier=business_id)

    assert result_entity.id is not None
Exemple #4
0
def test_find_by_entity_id(session):
    """Assert that a Contact can be retrieved via the entity id."""
    entity = EntityModel(business_identifier='CP1234567')
    session.add(entity)

    contact = ContactModel(entity_id=entity.id)

    session.add(contact)

    result_contact = ContactModel.find_by_entity_id(entity_id=entity.id)

    assert result_contact is not None
Exemple #5
0
def test_entity_find_by_business_id(session):
    """Assert that an Entity can be retrieved via business identifier."""
    entity = EntityModel(business_identifier='CP1234567',
                         business_number='791861073BC0001',
                         name='Foobar, Inc.')
    session.add(entity)
    session.commit()

    business_id = 'CP1234567'

    result_entity = EntityModel.find_by_business_identifier(
        business_identifier=business_id)

    assert result_entity.id is not None
Exemple #6
0
def test_contact(session):
    """Assert that a Contact can be stored in the service."""
    entity = EntityModel(business_identifier='CP1234567')
    session.add(entity)

    contact = ContactModel(street='123 Roundabout Lane',
                           street_additional='Unit 1',
                           city='Victoria',
                           region='British Columbia',
                           country='CA',
                           postal_code='V1A 1A1',
                           delivery_instructions='Ring buzzer 123',
                           phone='111-222-3333',
                           phone_extension='123',
                           email='*****@*****.**',
                           entity_id=entity.id)

    session.add(contact)
    session.commit()
    assert contact.id is not None
Exemple #7
0
async def process_name_events(event_message: Dict[str, any]):
    """Process name events.

    1. Check if the NR already exists in entities table, if yes apply changes. If not create entity record.
    2. Check if new status is DRAFT, if yes call pay-api and get the account details for the payments against the NR.
    3. If an account is found, affiliate to that account.

    Args:
        event_message (object): cloud event message, sample below.
            {
                'specversion': '1.0.1',
                'type': 'bc.registry.names.events',
                'source': '/requests/6724165',
                'id': id,
                'time': '',
                'datacontenttype': 'application/json',
                'identifier': '781020202',
                'data': {
                    'request': {
                        'nrNum': 'NR 5659951',
                        'newState': 'APPROVED',
                        'previousState': 'DRAFT'
                    }
                }
            }
    """
    logger.debug('>>>>>>>process_name_events>>>>>')
    request_data = event_message.get('data').get('request')
    nr_number = request_data['nrNum']
    nr_status = request_data['newState']
    nr_entity = EntityModel.find_by_business_identifier(nr_number)
    if nr_entity is None:
        logger.info('Entity doesn' 't exist, creating a new entity.')
        nr_entity = EntityModel(business_identifier=nr_number,
                                corp_type_code=CorpType.NR.value)

    nr_entity.status = nr_status
    nr_entity.name = request_data.get(
        'name',
        '')  # its not part of event now, this is to handle if they include it.
    nr_entity.last_modified_by = None  # TODO not present in event message.
    nr_entity.last_modified = parser.parse(event_message.get('time'))

    if nr_status == 'DRAFT' and AffiliationModel.find_affiliations_by_business_identifier(
            nr_number) is None:
        logger.info('Status is DRAFT, getting invoices for account')
        # Find account details for the NR.
        invoices = RestService.get(
            f'{APP_CONFIG.PAY_API_URL}/payment-requests?businessIdentifier={nr_number}',
            token=RestService.get_service_account_token()).json()

        # Ideally there should be only one or two (priority fees) payment request for the NR.
        if invoices and (auth_account_id := invoices['invoices'][0].get('paymentAccount').get('accountId')) \
                and str(auth_account_id).isnumeric():
            logger.info('Account ID received : %s', auth_account_id)
            # Auth account id can be service account value too, so doing a query lookup than find_by_id
            org: OrgModel = db.session.query(OrgModel).filter(
                OrgModel.id == auth_account_id).one_or_none()
            if org:
                nr_entity.pass_code_claimed = True
                # Create an affiliation.
                logger.info(
                    'Creating affiliation between Entity : %s and Org : %s',
                    nr_entity, org)
                affiliation: AffiliationModel = AffiliationModel(
                    entity=nr_entity, org=org)
                affiliation.flush()
Exemple #8
0
def test_entity(session):
    """Assert that an Entity can be stored in the service."""
    entity = EntityModel(business_identifier='CP1234567')
    session.add(entity)
    session.commit()
    assert entity.id is not None